svg_path_editor.intersect#

Attributes#

Classes#

Intersection

Common protocol for intersection results.

LineIntersection

Intersection of two parameterized lines.

LineCoincidentIntersection

Degenerate “intersection” of coincident parametric lines.

LineAroundIntersection

Fallback “around” configuration for two line segments.

LineArcIntersection

Intersection of a line with the interior of an elliptical arc.

LineArcExtIntersection

Intersection of a line with an arc’s tangent half-line.

LineArcAroundIntersection

Fallback “around” configuration for a line and an arc.

ArcArcIntersection

Intersection of two elliptical arcs.

ArcArcExtIntersection

Intersection of the tangent half-lines of two arcs.

ArcArcAroundIntersection

Fallback “around” configuration when arcs neither meet nor converge.

Functions#

intersect(…)

Public intersection helper.

intersect_lines_raw(l0, l1, *[, n])

Raw line-line intersection without segment clipping.

intersect_lines(l0, l1, *[, d, n])

Segment-segment intersection.

intersect_line_arc(lin, arc, *, line_before_arc, d, n)

Intersect a line segment with an elliptical arc and its tangents.

intersect_arc_arc(arc0, arc1, *[, d, n])

Intersect two elliptical arcs.

Module Contents#

type svg_path_editor.intersect.Expr = 'sp.Expr'#
type svg_path_editor.intersect.Symbol = 'sp.Symbol'#
type svg_path_editor.intersect.AnyBoolean = bool | Boolean#
class svg_path_editor.intersect.Intersection[source]#

Bases: Protocol

Common protocol for intersection results.

Variables:

intersection – The intersection point.

intersection: Vec2#
svg_path_editor.intersect.intersect(a: Line, b: Line, *, d: decimal.Decimal | None = None, n: Precision | None = None) LineIntersection | LineCoincidentIntersection | LineAroundIntersection | None[source]#
svg_path_editor.intersect.intersect(a: Line, b: ParametricEllipticalArc, *, d: decimal.Decimal | None = None, n: Precision | None = None) LineArcIntersection | LineArcExtIntersection | LineArcAroundIntersection | None
svg_path_editor.intersect.intersect(a: ParametricEllipticalArc, b: Line, *, d: decimal.Decimal | None = None, n: Precision | None = None) LineArcIntersection | LineArcExtIntersection | LineArcAroundIntersection | None
svg_path_editor.intersect.intersect(a: ParametricEllipticalArc, b: ParametricEllipticalArc, *, d: decimal.Decimal | None = None, n: Precision | None = None) ArcArcIntersection | ArcArcExtIntersection | ArcArcAroundIntersection | None

Public intersection helper.

Dispatches to the appropriate specialized routine using structural pattern matching on the argument types.

Parameters:
  • a – First primitive (line or arc).

  • b – Second primitive (line or arc).

  • d – Optional offset distance used only in “around” fallbacks.

  • n – Optional precision for SymPy evaluations.

Returns:

An intersection record or None if nothing applicable is found.

class svg_path_editor.intersect.LineIntersection[source]#

Intersection of two parameterized lines.

Parameters t and u satisfy

\[p_0 + (q_0 - p_0)\,t = p_1 + (q_1 - p_1)\,u.\]
Variables:
  • t – Parameter on the first line.

  • u – Parameter on the second line.

  • intersection – Common point.

t: Expr#
u: Expr#
intersection: Vec2#
property swapped: Self#

Swap coordinates of the intersection point.

Return type:

Self

class svg_path_editor.intersect.LineCoincidentIntersection[source]#

Degenerate “intersection” of coincident parametric lines.

Used when two lines lie on top of each other. A single representative point is stored.

Variables:
  • t – Chosen parameter on the first line.

  • u – Corresponding parameter on the second line.

  • intersection – Common endpoint on the coincident line.

t: Expr#
u: Expr#
intersection: Vec2#
property swapped: Self#

Swap coordinates of the intersection point.

Return type:

Self

class svg_path_editor.intersect.LineAroundIntersection[source]#

Fallback “around” configuration for two line segments.

The segments neither meet nor their endpoint-endpoint connector lies on both segments. This synthesizes a connection via an intermediate point.

Variables:
  • intersection – Midpoint of the constructed connection.

  • ante_intersection – End of the first segment.

  • post_intersection – Start of the second segment.

  • ante_extended – Offset from ante_intersection along the first line.

  • post_extended – Offset from post_intersection along the second line.

intersection: Vec2#
ante_intersection: Vec2#
post_intersection: Vec2#
ante_extended: Vec2#
post_extended: Vec2#
svg_path_editor.intersect.intersect_lines_raw(l0, l1, *, n=None)[source]#

Raw line-line intersection without segment clipping.

Solves for parameters \(t, u\) such that the two parametric lines meet. Returns None when they are parallel and distinct.

Degenerate collinear overlap is represented by picking the end of \(l_0\).

Parameters:
  • l0 (Line) – First parametric line (infinite).

  • l1 (Line) – Second parametric line (infinite).

  • n (Precision | None) – Optional precision for intermediate evaluation.

Return type:

LineIntersection | LineCoincidentIntersection | None

svg_path_editor.intersect.intersect_lines(l0, l1, *, d=None, n=None)[source]#

Segment-segment intersection.

Returns the line-line intersection if it lies within both segments, i.e. \(t, u ∈ [0, 1]\).

If no intersection exists and d is given, returns a LineAroundIntersection constructed from the closest endpoints.

Parameters:
  • l0 (Line) – First line segment.

  • l1 (Line) – Second line segment.

  • d (decimal.Decimal | None) – Optional offset distance for constructing an “around” connector.

  • n (Precision | None) – Optional precision for intersect_lines_raw().

Return type:

LineIntersection | LineCoincidentIntersection | LineAroundIntersection | None

class svg_path_editor.intersect.LineArcIntersection[source]#

Intersection of a line with the interior of an elliptical arc.

t is the line parameter, theta is the ellipse parameter in degrees.

Variables:
  • t – Parameter along the line segment.

  • theta – Angle parameter on the arc in degrees.

  • intersection – Common point.

t: Expr#
theta: Expr#
intersection: Vec2#
class svg_path_editor.intersect.LineArcExtIntersection[source]#

Intersection of a line with an arc’s tangent half-line.

Covers the half-lines defined by tangents at the arc endpoints:

  • ext="ante": tangent at start angle, extended backwards.

  • ext="post": tangent at end angle, extended forwards.

Variables:
  • t – Parameter along the line.

  • u – Parameter along the tangent half-line.

  • intersection – Common point of the line and tangent.

  • post_intersection – Endpoint of the arc used for the tangent.

  • theta – Angle of the tangent point in degrees.

  • ext – Which endpoint tangent is used ("ante" or "post").

t: Expr#
u: Expr#
intersection: Vec2#
post_intersection: Vec2#
theta: Expr#
ext: Literal['ante', 'post']#
class svg_path_editor.intersect.LineArcAroundIntersection[source]#

Fallback “around” configuration for a line and an arc.

Used when the line segment does not intersect the arc or its endpoint tangent half-lines. Synthesizes a connection via offset points.

Variables:
  • intersection – Midpoint of the constructed connection.

  • ante_intersection – End of the line or arc reached first.

  • post_intersection – Start of the following primitive.

  • ante_extended – Offset point from ante_intersection.

  • post_extended – Offset point from post_intersection.

intersection: Vec2#
ante_intersection: Vec2#
post_intersection: Vec2#
ante_extended: Vec2#
post_extended: Vec2#
svg_path_editor.intersect.intersect_line_arc(lin, arc, *, line_before_arc, d, n)[source]#

Intersect a line segment with an elliptical arc and its tangents.

  1. Intersect the line with the full ellipse in ellipse-local coordinates.

  2. Filter hits whose line-parameter and arc-angle lie on the segment/arc.

  3. If none, intersect the appropriate endpoint tangent half-line.

  4. If still none and d is given, synthesize an “around” configuration.

The first valid solution encountered is returned.

Parameters:
  • lin (Line) – Line segment.

  • arc (ParametricEllipticalArc) – Elliptical arc.

  • line_before_arc (bool) – If True, the line precedes the arc in path order.

  • d (decimal.Decimal | None) – Optional offset distance for an “around” configuration.

  • n (Precision | None) – Optional precision for internal SymPy calls.

Return type:

LineArcIntersection | LineArcExtIntersection | LineArcAroundIntersection | None

class svg_path_editor.intersect.ArcArcIntersection[source]#

Intersection of two elliptical arcs.

theta0 and theta1 are the ellipse parameters at the common point on the first and second arc, respectively (in degrees).

Variables:
  • theta0 – Angle on the first arc in degrees.

  • theta1 – Angle on the second arc in degrees.

  • intersection – Common point.

theta0: Expr#
theta1: Expr#
intersection: Vec2#
class svg_path_editor.intersect.ArcArcExtIntersection[source]#

Intersection of the tangent half-lines of two arcs.

t and u are the parameters along those half-lines.

Variables:
  • t – Parameter along the tangent from the first arc.

  • u – Parameter along the tangent from the second arc.

  • intersection – Intersection of the two tangent half-lines.

  • ante_intersection – Tangent point on the first arc.

  • post_intersection – Tangent point on the second arc.

t: Expr#
u: Expr#
intersection: Vec2#
ante_intersection: Vec2#
post_intersection: Vec2#
class svg_path_editor.intersect.ArcArcAroundIntersection[source]#

Fallback “around” configuration when arcs neither meet nor converge.

Used to synthesize a connection via offset tangent points.

Variables:
  • intersection – Midpoint of the constructed connection.

  • ante_intersection – End of the first arc.

  • post_intersection – Start of the second arc.

  • ante_extended – Offset from ante_intersection.

  • post_extended – Offset from post_intersection.

intersection: Vec2#
ante_intersection: Vec2#
post_intersection: Vec2#
ante_extended: Vec2#
post_extended: Vec2#
svg_path_editor.intersect.intersect_arc_arc(arc0, arc1, *, d=None, n=None)[source]#

Intersect two elliptical arcs.

  1. Compute the resultant of their implicit equations to eliminate \(y\).

  2. Solve for candidate \(x\) and refine to \((x, y)\) intersection points.

  3. Map to angular parameters on both arcs and check angle ranges.

  4. If no interior intersection exists, intersect the endpoint tangents.

  5. As a last resort, construct an “around” configuration using offsets.

Parameters:
  • arc0 (ParametricEllipticalArc) – First elliptical arc.

  • arc1 (ParametricEllipticalArc) – Second elliptical arc.

  • d (decimal.Decimal | None) – Optional offset distance for an “around” configuration.

  • n (Precision | None) – Optional precision for internal SymPy roots.

Returns:

Any of the arc-arc intersection variants, or None.

Return type:

ArcArcIntersection | ArcArcExtIntersection | ArcArcAroundIntersection | None