svg_path/convex_hull
Convex hull helpers for paths, subpaths, segments, and points.
This module computes closed hulls. Lines, quadratic Beziers, and arcs have semantic hulls: the primitive itself plus the chord joining its endpoints, with tiny/point-like cases collapsed to lines. Cubic Beziers use a cubic-specific support/event solver.
Types
pub type HullError {
PathError(svg_path.Error)
ConsecutiveCurves
DuplicateAdjacentTValues
RefinementReachedMaxIterations(Int)
PurificationReachedMaxIterations(Int)
LoopUnionCollapsed
TangentSearchDegenerateLoop
TangentSearchNonConvexVertex(Int)
TangentSearchExpectedTwoTangencies(Int)
SeededWorstDirectionExceededThreshold(Float, Float)
}
Constructors
-
PathError(svg_path.Error)The generated hull segments could not be converted into a valid closed
Subpath. -
ConsecutiveCurvesThe final hull-piece sequence failed the invariant that curve pieces must be separated by line pieces.
-
DuplicateAdjacentTValuesThe refined support samples still contained adjacent duplicate segment parameters.
-
RefinementReachedMaxIterations(Int)Support-sample refinement did not settle before the iteration limit.
-
PurificationReachedMaxIterations(Int)Support-sample simplification did not settle before the iteration limit.
-
LoopUnionCollapsedConvex-loop union collapsed to no boundary pieces.
-
TangentSearchDegenerateLoopTangent search expected a non-degenerate chord polygon.
-
TangentSearchNonConvexVertex(Int)Tangent search found a locally non-convex chord-polygon vertex.
-
TangentSearchExpectedTwoTangencies(Int)Tangent search did not find exactly two tangent transitions.
-
SeededWorstDirectionExceededThreshold(Float, Float)Seeded worst-direction search grew past its allowed interval width.
pub type PointLoopView {
TangentPoint
OutsidePoint
InsidePoint
}
Constructors
-
TangentPoint -
OutsidePoint -
InsidePoint
Values
pub fn path_hull(
path: svg_path.Path,
) -> Result(svg_path.Subpath, HullError)
Compute the convex hull of a path.
Move-only subpaths are treated as single points at their starts. The result is a single closed subpath containing the hull of every subpath in the input path.
pub fn points_hull(
points: List(vec2.Vec2(Float)),
) -> Result(svg_path.Subpath, HullError)
Compute the convex hull of a list of points.
The result is a single closed subpath containing every input point.
pub fn segment_hull(
segment: svg_path.Segment,
) -> Result(svg_path.Subpath, HullError)
pub fn subpath_hull(
subpath: svg_path.Subpath,
) -> Result(svg_path.Subpath, HullError)
Compute the convex hull of a subpath.
The result is a closed subpath. Move-only subpaths are treated as a single point at their start. Otherwise each individual segment is first converted to its own convex hull, then those convex loops are unioned one at a time.