Python API for constructing, folding, and rasterizing 2D paper states.
Two-dimensional vector used by geometry APIs.
| Name | Type | Description |
|---|---|---|
x |
float |
X coordinate. |
y |
float |
Y coordinate. |
Supported operations:
- Arithmetic:
+,-,*,/dot(other) -> floatcross(other) -> floatnorm() -> floatnormalized() -> Vec2
Line segment defined by two endpoints.
| Name | Type | Description |
|---|---|---|
p1 |
Vec2 |
First endpoint. |
p2 |
Vec2 |
Second endpoint. |
Single convex counterclockwise polygon layer.
| Name | Type | Description |
|---|---|---|
vertices |
list[Vec2] |
Polygon vertices. |
| Name | Type | Description |
|---|---|---|
vertices |
list[Vec2] |
Layer vertices. |
Represents a sheet of paper, possibly with multiple folded layers.
| Name | Type | Description |
|---|---|---|
layers |
list[Layer] |
Current set of layers. |
Method summary:
Method Description copy() -> PaperReturns a copy of the current paper state. fold(s: Segment) -> boolAttempts one fold operation; returns Trueif valid andFalseotherwise.compute_bounds() -> list[float]Returns [min_x, max_x, min_y, max_y].compute_boundary_points(max_dist: float) -> tuple[np.ndarray, np.ndarray]Samples boundary points and segment index offsets. rasterize(rows: int, cols: int, theta: float = 0) -> np.ndarrayRasterizes paper occupancy into a boolean array with shape (rows, cols).
from paper import Paper, Segment, Vec2
p = Paper()
ok = p.fold(Segment(Vec2(0.0, 0.0), Vec2(1.0, 0.5)))
img = p.rasterize(64, 64)
print(ok, img.shape)Expected output (example):
True (64, 64)
- This module is the stable Python import surface for simulation code.
- Internal C++ implementation details are intentionally not part of this reference.