Computational Geometry Primitives

FrechetDist builds on BasicCompGeometry for its geometric types and operations: Point (an SVector), Segment, Line, PntSeq (a polygonal curve), BBox, dist, convex_comb, and so on. See that package's documentation for them.

Floating-point primitives

The Frechet algorithms depend on a few primitives with specific floating-point behavior: convex_comb snaps to an endpoint when the parameter is within 1e-6 of it, nearest-point and segment-distance computations treat degenerate cases explicitly, and distances use @fastmath accumulation. These are kept here, with an fp_ prefix, so that results do not change with the BasicCompGeometry formulations.

FrechetDist.fp_convex_comb — Method
fp_convex_comb( p, q, t )

(1-t) p + t q, returning p and q exactly at t == 0 and t == 1. There is no snapping band: a fixed band in t moves points by a distance proportional to the edge length, which distorts long edges.

source
FrechetDist.fp_dist_point_segment — Method
fp_dist_point_segment( qr, s_p, s_q )

Distance from qr to the segment s_p-s_q, computed from the quadratic a t^2 + b t + c without constructing the nearest point. Values below FP_ZERO_SQ max(a, c) (squared rounding noise relative to the scale of the inputs) are reported as zero.

source
FrechetDist.fp_dist_segment_segment — Method
fp_dist_segment_segment( a_p, a_q, b_p, b_q )

Minimum distance between the segments a_p-a_q and b_p-b_q. Solves the 2x2 normal equations, snaps the solution to the segments, and takes the minimum with the four endpoint-to-segment distances. Parallel (rank one) systems fall back to the endpoint distances.

When det > 1e-8 trace^2 the system certainly has rank two (rank would need sigma2 / sigma1 <= 2 eps), and it is solved in closed form without allocating. Otherwise (nearly parallel or degenerate segments, overflow) the original rank / LAPACK path in fp_dist_segment_segment_lapack decides. Both give identical results; the closed form is about 30 times faster.

source
FrechetDist.fp_nn_point_ext_ext — Method
fp_nn_point_ext_ext

Nearest point on the segment s_p-s_q to qr, together with its convex combination coefficient. The caller must precompute

seg_len_sq = fp_dist_sq( s_p, s_q )
s_vec      = s_q - s_p
source
FrechetDist.fp_solve_sym2 — Method
fp_solve_sym2( m11, m12, m22, c1, c2 )

The solution of [m11 m12; m12 m22] \ [c1, c2], computed with the same operations as the dense solve (a diagonal solve when m12 == 0, else LU with partial pivoting that swaps only on a strictly larger pivot, and reciprocal-pivot scaling), so the result is bit-identical, without allocating.

source

Curve helpers

FrechetDist.Polygon_simplify_ext — Method
Polygon_simplify_ext

Simplify the input curve P: every vertex at distance larger than r from the last kept vertex is added to the simplification. Perhaps the cheapest and simplest simplification algorithm. Works for all measures. Returns the simplification and the indices of the vertices kept (both empty for an empty curve).

source
FrechetDist.point_dim — Method
point_dim(PT)

The dimension parameter N of event points and morphings with points of type PT: the length of a static vector, or AnyDim for points whose length is known only at run time.

source
FrechetDist.read_file — Function
read_file

Reads a curve from a text file with one point per line (see BasicCompGeometry.ReadWrite.read_plt). A curve with at most one point is completed to a two-point curve by repeating that point.

source
FrechetDist.remove_consecutive_duplicates — Method
remove_consecutive_duplicates( P )

The curve P without consecutive repeated vertices. Returns P itself when there are none, or when fewer than two distinct vertices would remain (a curve needs two vertices).

source