geom2d.util

Basic 2D utility functions.

geom2d.util.calc_rotation(start_angle: float, end_angle: float) float

Calculate the amount of rotation between two angles.

Parameters:
  • start_angle – Start angle in radians.

  • end_angle – End angle in radians.

Returns:

Rotation amount in radians where -PI <= rotation <= PI.

geom2d.util.float_formatter(scale: float = 1, precision: float | None = None) Callable[[float], str]

Get a float formatter for a specified precision.

Parameters:
  • scale – Scaling factor (for SVG). Default is 1.

  • precision – The max number of digits after the decimal point.

Returns:

A function that formats a float to the specified precision and strips off trailing zeros and decimal point when necessary.

geom2d.util.normalize_angle(angle: float, center: float = 3.141592653589793) float

Normalize angle about a 2*PI interval centered at center.

For angle between 0 and 2*PI (default):

normalize_angle(angle, center=math.pi)

For angle between -PI and PI:

normalize_angle(angle, center=0.0)

Parameters:
  • angle – Angle in radians to normalize

  • center – Center value about which to normalize. Default is math.pi.

Returns:

An angle value in radians between 0 and 2 * PI if center == PI, otherwise a value between -PI and PI if center == 0.

geom2d.util.reverse_path(path: Sequence[Line | Arc | CubicBezier]) list[Line | Arc | CubicBezier]

Reverse the order and direction of path segments.

geom2d.util.segments_are_g1(seg1: Line | Arc | CubicBezier, seg2: Line | Arc | CubicBezier, tolerance: float | None = None) bool

Determine if two segments have G1 continuity.

G1 continuity is when two segments are tangentially connected. G1 implies G0 continuity.

Parameters:
  • seg1 – First segment. Can be geom.Line, geom2d.Arc, geom.CubicBezier.

  • seg2 – Second segment. Can be geom.Line, geom2d.Arc, geom.CubicBezier.

  • tolerance – G0/G1 tolerance. Default is geom2d.const.EPSILON.

Returns:

True if the two segments have G1 continuity within the specified tolerance. Otherwise False.

geom2d.util.triplepoints(points: Iterable[TPoint]) Iterator[tuple[TPoint, TPoint, TPoint]]

Return overlapping point triplets from points.

>>> list(triplewise('ABCDE'))
[('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E')]
See:

https://github.com/more-itertools/more-itertools