TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
tmk::geom Namespace Reference

Classes

struct  Polygon
struct  Point
struct  Box
class  PolygonIndex
struct  Shape

Typedefs

using Ring = std::vector<Point>
 closed, first point not repeated
using Rings = std::vector<Ring>
 a region under the non-zero fill rule: outer rings and holes
using i128 = __int128
 GCC extension; exact products of nm coordinates.

Enumerations

enum class  Corners { Round , Chamfer }

Functions

Rings unite (const Rings &a)
Rings subtract (const Rings &a, const Rings &b)
Rings intersect (const Rings &a, const Rings &b)
Rings even_odd (const Rings &loops)
 Region of closed loops under the even-odd rule (a board outline with cut-outs).
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.
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), so a knockout built from it is never smaller than the clearance asks.
Ring circle_ring (Point centre, Coord radius, Coord max_error)
 Regular polygon around a circle with every edge outside it, chord error <= max_error.
double area (const Ring &r)
 signed: outer rings positive, holes negative (as returned by these functions)
double area (const Rings &rs)
bool contains (const Rings &rs, Point p)
 Inside the region or on its boundary.
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_polygon (SHAPE_POLY_SET::Fracture).
Coord kiround (double v)
 Rounds half away from zero, like KiCad's KiROUND.
double norm_deg (double a)
 Normalises degrees to [0, 360).
Point rotate (Point p, double deg)
 Rotates p by deg degrees the way KiCad does: positive angles turn counter-clockwise on screen in KiCad's y-down coordinates.
i128 orient (Point a, Point b, Point c)
 Orientation of c relative to a→b: >0 left (counter-clockwise in y-up math terms), <0 right, 0 collinear.
bool segments_intersect (Point a, Point b, Point c, Point d)
 True if closed segments ab and cd share at least one point.
bool point_seg_closer (Point p, Point a, Point b, Coord t)
 True if the distance from p to segment ab is strictly less than t (t >= 0).
bool seg_seg_closer (Point a, Point b, Point c, Point d, Coord t)
 True if the distance between segments ab and cd is strictly less than t (t >= 0).
long double point_seg_dist (Point p, Point a, Point b)
 Distances in nm (not squared), for reporting (long double).
long double seg_seg_dist (Point a, Point b, Point c, Point d)
bool point_in_polygon (Point p, const std::vector< Point > &poly)
 Point in closed polygon (boundary counts as inside).
bool closer_than (const Shape &a, const Shape &b, Coord clearance)
 True if the gap between the two shapes (distance between their surfaces, negative when they overlap) is strictly less than clearance.
bool closer_than_disk (const Shape &a, Point c, Coord r, Coord clearance)
 Equivalent to closer_than(a, Shape::point(c, r), clearance), without allocating.
double gap (const Shape &a, const Shape &b)
 Gap between two shapes in nm (negative = overlap depth bound; 0 when cores touch with r = 0).
std::vector< Point > arc_points (Point start, Point mid, Point end, Coord max_error=5 '000)
 Flattens a circular arc through start/mid/end into points with sagitta error <= max_error.
std::vector< Point > circle_points (Point centre, Coord radius, Coord max_error=5 '000)
 Circle outline as a closed polyline (first point repeated at the end).
std::vector< Point > convex_hull (std::vector< Point > pts)
 Convex hull, counter-clockwise in a y-up frame, no repeated point (Andrew's monotone chain, 1979; exact integer orientation tests).

Typedef Documentation

◆ i128

using tmk::geom::i128 = __int128

GCC extension; exact products of nm coordinates.

Definition at line 16 of file shape.hpp.

◆ Ring

using tmk::geom::Ring = std::vector<Point>

closed, first point not repeated

Definition at line 13 of file clip.hpp.

◆ Rings

using tmk::geom::Rings = std::vector<Ring>

a region under the non-zero fill rule: outer rings and holes

Definition at line 14 of file clip.hpp.

Enumeration Type Documentation

◆ Corners

enum class tmk::geom::Corners
strong
Enumerator
Round 
Chamfer 

Definition at line 16 of file clip.hpp.

Function Documentation

◆ arc_points()

std::vector< Point > tmk::geom::arc_points ( Point start,
Point mid,
Point end,
Coord max_error = 5 '000 )

Flattens a circular arc through start/mid/end into points with sagitta error <= max_error.

◆ area() [1/2]

double tmk::geom::area ( const Ring & r)

signed: outer rings positive, holes negative (as returned by these functions)

◆ area() [2/2]

double tmk::geom::area ( const Rings & rs)

◆ circle_points()

std::vector< Point > tmk::geom::circle_points ( Point centre,
Coord radius,
Coord max_error = 5 '000 )

Circle outline as a closed polyline (first point repeated at the end).

◆ circle_ring()

Ring tmk::geom::circle_ring ( Point centre,
Coord radius,
Coord max_error )

Regular polygon around a circle with every edge outside it, chord error <= max_error.

◆ closer_than()

bool tmk::geom::closer_than ( const Shape & a,
const Shape & b,
Coord clearance )

True if the gap between the two shapes (distance between their surfaces, negative when they overlap) is strictly less than clearance.

clearance may be 0 (then: do they overlap or touch? no — strictly overlap).

◆ closer_than_disk()

bool tmk::geom::closer_than_disk ( const Shape & a,
Point c,
Coord r,
Coord clearance )

Equivalent to closer_than(a, Shape::point(c, r), clearance), without allocating.

◆ contains()

bool tmk::geom::contains ( const Rings & rs,
Point p )

Inside the region or on its boundary.

◆ convex_hull()

std::vector< Point > tmk::geom::convex_hull ( std::vector< Point > pts)

Convex hull, counter-clockwise in a y-up frame, no repeated point (Andrew's monotone chain, 1979; exact integer orientation tests).

Fewer than three distinct points are returned sorted.

◆ even_odd()

Rings tmk::geom::even_odd ( const Rings & loops)

Region of closed loops under the even-odd rule (a board outline with cut-outs).

◆ fracture()

Ring tmk::geom::fracture ( const Polygon & p)

One ring with zero-width bridges from every hole to the outline, as KiCad writes a zone's filled_polygon (SHAPE_POLY_SET::Fracture).

Holes are joined in order of their leftmost point, each by a horizontal bridge to the nearest edge on its left (the hole-elimination step of ear clipping; Eberly, 2002).

◆ gap()

double tmk::geom::gap ( const Shape & a,
const Shape & b )

Gap between two shapes in nm (negative = overlap depth bound; 0 when cores touch with r = 0).

◆ intersect()

Rings tmk::geom::intersect ( const Rings & a,
const Rings & b )

◆ kiround()

Coord tmk::geom::kiround ( double v)
inline

Rounds half away from zero, like KiCad's KiROUND.

Definition at line 40 of file point.hpp.

◆ norm_deg()

double tmk::geom::norm_deg ( double a)
inline

Normalises degrees to [0, 360).

Definition at line 43 of file point.hpp.

◆ offset()

Rings tmk::geom::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.

◆ orient()

i128 tmk::geom::orient ( Point a,
Point b,
Point c )
inline

Orientation of c relative to a→b: >0 left (counter-clockwise in y-up math terms), <0 right, 0 collinear.

Definition at line 34 of file shape.hpp.

◆ point_in_polygon()

bool tmk::geom::point_in_polygon ( Point p,
const std::vector< Point > & poly )

Point in closed polygon (boundary counts as inside).

◆ point_seg_closer()

bool tmk::geom::point_seg_closer ( Point p,
Point a,
Point b,
Coord t )

True if the distance from p to segment ab is strictly less than t (t >= 0).

◆ point_seg_dist()

long double tmk::geom::point_seg_dist ( Point p,
Point a,
Point b )

Distances in nm (not squared), for reporting (long double).

◆ polygons()

std::vector< Polygon > tmk::geom::polygons ( const Rings & rs)

The region as separate polygons (a fill's islands), each with its holes.

◆ rotate()

Point tmk::geom::rotate ( Point p,
double deg )
inline

Rotates p by deg degrees the way KiCad does: positive angles turn counter-clockwise on screen in KiCad's y-down coordinates.

Multiples of 90° are exact.

Definition at line 52 of file point.hpp.

◆ seg_seg_closer()

bool tmk::geom::seg_seg_closer ( Point a,
Point b,
Point c,
Point d,
Coord t )

True if the distance between segments ab and cd is strictly less than t (t >= 0).

◆ seg_seg_dist()

long double tmk::geom::seg_seg_dist ( Point a,
Point b,
Point c,
Point d )

◆ segments_intersect()

bool tmk::geom::segments_intersect ( Point a,
Point b,
Point c,
Point d )

True if closed segments ab and cd share at least one point.

◆ shape_rings()

Rings tmk::geom::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), so a knockout built from it is never smaller than the clearance asks.

◆ subtract()

Rings tmk::geom::subtract ( const Rings & a,
const Rings & b )

◆ unite()

Rings tmk::geom::unite ( const Rings & a)