svg_path/intersections

Point-intersection queries for SVG path geometry.

This module owns segment, subpath, path, and self-intersection search. Result types are the root svg_path types, such as svg_path.SegmentIntersection, svg_path.SubpathIntersection, and svg_path.PathIntersection.

Types

Errors returned while classifying subpath intersections.

pub type ClassificationError {
  PathError(svg_path.Error)
  InvalidAngularTolerance(Float)
  InvalidClassificationDistanceTolerance(Float)
  InvalidClassificationInitialArcLength(Float)
  InvalidClassificationMaximumArcLength(Float)
  InvalidClassificationMaxSamplingSteps(Int)
}

Constructors

  • PathError(svg_path.Error)

    An underlying path direction query failed.

  • InvalidAngularTolerance(Float)

    Angular tolerance must be finite and in [0, 180) degrees.

  • InvalidClassificationDistanceTolerance(Float)

    Distance tolerance must be finite and non-negative.

  • InvalidClassificationInitialArcLength(Float)

    Initial arc length must be finite and greater than zero.

  • InvalidClassificationMaximumArcLength(Float)

    Maximum arc length must be finite and at least the initial arc length.

  • InvalidClassificationMaxSamplingSteps(Int)

    At least one sampling step is required.

Options for classifying one addressed subpath intersection.

pub type ClassificationOptions {
  ClassificationOptions(
    direction_options: svg_path.DirectionOptions,
    angular_tolerance: Float,
    distance_tolerance: Float,
    length_options: svg_path.LengthOptions,
    initial_arc_length: Float,
    maximum_arc_length: Float,
    max_sampling_steps: Int,
  )
}

Constructors

  • ClassificationOptions(
      direction_options: svg_path.DirectionOptions,
      angular_tolerance: Float,
      distance_tolerance: Float,
      length_options: svg_path.LengthOptions,
      initial_arc_length: Float,
      maximum_arc_length: Float,
      max_sampling_steps: Int,
    )

    Arguments

    direction_options

    Options used to recover singularity-safe path directions.

    angular_tolerance

    Angles at or below this many degrees are treated as coincident. Zero compares direction headings exactly.

    distance_tolerance

    Minimum trusted path-coordinate distance from the intersection.

    length_options

    Length options used to locate samples along each subpath.

    initial_arc_length

    First traveled distance used for nontransverse branch sampling.

    maximum_arc_length

    Largest traveled distance permitted for local branch sampling.

    max_sampling_steps

    Maximum number of successively doubled arc-length samples.

One parameter pair and its local intersection classification.

pub type ClassifiedSubpathIntersection {
  ClassifiedSubpathIntersection(
    first_parameter: svg_path.SubpathParameter,
    second_parameter: svg_path.SubpathParameter,
    classification: IntersectionClassification,
  )
}

Constructors

The oriented sense in which the second traversal crosses the first.

pub type CrossingDirection {
  Clockwise
  Counterclockwise
}

Constructors

  • Clockwise
  • Counterclockwise

Which endpoint/interior relationship occurs at an intersection.

pub type EndpointContact {
  FirstEndpointToSecondInterior(first: SubpathEndpoint)
  FirstInteriorToSecondEndpoint(second: SubpathEndpoint)
  EndpointToEndpoint(
    first: SubpathEndpoint,
    second: SubpathEndpoint,
  )
}

Constructors

The four clockwise apertures between the two subpath traversal directions.

Values are angles in degrees in [0, 360). Unlike TouchingOrder, these fields use traversal-oriented directions directly: an incoming direction points toward the intersection and an outgoing direction points away from it. In particular, the incoming apertures are not measured between the negated, outward-pointing incoming directions.

pub type IntersectionApertures {
  IntersectionApertures(
    first_incoming_to_second_incoming: Float,
    first_incoming_to_second_outgoing: Float,
    first_outgoing_to_second_incoming: Float,
    first_outgoing_to_second_outgoing: Float,
  )
}

Constructors

  • IntersectionApertures(
      first_incoming_to_second_incoming: Float,
      first_incoming_to_second_outgoing: Float,
      first_outgoing_to_second_incoming: Float,
      first_outgoing_to_second_outgoing: Float,
    )

The local topology of one addressed subpath intersection.

pub type IntersectionClassification {
  Crossing(
    direction: CrossingDirection,
    apertures: IntersectionApertures,
  )
  Touching(
    direction: TouchingDirection,
    incoming_order: TouchingOrder,
    outgoing_order: TouchingOrder,
    apertures: IntersectionApertures,
  )
  EndpointContact(EndpointContact)
  Indeterminate
}

Constructors

  • Crossing(
      direction: CrossingDirection,
      apertures: IntersectionApertures,
    )

    The two traversals pass through one another.

  • Touching(
      direction: TouchingDirection,
      incoming_order: TouchingOrder,
      outgoing_order: TouchingOrder,
      apertures: IntersectionApertures,
    )

    The traversals meet without alternating around the intersection.

    incoming_order and outgoing_order describe the visible geometric branches using outward-pointing rays sampled at equal arc lengths. The apertures payload instead records the exact traversal-direction convention documented by IntersectionApertures.

  • EndpointContact(EndpointContact)

    At least one address is an endpoint of an open subpath.

  • Indeterminate

    A required local direction could not be recovered.

Options for finding segment, subpath, and path intersections.

pub type IntersectionOptions {
  IntersectionOptions(tolerance: Float, max_depth: Int)
}

Constructors

  • IntersectionOptions(tolerance: Float, max_depth: Int)

    Arguments

    tolerance

    Path-coordinate distance used for geometric coincidence tests.

    max_depth

    Maximum recursive subdivision depth for one segment pair.

An endpoint of an open subpath traversal.

pub type SubpathEndpoint {
  StartEndpoint
  EndEndpoint
}

Constructors

  • StartEndpoint
  • EndEndpoint

The relative traversal direction at a tangential contact.

pub type TouchingDirection {
  SimilarlyDirected
  OppositelyDirected
}

Constructors

  • SimilarlyDirected
  • OppositelyDirected

Clockwise order of two outward-pointing sampled rays near a nontransverse contact.

On the incoming side, each ray points from the intersection backward along its traversal, opposite to the incoming traversal direction. On the outgoing side, each ray points forward along its traversal. Oppositely directed contacts compare the incoming branch of one traversal with the outgoing branch of the other so that each value describes one geometric side of the contact.

pub type TouchingOrder {
  ClockwiseFromFirstToSecond
  ClockwiseFromSecondToFirst
  IndeterminateTouchingOrder
}

Constructors

  • ClockwiseFromFirstToSecond
  • ClockwiseFromSecondToFirst
  • IndeterminateTouchingOrder

Values

pub fn classify_grouped_subpath_intersection(
  first: svg_path.Subpath,
  second: svg_path.Subpath,
  intersection: svg_path.SubpathIntersection,
) -> Result(
  List(ClassifiedSubpathIntersection),
  ClassificationError,
)

Classify every first/second parameter pair represented by one grouped subpath intersection.

pub fn classify_grouped_subpath_intersection_with(
  first: svg_path.Subpath,
  second: svg_path.Subpath,
  intersection: svg_path.SubpathIntersection,
  options options: ClassificationOptions,
) -> Result(
  List(ClassifiedSubpathIntersection),
  ClassificationError,
)

Classify every parameter pair using explicit options.

pub fn classify_subpath_intersection(
  first: svg_path.Subpath,
  second: svg_path.Subpath,
  first_parameter first_parameter: svg_path.SubpathParameter,
  second_parameter second_parameter: svg_path.SubpathParameter,
) -> Result(IntersectionClassification, ClassificationError)

Classify one explicitly addressed intersection between two subpaths.

This operation does not search for or verify an intersection. The two parameters are interpreted as addresses of the same already-known point. Endpoint contacts are classified before local directions are evaluated. Transverse intersections are classified from singularity-safe directions; nontransverse branch order is determined from equal-arc-length samples.

pub fn classify_subpath_intersection_with(
  first: svg_path.Subpath,
  second: svg_path.Subpath,
  first_parameter first_parameter: svg_path.SubpathParameter,
  second_parameter second_parameter: svg_path.SubpathParameter,
  options options: ClassificationOptions,
) -> Result(IntersectionClassification, ClassificationError)

Classify one explicitly addressed intersection using explicit options.

pub fn default_classification_options() -> ClassificationOptions

Return the default options for intersection classification.

The direction-relative tolerance is 0.000000001; the angular tolerance is 0.0000001 degrees. Nontransverse contacts are sampled first at an arc length of 0.000001, doubling up to 0.25 path-coordinate units.

pub fn default_options() -> IntersectionOptions

Return the default options for segment, subpath, and path intersection detection.

The default tolerance is 0.000000001 path-coordinate units and the default maximum subdivision depth is 48.

pub fn default_self_intersection_options() -> svg_path.SelfIntersectionOptions

Return the default options for subpath and path self-intersection detection.

pub fn path(
  left: svg_path.Path,
  right: svg_path.Path,
) -> Result(List(svg_path.PathIntersection), svg_path.Error)

Return the point intersections between two paths.

Each result contains an intersection point and every corresponding parameter on both paths. Results are ordered by the first left parameter. Segment-boundary aliases are canonicalized to one traversal address. A continuous overlap between any segment pair returns OverlappingSegments.

pub fn path_self(
  path: svg_path.Path,
) -> Result(List(svg_path.PathSelfIntersection), svg_path.Error)

Return point intersections where a path intersects itself.

This includes self-intersections inside one subpath and intersections between distinct subpaths in the same path. Results are ordered by the first path parameter. A continuous overlap between distinct constituent segments returns OverlappingSegments.

pub fn path_self_with(
  path: svg_path.Path,
  options options: svg_path.SelfIntersectionOptions,
) -> Result(List(svg_path.PathSelfIntersection), svg_path.Error)

Return point intersections where a path intersects itself using explicit options.

pub fn path_with(
  left: svg_path.Path,
  right: svg_path.Path,
  options options: IntersectionOptions,
) -> Result(List(svg_path.PathIntersection), svg_path.Error)

Return the point intersections between two paths using explicit options.

pub fn segment(
  left: svg_path.Segment,
  right: svg_path.Segment,
) -> Result(List(svg_path.SegmentIntersection), svg_path.Error)

Return point intersections between two segments.

Overlapping segments return OverlappingSegments, since they have more than a finite list of point intersections.

pub fn segment_self(
  segment: svg_path.Segment,
) -> Result(List(svg_path.SegmentIntersection), svg_path.Error)

Return point intersections where a segment intersects itself.

Straight lines and quadratic Beziers do not report self-intersections. Cubic Beziers can self-intersect, including at separated parameters that evaluate to the same endpoint. An arc whose start and end coincide reports that endpoint pair when both radii are nonzero.

pub fn segment_self_with(
  segment: svg_path.Segment,
  options options: svg_path.SelfIntersectionOptions,
) -> Result(List(svg_path.SegmentIntersection), svg_path.Error)

Return point intersections where a segment intersects itself using explicit options.

pub fn segment_subpath(
  segment: svg_path.Segment,
  subpath: svg_path.Subpath,
) -> Result(
  List(#(svg_path.Point, Float, List(svg_path.SubpathParameter))),
  svg_path.Error,
)

Return the intersections between a segment and a subpath.

Each result contains an intersection point, its local parameter on the standalone segment, and every corresponding parameter on the subpath. Results are ordered by the standalone segment parameter. Segment-boundary aliases are canonicalized to one traversal address. A continuous overlap with any segment of the subpath returns OverlappingSegments.

pub fn segment_subpath_with(
  segment: svg_path.Segment,
  subpath: svg_path.Subpath,
  options options: IntersectionOptions,
) -> Result(
  List(#(svg_path.Point, Float, List(svg_path.SubpathParameter))),
  svg_path.Error,
)

Return the intersections between a segment and a subpath using explicit options.

pub fn segment_with(
  left: svg_path.Segment,
  right: svg_path.Segment,
  options options: IntersectionOptions,
) -> Result(List(svg_path.SegmentIntersection), svg_path.Error)

Return point intersections between two segments using explicit options.

pub fn subpath(
  left: svg_path.Subpath,
  right: svg_path.Subpath,
) -> Result(List(svg_path.SubpathIntersection), svg_path.Error)

Return the point intersections between two subpaths.

Each result contains an intersection point and every corresponding parameter on both subpaths. Results are ordered by the first left parameter. Segment-boundary aliases are canonicalized to one traversal address. A continuous overlap between any segment pair returns OverlappingSegments.

pub fn subpath_self(
  subpath: svg_path.Subpath,
) -> Result(
  List(svg_path.SubpathSelfIntersection),
  svg_path.Error,
)

Return point intersections where a subpath intersects itself.

Results are ordered by the first parameter. Adjacent segment endpoints are filtered by arc-length separation, so ordinary segment joins are not reported as self-intersections. A continuous overlap between two distinct constituent segments returns OverlappingSegments.

pub fn subpath_self_with(
  subpath: svg_path.Subpath,
  options options: svg_path.SelfIntersectionOptions,
) -> Result(
  List(svg_path.SubpathSelfIntersection),
  svg_path.Error,
)

Return point intersections where a subpath intersects itself using explicit options.

pub fn subpath_with(
  left: svg_path.Subpath,
  right: svg_path.Subpath,
  options options: IntersectionOptions,
) -> Result(List(svg_path.SubpathIntersection), svg_path.Error)

Return the point intersections between two subpaths using explicit options.

Search Document