Expand description
Geometric math utilities.
Port of agg_math.h and agg_sqrt_tables.cpp — distances, intersections,
cross products, triangle operations, fast integer sqrt, and Bessel functions.
Constants§
- INTERSECTION_
EPSILON - Epsilon for intersection calculations.
- VERTEX_
DIST_ EPSILON - Coinciding points maximal distance (epsilon).
Functions§
- besj
- Bessel function of the first kind of order
n. - calc_
distance - Euclidean distance between two points.
- calc_
intersection - Calculate the intersection point of two line segments:
(ax,ay)→(bx,by) and (cx,cy)→(dx,dy).
Returns
Some((x, y))if they intersect,Noneif parallel. - calc_
line_ point_ distance - Signed distance from point (x, y) to the infinite line through (x1,y1)→(x2,y2). Positive means left side, negative means right side. If the line segment is degenerate (length < VERTEX_DIST_EPSILON), returns the distance from (x,y) to (x1,y1).
- calc_
orthogonal - Calculate the orthogonal displacement vector of magnitude
thicknessperpendicular to the line (x1,y1)→(x2,y2). - calc_
polygon_ area - Signed area of a polygon defined by a slice of points with
xandyfields. - calc_
polygon_ area_ vd - Signed area of a polygon defined by a slice of
VertexDist. Same algorithm ascalc_polygon_areabut works withVertexDistslices (needed byvcgen_contour). - calc_
segment_ point_ sq_ distance - Squared distance from point (x, y) to the closest point on segment (x1,y1)→(x2,y2).
- calc_
segment_ point_ sq_ distance_ with_ u - Squared distance from point (x, y) to the closest point on segment
(x1,y1)→(x2,y2), given pre-computed parameter
u. - calc_
segment_ point_ u - Compute the parameter
ufor the projection of point (x, y) onto the line segment (x1,y1)→(x2,y2). Returns 0 if the segment is degenerate. - calc_
sq_ distance - Squared Euclidean distance between two points.
- calc_
triangle_ area - Signed area of triangle (x1,y1), (x2,y2), (x3,y3).
- cross_
product - Cross product of vectors (x2-x1, y2-y1) and (x-x2, y-y2). The sign indicates which side of the line (x1,y1)→(x2,y2) the point (x,y) is on.
- dilate_
triangle - Dilate a triangle by distance
d, producing 6 output points (two per edge). Returns([x0..x5], [y0..y5]). - fast_
sqrt - Fast integer square root using lookup tables.
No divisions, multiplications, or loops — just bit shifts and table lookups.
Port of C++
fast_sqrt(portable C path). - intersection_
exists - Quick check whether two line segments (x1,y1)→(x2,y2) and (x3,y3)→(x4,y4) intersect (boundary excluded).
- point_
in_ triangle - Test if point (x, y) is inside triangle (x1,y1), (x2,y2), (x3,y3).