Detect overlapping shapes and update their overlapping_shapes dictionaries. This function requires each ShapeData to have its shape_id already set. It modifies the shapes in-place, adding shape IDs with overlap areas in square inches. Args: shapes: List of ShapeData objects wit
(shapes: List[ShapeData])
| 880 | |
| 881 | |
| 882 | def detect_overlaps(shapes: List[ShapeData]) -> None: |
| 883 | """Detect overlapping shapes and update their overlapping_shapes dictionaries. |
| 884 | |
| 885 | This function requires each ShapeData to have its shape_id already set. |
| 886 | It modifies the shapes in-place, adding shape IDs with overlap areas in square inches. |
| 887 | |
| 888 | Args: |
| 889 | shapes: List of ShapeData objects with shape_id attributes set |
| 890 | """ |
| 891 | n = len(shapes) |
| 892 | |
| 893 | # Compare each pair of shapes |
| 894 | for i in range(n): |
| 895 | for j in range(i + 1, n): |
| 896 | shape1 = shapes[i] |
| 897 | shape2 = shapes[j] |
| 898 | |
| 899 | # Ensure shape IDs are set |
| 900 | assert shape1.shape_id, f"Shape at index {i} has no shape_id" |
| 901 | assert shape2.shape_id, f"Shape at index {j} has no shape_id" |
| 902 | |
| 903 | rect1 = (shape1.left, shape1.top, shape1.width, shape1.height) |
| 904 | rect2 = (shape2.left, shape2.top, shape2.width, shape2.height) |
| 905 | |
| 906 | overlaps, overlap_area = calculate_overlap(rect1, rect2) |
| 907 | |
| 908 | if overlaps: |
| 909 | # Add shape IDs with overlap area in square inches |
| 910 | shape1.overlapping_shapes[shape2.shape_id] = overlap_area |
| 911 | shape2.overlapping_shapes[shape1.shape_id] = overlap_area |
| 912 | |
| 913 | |
| 914 | def extract_text_inventory( |
no test coverage detected