drawing_tools.helpers.dimension package#

Submodules#

drawing_tools.helpers.dimension.constraint_points module#

Dimension constraint point extraction and analysis.

class drawing_tools.helpers.dimension.constraint_points.DimensionConstraintPoint(point: Point2D, source_type: Literal['extension_line', 'leader'], source_object: Edge | Leader, source_index: int, direction_vector: Vector2D | None = None)#

Bases: object

Represents a constraint point extracted from a dimension with metadata.

This class provides context about where the constraint point came from (extension line or leader), which specific line/leader it was extracted from, and the direction vector at that point.

This metadata is crucial for proper edge matching in angular dimensions, where we need to ensure edges align with the extension line directions.

point: Point2D#

The actual constraint point location

source_type: Literal['extension_line', 'leader']#

Whether this point came from an extension line or a leader

source_object: Edge | Leader#

Reference to the actual extension line Edge or Leader object

source_index: int#

Index of the source in the dimension’s extension_lines or leaders list

direction_vector: Vector2D | None = None#

Direction vector at the constraint point. - For extension lines: the unit direction vector of the extension line - For leaders: the direction vector of the leader at the arrow tip

__post_init__()#

Compute direction vector if not provided.

matches_direction(edge: Edge, angular_tolerance: float = 0.001) bool#

Check if an edge’s direction at this constraint point matches the source direction.

This is particularly useful for angular dimensions where we need to match edges based on their alignment with extension lines.

Parameters:
  • edge – Edge to check

  • angular_tolerance – Angular tolerance in radians (default ~2.6 degrees)

Returns:

True if edge direction matches (parallel or anti-parallel)

__init__(point: Point2D, source_type: Literal['extension_line', 'leader'], source_object: Edge | Leader, source_index: int, direction_vector: Vector2D | None = None) None#
class drawing_tools.helpers.dimension.constraint_points.DimensionConstraintPointsProcessor(dimension: Dimension, tolerance: float = 0.001, point_mapper: Any | None = None)#

Bases: object

Processor for extracting geometric constraint reference points from dimensions.

This processor implements multiple strategies to identify the precise points where a dimension constrains the underlying geometry. It uses smart extension line analysis, leader arrow evaluation, and geometric heuristics to determine optimal constraint points.

The processor follows a strategy pattern with fallback mechanisms: 1. Smart extension line analysis (most reliable for linear/length dimensions) 2. Leader arrow analysis (reliable for radius/diameter dimensions) 3. Related geometric elements analysis 4. Dimension frame fallback

__init__(dimension: Dimension, tolerance: float = 0.001, point_mapper: Any | None = None) None#

Initialize the processor with a dimension object.

Parameters:
  • dimension – The dimension object to process

  • tolerance – Distance tolerance for point matching

  • point_mapper – Optional PointToEdgeMapper instance for edge finding

property constraint_points: list[DimensionConstraintPoint]#

Extract constraint points with metadata where the dimension constrains the geometry.

This property implements multiple strategies with smart extension line analysis that selects the optimal constraint points and enriches them with metadata about their source (extension line or leader), direction vectors, and indices.

Returns:

List of dimension constraint point objects

property constraint_points_simple: list[Point2D]#

Extract constraint points as simple Point2D objects (backward compatibility).

Returns:

List of constraint points (Point2D only, no metadata)

property geometry_constraint_points: list[Point2D]#

Extract the actual geometry points that the dimension constrains.

This method uses the same strategy as _get_edges_at_points - finding the nearest edges to constraint points using the point mapper, then extracting the closest points on those edges. This accounts for the typical 1-2mm offset between extension lines and geometry in technical drawings.

Returns:

List of actual geometry constraint points (Point2D objects)

drawing_tools.helpers.dimension.geometry module#

Utility functions for finding edges near points.

drawing_tools.helpers.dimension.geometry.find_edges_near_points(point_mapper: Any, points: list[Point2D], tolerance: float) dict[Point2D, list[Edge]]#

Standalone utility function to find edges near given points using a point mapper.

This function can be used by any class that needs to find edges near points, avoiding tight coupling between processors and analyzers.

Parameters:
  • point_mapper – PointToEdgeMapper instance

  • points – List of points to find edges near

  • tolerance – Distance tolerance for point matching

Returns:

Dictionary mapping each point to its nearby edges

Module contents#

Dimension analysis utilities and helpers.

class drawing_tools.helpers.dimension.DimensionConstraintPoint(point: Point2D, source_type: Literal['extension_line', 'leader'], source_object: Edge | Leader, source_index: int, direction_vector: Vector2D | None = None)#

Bases: object

Represents a constraint point extracted from a dimension with metadata.

This class provides context about where the constraint point came from (extension line or leader), which specific line/leader it was extracted from, and the direction vector at that point.

This metadata is crucial for proper edge matching in angular dimensions, where we need to ensure edges align with the extension line directions.

point: Point2D#

The actual constraint point location

source_type: Literal['extension_line', 'leader']#

Whether this point came from an extension line or a leader

source_object: Edge | Leader#

Reference to the actual extension line Edge or Leader object

source_index: int#

Index of the source in the dimension’s extension_lines or leaders list

direction_vector: Vector2D | None = None#

Direction vector at the constraint point. - For extension lines: the unit direction vector of the extension line - For leaders: the direction vector of the leader at the arrow tip

__post_init__()#

Compute direction vector if not provided.

matches_direction(edge: Edge, angular_tolerance: float = 0.001) bool#

Check if an edge’s direction at this constraint point matches the source direction.

This is particularly useful for angular dimensions where we need to match edges based on their alignment with extension lines.

Parameters:
  • edge – Edge to check

  • angular_tolerance – Angular tolerance in radians (default ~2.6 degrees)

Returns:

True if edge direction matches (parallel or anti-parallel)

__init__(point: Point2D, source_type: Literal['extension_line', 'leader'], source_object: Edge | Leader, source_index: int, direction_vector: Vector2D | None = None) None#
class drawing_tools.helpers.dimension.DimensionConstraintPointsProcessor(dimension: Dimension, tolerance: float = 0.001, point_mapper: Any | None = None)#

Bases: object

Processor for extracting geometric constraint reference points from dimensions.

This processor implements multiple strategies to identify the precise points where a dimension constrains the underlying geometry. It uses smart extension line analysis, leader arrow evaluation, and geometric heuristics to determine optimal constraint points.

The processor follows a strategy pattern with fallback mechanisms: 1. Smart extension line analysis (most reliable for linear/length dimensions) 2. Leader arrow analysis (reliable for radius/diameter dimensions) 3. Related geometric elements analysis 4. Dimension frame fallback

__init__(dimension: Dimension, tolerance: float = 0.001, point_mapper: Any | None = None) None#

Initialize the processor with a dimension object.

Parameters:
  • dimension – The dimension object to process

  • tolerance – Distance tolerance for point matching

  • point_mapper – Optional PointToEdgeMapper instance for edge finding

property constraint_points: list[DimensionConstraintPoint]#

Extract constraint points with metadata where the dimension constrains the geometry.

This property implements multiple strategies with smart extension line analysis that selects the optimal constraint points and enriches them with metadata about their source (extension line or leader), direction vectors, and indices.

Returns:

List of dimension constraint point objects

property constraint_points_simple: list[Point2D]#

Extract constraint points as simple Point2D objects (backward compatibility).

Returns:

List of constraint points (Point2D only, no metadata)

property geometry_constraint_points: list[Point2D]#

Extract the actual geometry points that the dimension constrains.

This method uses the same strategy as _get_edges_at_points - finding the nearest edges to constraint points using the point mapper, then extracting the closest points on those edges. This accounts for the typical 1-2mm offset between extension lines and geometry in technical drawings.

Returns:

List of actual geometry constraint points (Point2D objects)

drawing_tools.helpers.dimension.find_edges_near_points(point_mapper: Any, points: list[Point2D], tolerance: float) dict[Point2D, list[Edge]]#

Standalone utility function to find edges near given points using a point mapper.

This function can be used by any class that needs to find edges near points, avoiding tight coupling between processors and analyzers.

Parameters:
  • point_mapper – PointToEdgeMapper instance

  • points – List of points to find edges near

  • tolerance – Distance tolerance for point matching

Returns:

Dictionary mapping each point to its nearby edges