TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
clip.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Polygon booleans and offsets on integer nanometres, a thin wrapper over Clipper2 (Angus Johnson, 2022; the
4// Vatti scan-beam clipper, 1992). Used for zone fills (doc 05 §36). Results depend only on the inputs and
5// their order, so callers keep inputs in board order.
6#include <vector>
7
8#include "geom/point.hpp"
9#include "geom/shape.hpp"
10
11namespace tmk::geom {
12
13using Ring = std::vector<Point>; // closed, first point not repeated
14using Rings = std::vector<Ring>; // a region under the non-zero fill rule: outer rings and holes
15
16enum class Corners { Round, Chamfer };
17
18Rings unite(const Rings& a);
19Rings subtract(const Rings& a, const Rings& b);
20Rings intersect(const Rings& a, const Rings& b);
21// Region of closed loops under the even-odd rule (a board outline with cut-outs).
22Rings even_odd(const Rings& loops);
23// Grows (delta > 0) or shrinks a region; round corners stay within max_error of the true arc.
24Rings offset(const Rings& a, Coord delta, Corners corners, Coord max_error);
25// `s` grown by `grow`, every approximated arc outside the true one (KiCad's ERROR_OUTSIDE), so a knockout built
26// from it is never smaller than the clearance asks.
27Rings shape_rings(const Shape& s, Coord grow, Coord max_error);
28// Regular polygon around a circle with every edge outside it, chord error <= max_error.
29Ring circle_ring(Point centre, Coord radius, Coord max_error);
30
31double area(const Ring& r); // signed: outer rings positive, holes negative (as returned by these functions)
32double area(const Rings& rs);
33// Inside the region or on its boundary.
34bool contains(const Rings& rs, Point p);
35
40// The region as separate polygons (a fill's islands), each with its holes.
41std::vector<Polygon> polygons(const Rings& rs);
42// One ring with zero-width bridges from every hole to the outline, as KiCad writes a zone's filled_polygon
43// (SHAPE_POLY_SET::Fracture). Holes are joined in order of their leftmost point, each by a horizontal bridge to
44// the nearest edge on its left (the hole-elimination step of ear clipping; Eberly, 2002).
46
47} // namespace tmk::geom
Rings shape_rings(const Shape &s, Coord grow, Coord max_error)
s grown by grow, every approximated arc outside the true one (KiCad's ERROR_OUTSIDE),...
std::vector< Polygon > polygons(const Rings &rs)
The region as separate polygons (a fill's islands), each with its holes.
Ring fracture(const Polygon &p)
One ring with zero-width bridges from every hole to the outline, as KiCad writes a zone's filled_poly...
Ring circle_ring(Point centre, Coord radius, Coord max_error)
Regular polygon around a circle with every edge outside it, chord error <= max_error.
Rings unite(const Rings &a)
std::vector< Ring > Rings
a region under the non-zero fill rule: outer rings and holes
Definition clip.hpp:14
Rings offset(const Rings &a, Coord delta, Corners corners, Coord max_error)
Grows (delta > 0) or shrinks a region; round corners stay within max_error of the true arc.
bool contains(const Rings &rs, Point p)
Inside the region or on its boundary.
std::vector< Point > Ring
closed, first point not repeated
Definition clip.hpp:13
Rings subtract(const Rings &a, const Rings &b)
double area(const Ring &r)
signed: outer rings positive, holes negative (as returned by these functions)
Rings even_odd(const Rings &loops)
Region of closed loops under the even-odd rule (a board outline with cut-outs).
Rings intersect(const Rings &a, const Rings &b)
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
Integer-nanometre points and KiCad-compatible rotation.
Exact integer geometry for clearance checks (design doc 03 §1).