drawing_tools.helpers package#

Subpackages#

Submodules#

drawing_tools.helpers.geometry module#

Generic geometry helper functions.

HORIZONTAL and VERTICAL are the orientation vocabulary orientation_from_direction() returns, and the one every caller compares against; a direction aligned with neither is reported as None rather than by a third value. Orientation types that vocabulary, so a stray string is caught by the type checker rather than at the dictionary lookup it would fail in. AXIS_ALIGNMENT_TOLERANCE is the aperture that decides it, as the sine of the largest angle still read as aligned. It is deliberately not called an angle tolerance: the balloon helpers already export a HORIZONTAL_ANGLE_TOLERANCE measured in radians, and the two must not be confused.

drawing_tools.helpers.geometry.points_coincide(p1: Any, p2: Any, tolerance: float = 1e-06) → bool#

Check if two points are at the same position within tolerance.

Parameters:
  • p1 – First point with x and y attributes.

  • p2 – Second point with x and y attributes.

  • tolerance – Maximum distance per axis for coincidence.

Returns:

True if both coordinates match within tolerance.

drawing_tools.helpers.geometry.segments_coincide(seg_a: Any, seg_b: Any, tolerance: float = 1e-06) → bool#

Check if two segments are coincident (same endpoints, possibly reversed).

Parameters:
  • seg_a – First segment with start and end attributes.

  • seg_b – Second segment with start and end attributes.

  • tolerance – Point coincidence tolerance.

Returns:

True if the segments share the same endpoints.

drawing_tools.helpers.geometry.is_full_circle(edge: Edge) → bool#

Check whether an edge is an arc sweeping a full turn.

Parameters:

edge – The edge to test.

Returns:

True for a closed circle (a FullArc2D, or an Arc2D of angle 2 pi).

drawing_tools.helpers.geometry.get_arc_radius(edge: Edge) → float#

Get the radius of an arc edge.

Works around Edge.get_arc_radius, which returns self.radius instead of the geometry’s and therefore raises AttributeError for EVERY arc — an upstream dessia_drawing typo. Its sibling Edge.get_arc_center is fine and is used directly.

Parameters:

edge – An arc edge (Arc2D or FullArc2D); anything else raises AttributeError.

Returns:

The radius.

drawing_tools.helpers.geometry.is_segment_inside_circle(segment: Edge, center: Point2D, radius: float) → bool#

Check whether both endpoints of a straight segment lie inside a circle.

Containment of the whole segment follows only because a disk is convex, so this holds for a LINE SEGMENT: on a curved edge, both endpoints inside says nothing about the middle.

Parameters:
  • segment – The line segment to test.

  • center – The circle center.

  • radius – The circle radius.

Returns:

True when both endpoints lie inside the circle.

drawing_tools.helpers.geometry.orientation_from_direction(direction_x: float, direction_y: float, tolerance: float = 0.09) → Literal['horizontal', 'vertical'] | None#

Tell whether a direction runs horizontally, vertically, or neither.

Works for anything that has a direction: a segment through its direction vector, a text through (cos(angle), sin(angle)). The off-axis component is compared to the tolerance scaled by the vector’s own norm, so the tolerance reads as the sine of the largest angle still accepted as aligned whatever the length of the vector passed in. A direction of zero length points nowhere and is reported as such.

Parameters:
  • direction_x – Horizontal component of the direction.

  • direction_y – Vertical component of the direction.

  • tolerance – Sine of the maximum angle to an axis for the direction to count as aligned with it.

Returns:

HORIZONTAL, VERTICAL, or None for an oblique or null direction.

Module contents#

Package initialization.