TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
poly_index.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Bucketed edges of one large closed polygon (a zone fill), so "does this disk touch the polygon?" costs the
4// edges near the disk instead of every edge. Exact: the answer equals
5// closer_than(Shape::point(c, r), Shape::polygon(pts, 0), clearance) (reference path; tests/test_geom.cpp).
6#include <vector>
7
8#include "geom/shape.hpp"
9
10namespace tmk::geom {
11
13 public:
14 PolygonIndex() = default;
15 explicit PolygonIndex(const std::vector<Point>& pts);
16
17 // True if the gap between the disk (centre c, radius r) and the polygon is strictly less than `clearance`
18 // (clearance + r > 0).
19 bool disk_closer(Point c, Coord r, Coord clearance) const;
20
21 // Any shape against the polygon. shape_closer(s, clearance) equals closer_than(s, Shape::polygon(pts, 0),
22 // clearance); shape_gap(s, bound) equals gap(s, Shape::polygon(pts, 0)) when the two cores are closer than
23 // `bound` (the caller knows that from shape_closer). Both visit only the polygon edges near the shape; the
24 // linear functions are the reference path (tests/test_geom.cpp).
25 bool shape_closer(const Shape& s, Coord clearance) const;
26 double shape_gap(const Shape& s, Coord bound) const;
27
28 private:
29 bool inside(Point c) const; // crossing parity; a point on the boundary may count either way
30 // Calls f(p, q, a, b) for every core edge pq of s and every polygon edge ab in a cell within `reach` of pq
31 // (an edge may come up more than once); stops and returns true when f does.
32 template <class F>
33 bool near_edges(const Shape& s, Coord reach, F&& f) const;
34 int cell_x(Coord x) const;
35 int cell_y(Coord y) const;
36
37 std::vector<Point> pts_;
38 Box box_;
39 Coord cell_ = 1;
40 int nx_ = 0, ny_ = 0;
41 std::vector<std::vector<int>> cells_; // edges (index of the start point) overlapping each cell, row-major
42 std::vector<std::vector<int>> rows_; // edges whose y-range overlaps each row of cells (crossing counts)
43};
44
45} // namespace tmk::geom
double shape_gap(const Shape &s, Coord bound) const
bool shape_closer(const Shape &s, Coord clearance) const
Any shape against the polygon.
bool disk_closer(Point c, Coord r, Coord clearance) const
True if the gap between the disk (centre c, radius r) and the polygon is strictly less than clearance...
PolygonIndex(const std::vector< Point > &pts)
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
Exact integer geometry for clearance checks (design doc 03 ยง1).