svg_path_editor.path_offset#

Attributes#

Shape

additional_digits

Extra decimal digits used when prec="auto".

Classes#

_OffsetData

Precomputed data for offsetting a simple closed path.

Tri

Small bevel triangle between original and offset geometry.

BevelPolygon

Planar bevel face bounded by straight segments.

BevelArced

Planar bevel face containing an elliptical-arc boundary.

Functions#

_all_non_none(elems)

Return True iff elems contains no None values.

_prepare_offset_data(path, *, d, prec)

Validate path and compute offset segments and their intersections.

_line_outgoing_point(inter1)

Outgoing point of a line offset segment (after inter1).

_arc_outgoing_point(inter1)

Outgoing point of an arc offset segment (after inter1).

outward_normal(p0, p1, is_ccw)

Compute the outward unit normal of an edge.

_iter_segment_contexts(offsets, inters, items)

Yield (orig_item, offset_geom, incoming_inter, outgoing_inter) per segment.

_arc_ante(orig, inter0)

Handle the incoming side of an offset arc.

_arc_post(orig, inter1)

Handle the outgoing side of an offset arc.

_line_ante(orig, inter0)

Handle the incoming side of a straight segment.

offset_path(path, *, d[, prec])

Offset a simple closed SVG path.

bevel_path(path, *, d[, prec])

Construct bevel faces for an offset of a simple closed path.

Module Contents#

type svg_path_editor.path_offset.Shape = Line | ParametricEllipticalArc#
svg_path_editor.path_offset.additional_digits: int = 8#

Extra decimal digits used when prec="auto".

svg_path_editor.path_offset._all_non_none[T](elems)[source]#

Return True iff elems contains no None values.

Parameters:

elems (list[T | None])

Return type:

TypeGuard[list[T]]

class svg_path_editor.path_offset._OffsetData[source]#

Bases: NamedTuple

Precomputed data for offsetting a simple closed path.

is_ccw: bool#
items: list[SvgItem]#
offsets: list[Shape]#
inters: list[Intersection]#
svg_path_editor.path_offset._prepare_offset_data(path, *, d, prec)[source]#

Validate path and compute offset segments and their intersections.

Parameters:
Return type:

_OffsetData

svg_path_editor.path_offset._line_outgoing_point(inter1)[source]#

Outgoing point of a line offset segment (after inter1).

Parameters:

inter1 (Intersection)

Return type:

Point

svg_path_editor.path_offset._arc_outgoing_point(inter1)[source]#

Outgoing point of an arc offset segment (after inter1).

Parameters:

inter1 (Intersection)

Return type:

Point

svg_path_editor.path_offset.outward_normal(p0, p1, is_ccw)[source]#

Compute the outward unit normal of an edge.

Parameters:
  • p0 (Point) – Start point of the edge.

  • p1 (Point) – End point of the edge.

  • is_ccw (bool) – True iff the polygon is oriented counter-clockwise.

Returns:

Unit normal pointing outside the filled region.

Return type:

Point

class svg_path_editor.path_offset.Tri[source]#

Bases: NamedTuple

Small bevel triangle between original and offset geometry.

Variables:
  • orig0 – Vertex on the original path.

  • off0 – First vertex on the offset path.

  • off1 – Second vertex on the offset path.

orig0: Point#
off0: Point#
off1: Point#
property path: SvgPath#

Return this triangle as a closed SvgPath.

Return type:

SvgPath

outward_normal(is_ccw)[source]#

Return outward unit normal of this triangle.

Parameters:

is_ccw (bool) – True iff the enclosing polygon is CCW.

Return type:

Point

svg_path_editor.path_offset._iter_segment_contexts(offsets, inters, items)[source]#

Yield (orig_item, offset_geom, incoming_inter, outgoing_inter) per segment.

Parameters:
Return type:

collections.abc.Iterable[tuple[SvgItem, Shape, Intersection, Intersection]]

svg_path_editor.path_offset._arc_ante(orig, inter0)[source]#

Handle the incoming side of an offset arc.

Returns the ante point on the offset arc plus bevel triangles to emit before the arc segment.

Parameters:
Return type:

tuple[Point, tuple[Tri, Ellipsis]]

svg_path_editor.path_offset._arc_post(orig, inter1)[source]#

Handle the outgoing side of an offset arc.

Yields bevel triangles to emit after the arc segment.

Parameters:
Return type:

collections.abc.Iterable[Tri]

svg_path_editor.path_offset._line_ante(orig, inter0)[source]#

Handle the incoming side of a straight segment.

Returns the ante point on the offset line plus bevel triangles to emit before the line segment.

Parameters:
Return type:

tuple[Point, tuple[Tri, Ellipsis]]

svg_path_editor.path_offset.offset_path(path, *, d, prec=None)[source]#

Offset a simple closed SVG path.

The input must be a single closed subpath M Z of straight lines and elliptical arcs. Every segment is offset by distance d (inwards for d > 0), and consecutive offset segments are intersected to form the output path.

Parameters:
  • path (SvgPath) – Closed SvgPath with exactly one subpath M Z, using only line and elliptical-arc segments.

  • d (Number) – Offset distance. Positive values move edges towards the interior.

  • prec (Precision | Literal['auto', 'auto-intersections'] | None) –

    Intersection and offsetting precision:

    • "auto": decimal precision + additional_digits for both offset geometry and intersections.

    • "auto-intersections": same automatic precision for intersections only; offsets remain symbolic.

    • Precision: use this precision everywhere.

    • None: purely symbolic where supported.

Returns:

The offset closed path.

Raises:

AssertionError – If path is not a single closed subpath of the expected form, or if an offset intersection cannot be computed.

Return type:

SvgPath

class svg_path_editor.path_offset.BevelPolygon[source]#

Bases: NamedTuple

Planar bevel face bounded by straight segments.

Variables:
  • path – Closed SvgPath describing the bevel polygon.

  • outward_normal – Unit normal pointing out of the filled region.

path: SvgPath#
outward_normal: Point#
ante_ext: bool = False#
post_ext: bool = False#
class svg_path_editor.path_offset.BevelArced[source]#

Bases: NamedTuple

Planar bevel face containing an elliptical-arc boundary.

The path consists of two corresponding arc segments (original and offset) joined by straight segments.

Variables:
  • path – Closed SvgPath describing the bevel face.

  • c – Center of the supporting ellipse.

  • r – Radii vector of the supporting ellipse.

  • phi – Rotation of the ellipse in degrees.

  • locally_convexTrue iff the bevel is convex w.r.t. the interior.

path: SvgPath#
c: Point#
r: Point#
phi: decimal.Decimal#
locally_convex: bool#
ante_ext: bool = False#
post_ext: bool = False#
svg_path_editor.path_offset.bevel_path(path, *, d, prec=None)[source]#

Construct bevel faces for an offset of a simple closed path.

Unlike offset_path(), this yields only the auxiliary faces that fill the bevel region between the original path and its offset.

Parameters:
  • path (SvgPath) – Closed SvgPath with exactly one subpath M Z, using only line and elliptical-arc segments.

  • d (Number) – Offset distance. Positive values move edges towards the interior.

  • prec (Precision | Literal['auto', 'auto-intersections'] | None) – Same semantics as in offset_path().

Returns:

Closed paths covering the bevel surface between original and offset.

Raises:

AssertionError – If path is not a single closed subpath of the expected form, or if an offset intersection cannot be computed.

Return type:

collections.abc.Iterable[BevelPolygon | BevelArced]