overlap
pleat.overlap ¶
Compute folded states of crease patterns: overlap graphs, stacking order, and crease assignments.
group_closeby
module-attribute
¶
Plan for cleaner and more efficient overlap-graph creation:
- Start with list of N line segments, as array of shape (N, 2, 2)
- Find identical segments (reshape to (N, 4) , cluster with group_closeby())
- Find crossings of unique segments with sweeping line algorithm
- Group close crossings
- Find segments very close to crossings; Add these to the crossings (This step is new!!)
- Again, group close segments
-
Construct nx graph
-
return: the nx graph, a mapping from the indices of original segments to the edges in the graph
To use this for cleaning of e.g. svg-imported CPs, provide additional method that 'cleans' the CP: Join all straight degree 2 vertices that
FoldResult ¶
FoldResult(
CP: "EuclideanPositionHEG | None" = None,
folded_state: "EuclideanPositionHEG | None" = None,
folded_view_top: "EuclideanPositionHEG | None" = None,
folded_view_bottom: "EuclideanPositionHEG | None" = None,
CP_for_origami_simulator: "EuclideanPositionHEG | None" = None,
)
Bases: dict
Container for the output of :func:fold_complete.
Behaves like a dict for backwards compatibility (result['CP']) and
additionally exposes its entries as attributes (result.CP). Any of
the slots may be None / missing.
Source code in pleat/overlap.py
show ¶
show(
render_settings: dict | None = None,
opacity: float = 0.15,
ncols: int | None = 2,
suptitle: str | None = None,
cell_size: float = 4.0,
) -> None
Display the available result graphs side-by-side via :func:multi_show.
Uses the same per-panel render settings as :func:save_results:
the CP is drawn without face fills, the top/bottom views with
half-thickness edges, and the folded state as a back-lit composite
with face opacity stacking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
render_settings
|
dict | None
|
Base |
None
|
opacity
|
float
|
Per-layer alpha used by the back-lit folded-state panel. |
0.15
|
ncols
|
int | None
|
Number of columns in the matplotlib grid. |
2
|
suptitle
|
str | None
|
Optional figure-level title. |
None
|
cell_size
|
float
|
Per-cell size in matplotlib inches. |
4.0
|
Source code in pleat/overlap.py
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
intervals_overlapping ¶
Check if two intervals overlap (inclusive of endpoints).
get_potential_intersections ¶
Return pairs of segment indices that may intersect, using a sweep-line approach on bounding boxes.
Source code in pleat/overlap.py
line_segment_intersections ¶
Return a list of intersection points between two line segments, handling collinear cases.
Source code in pleat/overlap.py
fast_group_closeby ¶
Cluster nearby points using single-linkage clustering on cityblock distance.
Source code in pleat/overlap.py
faster_group_closeby_nx ¶
Cluster nearby points via approximate single-linkage using grid-based connected components.
Points less than eps apart receive the same label. Return an array mapping each input point to its cluster label.
Source code in pleat/overlap.py
overlap_graph ¶
Build the overlap graph of a folded crease pattern by intersecting all edges.
Return an EuclideanPositionHEG whose faces carry 'original_faces' attributes indicating which original faces overlap at each region.
Source code in pleat/overlap.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
find_triplet_overlap_areas ¶
Compute the total overlap area for each triplet of original faces.
Source code in pleat/overlap.py
find_fold_over_facet_lengths ¶
Compute total edge length where a fold passes over a facet.
Source code in pleat/overlap.py
find_conincident_fold_lengths ¶
Compute total edge length where two folds coincide.
Source code in pleat/overlap.py
cache_all ¶
Decorator factory that memoizes all calls in a shared cache dict.
Source code in pleat/overlap.py
infer_additional_over_under_pairs ¶
Transitively close over/under relations: if A over B and B over C within a triplet, infer A over C.
Source code in pleat/overlap.py
find_folded_face_order ¶
find_folded_face_order(
G: "EuclideanPositionHEG",
over_under_pairs=(),
solver=None,
double_fold_weight: float = 0,
allow_slack: bool = True,
problem_file: str | None = None,
quiet: bool = False,
) -> dict
Determine the stacking order of overlapping faces by solving an ILP.
Assign 'sorted_original_faces' to each face of the overlap graph G and return a crease assignment dict mapping original half-edges to MOUNTAIN/VALLEY.
Source code in pleat/overlap.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
fold_wireframe ¶
Fold a crease pattern in place by mirroring alternating faces about their shared edges.
Returns the initial face used for two-coloring, which is guaranteed to be unflipped.
Source code in pleat/overlap.py
get_over_under_pairs_from_creases ¶
get_over_under_pairs_from_creases(
G: "EuclideanPositionHEG",
two_coloring_key: str = "color_key",
) -> list[list["Face"]]
Derive over/under face pairs from mountain/valley crease assignments on a two-colored graph.
Source code in pleat/overlap.py
face_order_to_clean_graph ¶
face_order_to_clean_graph(
G: "EuclideanPositionHEG",
side: str = TOP,
top_color: tuple = (0.5, 0.5, 0.9),
bottom_color: tuple = (0.8, 0.8, 0.8),
) -> "EuclideanPositionHEG"
Extract a clean renderable graph showing only the top or bottom layer of a folded model.
Source code in pleat/overlap.py
color_creases ¶
color_creases(
G: "EuclideanPositionHEG",
colors: dict | None = None,
color_border: bool = False,
) -> None
Assign edge colors based on crease assignments (mountain=red, valley=blue, flat=black).
Source code in pleat/overlap.py
fold_complete ¶
fold_complete(
G: "EuclideanPositionHEG",
initial_face: "Face | None" = None,
overlap_eps: float = 1e-06,
area_eps: float = 0,
quiet: bool = False,
) -> "FoldResult"
Fold a crease pattern and compute the full folded state, including overlap and stacking order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
'EuclideanPositionHEG'
|
The crease pattern graph (mutated in place). |
required |
initial_face
|
'Face | None'
|
Face to keep fixed during folding; auto-picked if |
None
|
overlap_eps
|
float
|
Distance tolerance used by :func: |
1e-06
|
area_eps
|
float
|
Reserved; must be 0. |
0
|
quiet
|
bool
|
If True, suppress all progress bars and log output produced during the pipeline. |
False
|
Returns a :class:FoldResult with attributes/keys 'CP',
'folded_state', 'folded_view_top', and 'folded_view_bottom'.
Source code in pleat/overlap.py
save_results ¶
save_results(
results,
path: str = "results",
render_settings: dict | None = None,
min_foldable_length: float | None = None,
bbox: tuple[float, float] | None = None,
extra_info: str = None,
opacity: float = 0.15,
)
Save rendered crease pattern, folded views, and a plotter-ready SVG to a directory.
The plotter SVG is scaled to fit within bbox (in cm) or so that the shortest fold equals min_foldable_length. Results is the output dict from fold_complete, with keys 'CP', 'folded_state', 'folded_view_top', and 'folded_view_bottom'. Additionally, a key 'CP_for_origami_simulator' can be provided, which is a version of the CP optimized for folding in Origami Simulator.
Source code in pleat/overlap.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | |
remove_duplicates ¶
remove_duplicates(
G: "EuclideanPositionHEG",
eps: float = 1e-06,
exclude_edges=(),
) -> "EuclideanPositionHEG"
Merge duplicate vertices and edges within eps distance, returning a clean graph.
The faces of the resulting graph are built from scratch based on the new edges, so this only works for planar graphs.