svg_path_editor.intersect ========================= .. py:module:: svg_path_editor.intersect Attributes ---------- .. autoapisummary:: svg_path_editor.intersect.Expr svg_path_editor.intersect.Symbol svg_path_editor.intersect.AnyBoolean Classes ------- .. autoapisummary:: svg_path_editor.intersect.Intersection svg_path_editor.intersect.LineIntersection svg_path_editor.intersect.LineCoincidentIntersection svg_path_editor.intersect.LineAroundIntersection svg_path_editor.intersect.LineArcIntersection svg_path_editor.intersect.LineArcExtIntersection svg_path_editor.intersect.LineArcAroundIntersection svg_path_editor.intersect.ArcArcIntersection svg_path_editor.intersect.ArcArcExtIntersection svg_path_editor.intersect.ArcArcAroundIntersection Functions --------- .. autoapisummary:: svg_path_editor.intersect.intersect svg_path_editor.intersect.intersect_lines_raw svg_path_editor.intersect.intersect_lines svg_path_editor.intersect.intersect_line_arc svg_path_editor.intersect.intersect_arc_arc Module Contents --------------- .. py:type:: Expr :canonical: 'sp.Expr' .. py:type:: Symbol :canonical: 'sp.Symbol' .. py:type:: AnyBoolean :canonical: bool | Boolean .. py:class:: Intersection Bases: :py:obj:`Protocol` Common protocol for intersection results. :ivar intersection: The intersection point. .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:function:: intersect(a: svg_path_editor.geometry.Line, b: svg_path_editor.geometry.Line, *, d: decimal.Decimal | None = None, n: svg_path_editor.math.Precision | None = None) -> LineIntersection | LineCoincidentIntersection | LineAroundIntersection | None intersect(a: svg_path_editor.geometry.Line, b: svg_path_editor.geometry.ParametricEllipticalArc, *, d: decimal.Decimal | None = None, n: svg_path_editor.math.Precision | None = None) -> LineArcIntersection | LineArcExtIntersection | LineArcAroundIntersection | None intersect(a: svg_path_editor.geometry.ParametricEllipticalArc, b: svg_path_editor.geometry.Line, *, d: decimal.Decimal | None = None, n: svg_path_editor.math.Precision | None = None) -> LineArcIntersection | LineArcExtIntersection | LineArcAroundIntersection | None intersect(a: svg_path_editor.geometry.ParametricEllipticalArc, b: svg_path_editor.geometry.ParametricEllipticalArc, *, d: decimal.Decimal | None = None, n: svg_path_editor.math.Precision | None = None) -> ArcArcIntersection | ArcArcExtIntersection | ArcArcAroundIntersection | None Public intersection helper. Dispatches to the appropriate specialized routine using structural pattern matching on the argument types. :param a: First primitive (line or arc). :param b: Second primitive (line or arc). :param d: Optional offset distance used only in “around” fallbacks. :param n: Optional precision for SymPy evaluations. :return: An intersection record or ``None`` if nothing applicable is found. .. py:class:: LineIntersection Intersection of two parameterized lines. Parameters :attr:`t` and :attr:`u` satisfy .. math:: p_0 + (q_0 - p_0)\,t = p_1 + (q_1 - p_1)\,u. :ivar t: Parameter on the first line. :ivar u: Parameter on the second line. :ivar intersection: Common point. .. py:attribute:: t :type: Expr .. py:attribute:: u :type: Expr .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:property:: swapped :type: Self Swap coordinates of the intersection point. .. py:class:: LineCoincidentIntersection Degenerate “intersection” of coincident parametric lines. Used when two lines lie on top of each other. A single representative point is stored. :ivar t: Chosen parameter on the first line. :ivar u: Corresponding parameter on the second line. :ivar intersection: Common endpoint on the coincident line. .. py:attribute:: t :type: Expr .. py:attribute:: u :type: Expr .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:property:: swapped :type: Self Swap coordinates of the intersection point. .. py:class:: LineAroundIntersection 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. :ivar intersection: Midpoint of the constructed connection. :ivar ante_intersection: End of the first segment. :ivar post_intersection: Start of the second segment. :ivar ante_extended: Offset from :attr:`ante_intersection` along the first line. :ivar post_extended: Offset from :attr:`post_intersection` along the second line. .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: ante_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: ante_extended :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_extended :type: svg_path_editor.geometry.Vec2 .. py:function:: intersect_lines_raw(l0, l1, *, n = None) Raw line-line intersection without segment clipping. Solves for parameters :math:`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 :math:`l_0`. :param l0: First parametric line (infinite). :param l1: Second parametric line (infinite). :param n: Optional precision for intermediate evaluation. .. py:function:: intersect_lines(l0, l1, *, d = None, n = None) Segment-segment intersection. Returns the line-line intersection if it lies within both segments, i.e. :math:`t, u ∈ [0, 1]`. If no intersection exists and ``d`` is given, returns a :class:`LineAroundIntersection` constructed from the closest endpoints. :param l0: First line segment. :param l1: Second line segment. :param d: Optional offset distance for constructing an “around” connector. :param n: Optional precision for :func:`intersect_lines_raw`. .. py:class:: LineArcIntersection Intersection of a line with the interior of an elliptical arc. :attr:`t` is the line parameter, :attr:`theta` is the ellipse parameter in degrees. :ivar t: Parameter along the line segment. :ivar theta: Angle parameter on the arc in degrees. :ivar intersection: Common point. .. py:attribute:: t :type: Expr .. py:attribute:: theta :type: Expr .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:class:: LineArcExtIntersection 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. :ivar t: Parameter along the line. :ivar u: Parameter along the tangent half-line. :ivar intersection: Common point of the line and tangent. :ivar post_intersection: Endpoint of the arc used for the tangent. :ivar theta: Angle of the tangent point in degrees. :ivar ext: Which endpoint tangent is used (``"ante"`` or ``"post"``). .. py:attribute:: t :type: Expr .. py:attribute:: u :type: Expr .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: theta :type: Expr .. py:attribute:: ext :type: Literal['ante', 'post'] .. py:class:: LineArcAroundIntersection 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. :ivar intersection: Midpoint of the constructed connection. :ivar ante_intersection: End of the line or arc reached first. :ivar post_intersection: Start of the following primitive. :ivar ante_extended: Offset point from :attr:`ante_intersection`. :ivar post_extended: Offset point from :attr:`post_intersection`. .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: ante_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: ante_extended :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_extended :type: svg_path_editor.geometry.Vec2 .. py:function:: intersect_line_arc(lin, arc, *, line_before_arc, d, n) 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. :param lin: Line segment. :param arc: Elliptical arc. :param line_before_arc: If ``True``, the line precedes the arc in path order. :param d: Optional offset distance for an “around” configuration. :param n: Optional precision for internal SymPy calls. .. py:class:: ArcArcIntersection Intersection of two elliptical arcs. :attr:`theta0` and :attr:`theta1` are the ellipse parameters at the common point on the first and second arc, respectively (in degrees). :ivar theta0: Angle on the first arc in degrees. :ivar theta1: Angle on the second arc in degrees. :ivar intersection: Common point. .. py:attribute:: theta0 :type: Expr .. py:attribute:: theta1 :type: Expr .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:class:: ArcArcExtIntersection Intersection of the tangent half-lines of two arcs. :attr:`t` and :attr:`u` are the parameters along those half-lines. :ivar t: Parameter along the tangent from the first arc. :ivar u: Parameter along the tangent from the second arc. :ivar intersection: Intersection of the two tangent half-lines. :ivar ante_intersection: Tangent point on the first arc. :ivar post_intersection: Tangent point on the second arc. .. py:attribute:: t :type: Expr .. py:attribute:: u :type: Expr .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: ante_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_intersection :type: svg_path_editor.geometry.Vec2 .. py:class:: ArcArcAroundIntersection Fallback “around” configuration when arcs neither meet nor converge. Used to synthesize a connection via offset tangent points. :ivar intersection: Midpoint of the constructed connection. :ivar ante_intersection: End of the first arc. :ivar post_intersection: Start of the second arc. :ivar ante_extended: Offset from :attr:`ante_intersection`. :ivar post_extended: Offset from :attr:`post_intersection`. .. py:attribute:: intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: ante_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_intersection :type: svg_path_editor.geometry.Vec2 .. py:attribute:: ante_extended :type: svg_path_editor.geometry.Vec2 .. py:attribute:: post_extended :type: svg_path_editor.geometry.Vec2 .. py:function:: intersect_arc_arc(arc0, arc1, *, d = None, n = None) Intersect two elliptical arcs. 1. Compute the resultant of their implicit equations to eliminate :math:`y`. 2. Solve for candidate :math:`x` and refine to :math:`(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. :param arc0: First elliptical arc. :param arc1: Second elliptical arc. :param d: Optional offset distance for an “around” configuration. :param n: Optional precision for internal SymPy roots. :return: Any of the arc-arc intersection variants, or ``None``.