drawing_tools.view.geometry.relationships package#

Submodules#

drawing_tools.view.geometry.relationships.detector module#

Edge relationship detection algorithms.

This module contains the EdgeRelationshipDetector class for discovering geometric relationships.

class drawing_tools.view.geometry.relationships.detector.EdgeRelationshipDetector(tolerance: float = 0.001, angle_tolerance: float = 0.01)#

Bases: object

Detects implicit geometric relationships between edges.

This class analyzes a collection of edges and identifies: - Coincident endpoints (connectivity) - Parallel and perpendicular relationships - Collinear edges - Tangent relationships (for curves) - Concentric circles/arcs - Symmetric patterns

__init__(tolerance: float = 0.001, angle_tolerance: float = 0.01)#

Initialize the detector.

Parameters:
  • tolerance – Distance tolerance for coincidence detection (drawing units)

  • angle_tolerance – Angular tolerance in radians (default ~0.57 degrees)

classmethod from_view(view: View, tolerance: float = 0.5, angle_tolerance: float = 0.01) EdgeConstraintGraph#

Build an edge constraint graph directly from a View.

Parameters:
  • view – View to analyze

  • tolerance – Distance tolerance for geometric comparisons

  • angle_tolerance – Angular tolerance in radians

Returns:

EdgeConstraintGraph containing all detected relationships

detect_relationships(edge1: Edge, edge2: Edge) list[EdgeRelationship]#

Detect all geometric relationships between two specific edges.

Parameters:
  • edge1 – First edge to analyze

  • edge2 – Second edge to analyze

Returns:

List of EdgeRelationship objects

detect_all_relationships(edges: list[Edge]) EdgeConstraintGraph#

Detect all geometric relationships between edges and build constraint graph.

This is the main entry point for building the edge constraint graph.

Parameters:

edges – List of edges to analyze

Returns:

EdgeConstraintGraph containing all detected relationships

drawing_tools.view.geometry.relationships.graph module#

Edge constraint graph for representing geometric relationships.

This module contains the EdgeConstraintGraph class and helper classes for graph traversal.

class drawing_tools.view.geometry.relationships.graph.EdgeConstraintGraph(tolerance: float = 0.001)#

Bases: object

Graph structure representing geometric constraint relationships between edges.

The graph maintains multiple indices for efficient querying: - Edge-to-relationships mapping - Relationship type index - Point-to-edges mapping for connectivity

__init__(tolerance: float = 0.001)#

Initialize the edge constraint graph.

Parameters:

tolerance – Tolerance for geometric comparisons (in drawing units)

add_edge(edge: Edge) None#

Add an edge to the graph and index its endpoints.

Parameters:

edge – Edge to add to the graph

add_relationship(relationship: EdgeRelationship) None#

Add a geometric relationship between two edges.

Parameters:

relationship – EdgeRelationship to add

has_relationship(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType) bool#

Check if two edges have a specific type of relationship.

Parameters:
Returns:

True if the relationship exists

get_relationships_between(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType | None = None) list[EdgeRelationship]#

Get all relationships between two specific edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • relationship_type – Optional filter by GeometricRelationType

Returns:

List of EdgeRelationship objects

get_relationship_metadata(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType) list[dict]#

Get metadata for all relationships of a specific type between two edges.

Parameters:
Returns:

List of metadata dictionaries

count_relationships(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType | None = None) int#

Count relationships between two edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • relationship_type – Optional filter by GeometricRelationType

Returns:

Number of relationships

get_tangent_relationships(edge1: Edge, edge2: Edge) list[EdgeRelationship]#

Get all tangent relationships between two specific edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

List of EdgeRelationship objects with TANGENT type

get_tangent_points(edge1: Edge, edge2: Edge) list[volmdlr.Point2D]#

Get all tangent points between two specific edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

List of tangent points between the edges

are_parallel(edge1: Edge, edge2: Edge, include_collinear: bool = False) bool#

Check if two edges are parallel.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • include_collinear – If True, also consider collinear edges as parallel

Returns:

True if edges are parallel

are_perpendicular(edge1: Edge, edge2: Edge) bool#

Check if two edges are perpendicular.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are perpendicular

are_connected(edge1: Edge, edge2: Edge) bool#

Check if two edges share an endpoint (are connected).

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges share an endpoint

are_tangent(edge1: Edge, edge2: Edge) bool#

Check if two edges are tangent.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are tangent

are_concentric(edge1: Edge, edge2: Edge) bool#

Check if two edges are concentric (share the same center).

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are concentric

are_symmetric(edge1: Edge, edge2: Edge) bool#

Check if two edges are symmetric.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are symmetric

get_connection_points(edge1: Edge, edge2: Edge) list[volmdlr.Point2D]#

Get all points where two edges connect (share endpoints).

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

List of connection points

get_parallel_offset(edge1: Edge, edge2: Edge) float | None#

Get the offset distance between two parallel edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

Offset distance if edges are parallel, None otherwise

get_angular_relationship(edge1: Edge, edge2: Edge) float | None#

Get the angle between two edges if they have an angular relationship.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

Angle in radians if angular relationship exists, None otherwise

Get all edges related to the given edge by specified relationship types.

Parameters:
  • edge – The edge to query

  • relationship_types – Filter by specific GeometricRelationType list (None = all)

Returns:

List of related edges

find_edges_by_pattern(edge: Edge, pattern: list[list[GeometricRelationType]]) list[Edge]#

Find edges that match any relationship pattern.

A pattern is a list of relationship sets. An edge matches if it satisfies ANY of the relationship sets in the pattern.

Parameters:
Returns:

List of edges that match the pattern

find_chains_by_pattern(start_edge: Edge, pattern: list[list[GeometricRelationType]], max_length: int = 10) list[list[Edge]]#

Find chains of edges connected by relationship patterns.

Parameters:
  • start_edge – Starting edge for chain search

  • pattern – List of GeometricRelationType sets for chain traversal

  • max_length – Maximum chain length

Returns:

List of edge chains

find_rectangular_connections(edge: Edge) list[Edge]#

Find edges that form rectangular connections (corners or sides).

find_rectangular_corners(edge: Edge) list[Edge]#

Find edges that form rectangular corner connections.

find_rectangular_chains(start_edge: Edge, max_length: int = 10) list[list[Edge]]#

Find chains of edges forming rectangular connections.

get_parallel_edges(edge: Edge, include_collinear: bool = False) list[Edge]#

Get all edges parallel to the given edge.

Parameters:
  • edge – The edge to query

  • include_collinear – If True, also include collinear edges

Returns:

List of parallel edges

get_perpendicular_edges(edge: Edge) list[Edge]#

Get all edges perpendicular to the given edge.

Parameters:

edge – The edge to query

Returns:

List of perpendicular edges

get_perpendicular_connected_edges(edge: Edge) list[Edge]#

Get all edges that are both perpendicular to and connected with the given edge.

Parameters:

edge – The edge to query

Returns:

List of perpendicular edges that share an endpoint

get_collinear_edges(edge: Edge) list[Edge]#

Get all edges collinear to the given edge.

Parameters:

edge – The edge to query

Returns:

List of collinear edges

get_collinear_connected_edges(edge: Edge) list[Edge]#

Get all edges that are both collinear and connected with the given edge.

Parameters:

edge – The edge to query

Returns:

List of collinear edges that share an endpoint

get_connected_edges(edge: Edge) list[Edge]#

Get all edges connected (sharing endpoints) with the given edge.

Parameters:

edge – The edge to query

Returns:

List of connected edges

get_tangent_edges(edge: Edge) list[Edge]#

Get all edges tangent to the given edge.

Parameters:

edge – The edge to query

Returns:

List of tangent edges

get_concentric_edges(edge: Edge) list[Edge]#

Get all edges concentric to the given edge.

Parameters:

edge – The edge to query

Returns:

List of concentric edges

get_symmetric_edges(edge: Edge) list[Edge]#

Get all edges symmetric to the given edge.

Parameters:

edge – The edge to query

Returns:

List of symmetric edges

get_edges_at_point(point: volmdlr.Point2D) list[Edge]#

Get all edges that have an endpoint at the given point.

Parameters:

point – The point to query

Returns:

List of edges with endpoint at this point

find_connected_components() list[set[Edge]]#

Find all connected components in the graph.

A connected component is a set of edges connected through coincident relationships.

Returns:

List of connected components (sets of edges)

find_parallel_groups() list[set[Edge]]#

Find groups of mutually parallel edges.

Returns:

List of parallel edge groups

find_chains(start_edge: Edge, relationship_types: list[GeometricRelationType], max_length: int = 10) list[list[Edge]]#

Find chains of edges connected by specific relationship types.

Parameters:
  • start_edge – Starting edge for chain search

  • relationship_types – List of relationship types to follow

  • max_length – Maximum chain length

Returns:

List of edge chains

get_statistics() dict#

Get comprehensive statistics about the graph.

Returns:

Dictionary with graph statistics

print_summary() None#

Print a summary of the graph structure.

drawing_tools.view.geometry.relationships.point_mapper module#

Point-to-edge mapping system for efficient spatial indexing.

This module provides the PointToEdgeMapper class for O(1) lookup of edges at specific points.

class drawing_tools.view.geometry.relationships.point_mapper.PointToEdgeMapper(tolerance: float = 0.001)#

Bases: object

Efficient point-to-edge mapping system using Point2D equality.

This class provides O(1) lookup performance for finding edges at specific points, which is essential for geometric constraint detection, dimension analysis and graph visualization.

Key features: - Uses Point2D objects as dictionary keys (coordinate-based equality via __eq__ and __hash__) - Different Point2D instances with same coordinates map to the same entry - Simple and fast: direct dict lookups, no tolerance clustering, no spatial indexing - Point roles tracking for enhanced visualization (“endpoint”, “center”)

Example

mapper = PointToEdgeMapper() mapper.add_edge(edge)

# These all access the same entry (same coordinates): point1 = Point2D(10, 10) point2 = Point2D(10, 10) # Different instance, same coordinates assert mapper.get_edges_at_point(point1) == mapper.get_edges_at_point(point2)

__init__(tolerance: float = 0.001)#

Initialize the point-to-edge mapper.

Parameters:

tolerance – Distance tolerance for point coincidence (drawing units)

add_edge(edge: Edge) None#

Add an edge and index its endpoints.

Uses spatial index to efficiently find or create canonical Point2D instances. This ensures points within tolerance share the same instance (O(1) lookup).

For Arc2D and FullArc2D geometries, also indexes the center point.

Parameters:

edge – Edge to add to the mapping

add_edges(edges: list[Edge]) None#

Add multiple edges efficiently.

For Arc2D and FullArc2D geometries, also indexes the center points.

Parameters:

edges – List of edges to add

classmethod from_view(view: View, tolerance: float = 0.001) PointToEdgeMapper#

Initialize a PointToEdgeMapper from a view.

Parameters:
  • view – View to initialize from

  • tolerance – Distance tolerance for point coincidence (drawing units)

Returns:

PointToEdgeMapper

remove_edge(edge: Edge) bool#

Remove an edge from the mapping.

Parameters:

edge – Edge to remove

Returns:

True if edge was found and removed, False otherwise

get_edges_at_point(point: volmdlr.Point2D) list[Edge]#

Get all edges that have an endpoint at the given point.

Uses spatial index to find the canonical point within tolerance, enabling tolerance-based lookups.

Parameters:

point – The point to query

Returns:

List of edges with endpoint at this point (or within tolerance)

get_edges_at_points(points: list[volmdlr.Point2D]) dict[volmdlr.Point2D, list[Edge]]#

Get edges at multiple points efficiently.

Parameters:

points – List of points to query

Returns:

Dictionary mapping points to their edges

find_nearest_point(target_point: volmdlr.Point2D, return_distance: bool = False) tuple[volmdlr.Point2D, list[Edge]] | None | tuple[volmdlr.Point2D, list[Edge], float] | None#

Find the nearest indexed point to the target point.

Parameters:
  • target_point – Point to find nearest match for

  • return_distance – If true, return distance to target_point

Returns:

Tuple of (nearest_point, edges_at_point) or (nearest_point, edges_at_point, distance)

get_all_points() Generator[Point2D, None, None]#

Yield all indexed points.

Returns:

Generator of Point2D objects

get_points_in_region(min_point: volmdlr.Point2D, max_point: volmdlr.Point2D) list[tuple[volmdlr.Point2D, list[Edge]]]#

Get all points and their edges within a rectangular region.

Parameters:
  • min_point – Bottom-left corner of region

  • max_point – Top-right corner of region

Returns:

List of (point, edges) tuples within the region

find_canonical_point(point: Point2D) Point2D | None#

Find the canonical Point2D instance for a given point if one exists.

Unlike _get_or_create_canonical_point, this method does NOT add the point to the spatial index if no match is found. Use this for querying existing canonical points without modifying the mapper state.

Parameters:

point – Point to find canonical instance for

Returns:

Canonical Point2D instance if found within tolerance, None otherwise

clear() None#

Clear all mappings and reset statistics.

validate_integrity() list[str]#

Validate the integrity of internal data structures.

Returns:

List of error messages (empty if no issues found)

to_networkx() Graph#

Export the point-to-edge mapping to a NetworkX graph.

In this bipartite graph: - Point nodes (volmdlr.Point2D objects) represent geometric points - Edge nodes (Edge objects) represent the edges themselves - Graph edges connect points to the edges they belong to

Uses actual Point2D objects directly as node identifiers (no quantization). This ensures perfect identity matching with dimension constraint geometries.

Returns:

NetworkX graph with Point2D and Edge objects as nodes

plot_data_graph(filepath: str | None = None, show_edge_name: bool = False) None#

Plot the graph using plot_data.

Parameters:
  • filepath – Optional file path to save the plot

  • show_edge_name – Whether to show edge names on the graph

plot_data_edges(filepath: str | None = None) None#

Plot the all the edges using plot_data.

Parameters:

filepath – Optional file path to save the plot

get_mapping_statistics() dict#

Get statistics about the point-to-edge mapping.

Returns:

Dictionary with mapping statistics

print_mapping_summary() None#

Print a summary of the point-to-edge mapping.

drawing_tools.view.geometry.relationships.types module#

Type definitions and data structures for edge relationships.

This module contains the foundational types used throughout the edge relationship system.

class drawing_tools.view.geometry.relationships.types.SymmetryAxis(*values)#

Bases: Enum

Types of symmetry axes.

VERTICAL = 1#
HORIZONTAL = 2#
class drawing_tools.view.geometry.relationships.types.GeometricRelationType(*values)#

Bases: Enum

Types of geometric relationships between edges.

These form the basis for constraint propagation.

COINCIDENT = 1#
INCIDENT = 2#
PARALLEL = 3#
PERPENDICULAR = 4#
COLLINEAR = 5#
ANGULAR = 6#
TANGENT = 7#
CONCENTRIC = 8#
SYMMETRIC = 9#
OFFSET = 10#
__str__()#

Return the type as a string.

class drawing_tools.view.geometry.relationships.types.CoincidentType(*values)#

Bases: Enum

Detailed types of coincident relationships between edge extremities.

START_START = 1#
END_END = 2#
START_END = 3#
END_START = 4#
class drawing_tools.view.geometry.relationships.types.CoincidentTypeProcessor#

Bases: object

Processor for handling fine-grained coincident relationship types.

static get_coincident_type(edge1: Edge, edge2: Edge, connection_point: volmdlr.Point2D, tolerance: float = 0.001) CoincidentType#

Determine the specific type of coincident relationship between two edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • connection_point – The point where edges connect

  • tolerance – Tolerance for point comparison

Returns:

Specific coincident type

static get_coincident_metadata(edge1: Edge, edge2: Edge, connection_point: volmdlr.Point2D, tolerance: float = 0.001) dict#

Get metadata for a coincident relationship including the specific type.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • connection_point – The point where edges connect

  • tolerance – Tolerance for point comparison

Returns:

Metadata dictionary with coincident type and connection point

class drawing_tools.view.geometry.relationships.types.EdgeRelationship(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType, metadata: dict = <factory>)#

Bases: object

Represents a geometric relationship between two edges.

This is the fundamental building block of the constraint graph.

edge1: Edge#
edge2: Edge#
relationship_type: GeometricRelationType#
metadata: dict#
__hash__()#

Make relationship hashable for use in sets.

__eq__(other: Any)#

Check equality based on edges, relationship type, and relevant metadata.

involves_edge(edge: Edge) bool#

Check if this relationship involves a specific edge.

get_other_edge(edge: Edge) Edge | None#

Get the other edge in this relationship.

__repr__() str#

Return string representation for debugging.

__init__(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType, metadata: dict = <factory>) None#

Module contents#

VolmdlrDrawing Relationships Module.

This module provides comprehensive analysis of relationships between dimensions and edges in technical drawings, including both dimension-edge relationships and edge-edge implicit constraint relationships.

class drawing_tools.view.geometry.relationships.EdgeConstraintGraph(tolerance: float = 0.001)#

Bases: object

Graph structure representing geometric constraint relationships between edges.

The graph maintains multiple indices for efficient querying: - Edge-to-relationships mapping - Relationship type index - Point-to-edges mapping for connectivity

__init__(tolerance: float = 0.001)#

Initialize the edge constraint graph.

Parameters:

tolerance – Tolerance for geometric comparisons (in drawing units)

add_edge(edge: Edge) None#

Add an edge to the graph and index its endpoints.

Parameters:

edge – Edge to add to the graph

add_relationship(relationship: EdgeRelationship) None#

Add a geometric relationship between two edges.

Parameters:

relationship – EdgeRelationship to add

has_relationship(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType) bool#

Check if two edges have a specific type of relationship.

Parameters:
Returns:

True if the relationship exists

get_relationships_between(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType | None = None) list[EdgeRelationship]#

Get all relationships between two specific edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • relationship_type – Optional filter by GeometricRelationType

Returns:

List of EdgeRelationship objects

get_relationship_metadata(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType) list[dict]#

Get metadata for all relationships of a specific type between two edges.

Parameters:
Returns:

List of metadata dictionaries

count_relationships(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType | None = None) int#

Count relationships between two edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • relationship_type – Optional filter by GeometricRelationType

Returns:

Number of relationships

get_tangent_relationships(edge1: Edge, edge2: Edge) list[EdgeRelationship]#

Get all tangent relationships between two specific edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

List of EdgeRelationship objects with TANGENT type

get_tangent_points(edge1: Edge, edge2: Edge) list[volmdlr.Point2D]#

Get all tangent points between two specific edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

List of tangent points between the edges

are_parallel(edge1: Edge, edge2: Edge, include_collinear: bool = False) bool#

Check if two edges are parallel.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

  • include_collinear – If True, also consider collinear edges as parallel

Returns:

True if edges are parallel

are_perpendicular(edge1: Edge, edge2: Edge) bool#

Check if two edges are perpendicular.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are perpendicular

are_connected(edge1: Edge, edge2: Edge) bool#

Check if two edges share an endpoint (are connected).

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges share an endpoint

are_tangent(edge1: Edge, edge2: Edge) bool#

Check if two edges are tangent.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are tangent

are_concentric(edge1: Edge, edge2: Edge) bool#

Check if two edges are concentric (share the same center).

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are concentric

are_symmetric(edge1: Edge, edge2: Edge) bool#

Check if two edges are symmetric.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

True if edges are symmetric

get_connection_points(edge1: Edge, edge2: Edge) list[volmdlr.Point2D]#

Get all points where two edges connect (share endpoints).

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

List of connection points

get_parallel_offset(edge1: Edge, edge2: Edge) float | None#

Get the offset distance between two parallel edges.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

Offset distance if edges are parallel, None otherwise

get_angular_relationship(edge1: Edge, edge2: Edge) float | None#

Get the angle between two edges if they have an angular relationship.

Parameters:
  • edge1 – First edge

  • edge2 – Second edge

Returns:

Angle in radians if angular relationship exists, None otherwise

Get all edges related to the given edge by specified relationship types.

Parameters:
  • edge – The edge to query

  • relationship_types – Filter by specific GeometricRelationType list (None = all)

Returns:

List of related edges

find_edges_by_pattern(edge: Edge, pattern: list[list[GeometricRelationType]]) list[Edge]#

Find edges that match any relationship pattern.

A pattern is a list of relationship sets. An edge matches if it satisfies ANY of the relationship sets in the pattern.

Parameters:
Returns:

List of edges that match the pattern

find_chains_by_pattern(start_edge: Edge, pattern: list[list[GeometricRelationType]], max_length: int = 10) list[list[Edge]]#

Find chains of edges connected by relationship patterns.

Parameters:
  • start_edge – Starting edge for chain search

  • pattern – List of GeometricRelationType sets for chain traversal

  • max_length – Maximum chain length

Returns:

List of edge chains

find_rectangular_connections(edge: Edge) list[Edge]#

Find edges that form rectangular connections (corners or sides).

find_rectangular_corners(edge: Edge) list[Edge]#

Find edges that form rectangular corner connections.

find_rectangular_chains(start_edge: Edge, max_length: int = 10) list[list[Edge]]#

Find chains of edges forming rectangular connections.

get_parallel_edges(edge: Edge, include_collinear: bool = False) list[Edge]#

Get all edges parallel to the given edge.

Parameters:
  • edge – The edge to query

  • include_collinear – If True, also include collinear edges

Returns:

List of parallel edges

get_perpendicular_edges(edge: Edge) list[Edge]#

Get all edges perpendicular to the given edge.

Parameters:

edge – The edge to query

Returns:

List of perpendicular edges

get_perpendicular_connected_edges(edge: Edge) list[Edge]#

Get all edges that are both perpendicular to and connected with the given edge.

Parameters:

edge – The edge to query

Returns:

List of perpendicular edges that share an endpoint

get_collinear_edges(edge: Edge) list[Edge]#

Get all edges collinear to the given edge.

Parameters:

edge – The edge to query

Returns:

List of collinear edges

get_collinear_connected_edges(edge: Edge) list[Edge]#

Get all edges that are both collinear and connected with the given edge.

Parameters:

edge – The edge to query

Returns:

List of collinear edges that share an endpoint

get_connected_edges(edge: Edge) list[Edge]#

Get all edges connected (sharing endpoints) with the given edge.

Parameters:

edge – The edge to query

Returns:

List of connected edges

get_tangent_edges(edge: Edge) list[Edge]#

Get all edges tangent to the given edge.

Parameters:

edge – The edge to query

Returns:

List of tangent edges

get_concentric_edges(edge: Edge) list[Edge]#

Get all edges concentric to the given edge.

Parameters:

edge – The edge to query

Returns:

List of concentric edges

get_symmetric_edges(edge: Edge) list[Edge]#

Get all edges symmetric to the given edge.

Parameters:

edge – The edge to query

Returns:

List of symmetric edges

get_edges_at_point(point: volmdlr.Point2D) list[Edge]#

Get all edges that have an endpoint at the given point.

Parameters:

point – The point to query

Returns:

List of edges with endpoint at this point

find_connected_components() list[set[Edge]]#

Find all connected components in the graph.

A connected component is a set of edges connected through coincident relationships.

Returns:

List of connected components (sets of edges)

find_parallel_groups() list[set[Edge]]#

Find groups of mutually parallel edges.

Returns:

List of parallel edge groups

find_chains(start_edge: Edge, relationship_types: list[GeometricRelationType], max_length: int = 10) list[list[Edge]]#

Find chains of edges connected by specific relationship types.

Parameters:
  • start_edge – Starting edge for chain search

  • relationship_types – List of relationship types to follow

  • max_length – Maximum chain length

Returns:

List of edge chains

get_statistics() dict#

Get comprehensive statistics about the graph.

Returns:

Dictionary with graph statistics

print_summary() None#

Print a summary of the graph structure.

class drawing_tools.view.geometry.relationships.EdgeRelationship(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType, metadata: dict = <factory>)#

Bases: object

Represents a geometric relationship between two edges.

This is the fundamental building block of the constraint graph.

edge1: Edge#
edge2: Edge#
relationship_type: GeometricRelationType#
metadata: dict#
__hash__()#

Make relationship hashable for use in sets.

__eq__(other: Any)#

Check equality based on edges, relationship type, and relevant metadata.

involves_edge(edge: Edge) bool#

Check if this relationship involves a specific edge.

get_other_edge(edge: Edge) Edge | None#

Get the other edge in this relationship.

__repr__() str#

Return string representation for debugging.

__init__(edge1: Edge, edge2: Edge, relationship_type: GeometricRelationType, metadata: dict = <factory>) None#
class drawing_tools.view.geometry.relationships.EdgeRelationshipDetector(tolerance: float = 0.001, angle_tolerance: float = 0.01)#

Bases: object

Detects implicit geometric relationships between edges.

This class analyzes a collection of edges and identifies: - Coincident endpoints (connectivity) - Parallel and perpendicular relationships - Collinear edges - Tangent relationships (for curves) - Concentric circles/arcs - Symmetric patterns

__init__(tolerance: float = 0.001, angle_tolerance: float = 0.01)#

Initialize the detector.

Parameters:
  • tolerance – Distance tolerance for coincidence detection (drawing units)

  • angle_tolerance – Angular tolerance in radians (default ~0.57 degrees)

classmethod from_view(view: View, tolerance: float = 0.5, angle_tolerance: float = 0.01) EdgeConstraintGraph#

Build an edge constraint graph directly from a View.

Parameters:
  • view – View to analyze

  • tolerance – Distance tolerance for geometric comparisons

  • angle_tolerance – Angular tolerance in radians

Returns:

EdgeConstraintGraph containing all detected relationships

detect_relationships(edge1: Edge, edge2: Edge) list[EdgeRelationship]#

Detect all geometric relationships between two specific edges.

Parameters:
  • edge1 – First edge to analyze

  • edge2 – Second edge to analyze

Returns:

List of EdgeRelationship objects

detect_all_relationships(edges: list[Edge]) EdgeConstraintGraph#

Detect all geometric relationships between edges and build constraint graph.

This is the main entry point for building the edge constraint graph.

Parameters:

edges – List of edges to analyze

Returns:

EdgeConstraintGraph containing all detected relationships

class drawing_tools.view.geometry.relationships.GeometricRelationType(*values)#

Bases: Enum

Types of geometric relationships between edges.

These form the basis for constraint propagation.

COINCIDENT = 1#
INCIDENT = 2#
PARALLEL = 3#
PERPENDICULAR = 4#
COLLINEAR = 5#
ANGULAR = 6#
TANGENT = 7#
CONCENTRIC = 8#
SYMMETRIC = 9#
OFFSET = 10#
__str__()#

Return the type as a string.

class drawing_tools.view.geometry.relationships.PointToEdgeMapper(tolerance: float = 0.001)#

Bases: object

Efficient point-to-edge mapping system using Point2D equality.

This class provides O(1) lookup performance for finding edges at specific points, which is essential for geometric constraint detection, dimension analysis and graph visualization.

Key features: - Uses Point2D objects as dictionary keys (coordinate-based equality via __eq__ and __hash__) - Different Point2D instances with same coordinates map to the same entry - Simple and fast: direct dict lookups, no tolerance clustering, no spatial indexing - Point roles tracking for enhanced visualization (“endpoint”, “center”)

Example

mapper = PointToEdgeMapper() mapper.add_edge(edge)

# These all access the same entry (same coordinates): point1 = Point2D(10, 10) point2 = Point2D(10, 10) # Different instance, same coordinates assert mapper.get_edges_at_point(point1) == mapper.get_edges_at_point(point2)

__init__(tolerance: float = 0.001)#

Initialize the point-to-edge mapper.

Parameters:

tolerance – Distance tolerance for point coincidence (drawing units)

add_edge(edge: Edge) None#

Add an edge and index its endpoints.

Uses spatial index to efficiently find or create canonical Point2D instances. This ensures points within tolerance share the same instance (O(1) lookup).

For Arc2D and FullArc2D geometries, also indexes the center point.

Parameters:

edge – Edge to add to the mapping

add_edges(edges: list[Edge]) None#

Add multiple edges efficiently.

For Arc2D and FullArc2D geometries, also indexes the center points.

Parameters:

edges – List of edges to add

classmethod from_view(view: View, tolerance: float = 0.001) PointToEdgeMapper#

Initialize a PointToEdgeMapper from a view.

Parameters:
  • view – View to initialize from

  • tolerance – Distance tolerance for point coincidence (drawing units)

Returns:

PointToEdgeMapper

remove_edge(edge: Edge) bool#

Remove an edge from the mapping.

Parameters:

edge – Edge to remove

Returns:

True if edge was found and removed, False otherwise

get_edges_at_point(point: volmdlr.Point2D) list[Edge]#

Get all edges that have an endpoint at the given point.

Uses spatial index to find the canonical point within tolerance, enabling tolerance-based lookups.

Parameters:

point – The point to query

Returns:

List of edges with endpoint at this point (or within tolerance)

get_edges_at_points(points: list[volmdlr.Point2D]) dict[volmdlr.Point2D, list[Edge]]#

Get edges at multiple points efficiently.

Parameters:

points – List of points to query

Returns:

Dictionary mapping points to their edges

find_nearest_point(target_point: volmdlr.Point2D, return_distance: bool = False) tuple[volmdlr.Point2D, list[Edge]] | None | tuple[volmdlr.Point2D, list[Edge], float] | None#

Find the nearest indexed point to the target point.

Parameters:
  • target_point – Point to find nearest match for

  • return_distance – If true, return distance to target_point

Returns:

Tuple of (nearest_point, edges_at_point) or (nearest_point, edges_at_point, distance)

get_all_points() Generator[Point2D, None, None]#

Yield all indexed points.

Returns:

Generator of Point2D objects

get_points_in_region(min_point: volmdlr.Point2D, max_point: volmdlr.Point2D) list[tuple[volmdlr.Point2D, list[Edge]]]#

Get all points and their edges within a rectangular region.

Parameters:
  • min_point – Bottom-left corner of region

  • max_point – Top-right corner of region

Returns:

List of (point, edges) tuples within the region

find_canonical_point(point: Point2D) Point2D | None#

Find the canonical Point2D instance for a given point if one exists.

Unlike _get_or_create_canonical_point, this method does NOT add the point to the spatial index if no match is found. Use this for querying existing canonical points without modifying the mapper state.

Parameters:

point – Point to find canonical instance for

Returns:

Canonical Point2D instance if found within tolerance, None otherwise

clear() None#

Clear all mappings and reset statistics.

validate_integrity() list[str]#

Validate the integrity of internal data structures.

Returns:

List of error messages (empty if no issues found)

to_networkx() Graph#

Export the point-to-edge mapping to a NetworkX graph.

In this bipartite graph: - Point nodes (volmdlr.Point2D objects) represent geometric points - Edge nodes (Edge objects) represent the edges themselves - Graph edges connect points to the edges they belong to

Uses actual Point2D objects directly as node identifiers (no quantization). This ensures perfect identity matching with dimension constraint geometries.

Returns:

NetworkX graph with Point2D and Edge objects as nodes

plot_data_graph(filepath: str | None = None, show_edge_name: bool = False) None#

Plot the graph using plot_data.

Parameters:
  • filepath – Optional file path to save the plot

  • show_edge_name – Whether to show edge names on the graph

plot_data_edges(filepath: str | None = None) None#

Plot the all the edges using plot_data.

Parameters:

filepath – Optional file path to save the plot

get_mapping_statistics() dict#

Get statistics about the point-to-edge mapping.

Returns:

Dictionary with mapping statistics

print_mapping_summary() None#

Print a summary of the point-to-edge mapping.