drawing_tools.view.geometry package#

Subpackages#

Submodules#

drawing_tools.view.geometry.rectangles module#

The free-standing rectangles of a view that given points land on: four visible straight segments.

Geometry only – nothing here knows what the points are. A rectangle is found from a segment a point lands on by walking corner to corner: four visible straight segments, each starting where the previous one ends, the fourth ending where the first starts, their directions two perpendicular families. It must then have FREE CORNERS: no other visible straight segment ends at one of them. That is what tells a rectangle standing on its own from one the part’s lines close – a line may cross it, never start from it.

RectangleSegments is the shape every rectangle takes here: its four sides, in walk order. RECTANGLE_SIDE_COUNT and PERPENDICULAR_SIDE_COUNT state what a rectangle IS rather than tune the search, hence their staying out of RectangleDetectionConfig.

class drawing_tools.view.geometry.rectangles.RectangleDetectionConfig(corner_tolerance: float = 0.05, right_angle_cosine_tolerance: float = 0.05)#

Bases: object

Tuning of detect_rectangles_at_points(), both bounds absolute.

Parameters:
  • corner_tolerance – How far apart two endpoints still count as one corner, in drawing units – the drawing’s own precision, measured identical anywhere between 0.05 and 0.5.

  • right_angle_cosine_tolerance – Bound on the dot product between two unit side directions. Read as a cosine, 0.05 bounds a right angle to 3 degrees.

corner_tolerance: float = 0.05#
right_angle_cosine_tolerance: float = 0.05#
__init__(corner_tolerance: float = 0.05, right_angle_cosine_tolerance: float = 0.05) → None#
drawing_tools.view.geometry.rectangles.detect_rectangles_at_points(view: View, points: list[Point2D], max_distance: float, config: RectangleDetectionConfig | None = None) → list[RectangleSegments]#

Return the free-standing rectangles of the view one side of which one of points lands on.

Invisible geometries – blanked_status 1, which the drawing does not show – are neither sides nor lines meeting a corner.

Parameters:
  • view – The view to search.

  • points – Where to search from, typically the terminators of the view’s leaders.

  • max_distance – How far a point may lie from a side, in drawing units.

  • config – Detection parameters. Uses defaults if not provided.

Returns:

The four sides of each rectangle, each rectangle once, top-down then left to right. The order is not for reading: it only makes the output deterministic, Edge.__hash__ being randomized per process.

Module contents#

Module specialized on analysis on view’s geometries.