TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
shape.hpp File Reference

Exact integer geometry for clearance checks (design doc 03 §1). More...

#include <cstdint>
#include <vector>
#include "geom/point.hpp"

Go to the source code of this file.

Classes

struct  tmk::geom::Shape

Namespaces

namespace  tmk
namespace  tmk::geom

Typedefs

using tmk::geom::i128 = __int128
 GCC extension; exact products of nm coordinates.

Functions

i128 tmk::geom::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 tmk::geom::segments_intersect (Point a, Point b, Point c, Point d)
 True if closed segments ab and cd share at least one point.
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).
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).
long double tmk::geom::point_seg_dist (Point p, Point a, Point b)
 Distances in nm (not squared), for reporting (long double).
long double tmk::geom::seg_seg_dist (Point a, Point b, Point c, Point d)
bool tmk::geom::point_in_polygon (Point p, const std::vector< Point > &poly)
 Point in closed polygon (boundary counts as inside).
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.
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.
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).
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.
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).
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).

Detailed Description

Exact integer geometry for clearance checks (design doc 03 §1).

Every copper shape is a "rounded core": a point, an open polyline or a closed polygon, inflated by a radius r. Tracks are 2-point polylines with r = width/2, round pads are points, ovals are segments, round-rect pads are rectangles shrunk by the corner radius and inflated back. Gap tests compare squared distances in 128-bit integers, so "closer than" decisions are exact.

Definition in file shape.hpp.