Spaces:
Sleeping
Sleeping
Commit ·
8da8915
1
Parent(s): c46fef8
fix(canvas): adapt CreaseCanvas to engine FOLD-format paper_state
Browse filespaper_state now uses vertices_coords/edges_vertices/edges_assignment (FOLD
format) instead of the old {vertices, edges, anchor_points} shape. Add null
guards for missing vertices. Remove AnchorCrosses component (anchor points
no longer in paper_state). Handle 3D vertices_coords [x,y,z] by dropping z.
- src/components/CreaseCanvas.js +21 -35
src/components/CreaseCanvas.js
CHANGED
|
@@ -13,10 +13,11 @@ function GhostEdges({ target, dim }) {
|
|
| 13 |
return edges_vertices.map((ev, i) => {
|
| 14 |
const asgn = edges_assignment[i];
|
| 15 |
if (asgn === 'B') return null;
|
| 16 |
-
const
|
| 17 |
-
const
|
| 18 |
-
|
| 19 |
-
const [
|
|
|
|
| 20 |
const color = asgn === 'M' ? MOUNTAIN : VALLEY;
|
| 21 |
return (
|
| 22 |
<line
|
|
@@ -32,15 +33,23 @@ function GhostEdges({ target, dim }) {
|
|
| 32 |
}
|
| 33 |
|
| 34 |
function CurrentEdges({ paperState, dim }) {
|
| 35 |
-
if (!paperState
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
return (
|
| 42 |
<line
|
| 43 |
-
key={
|
| 44 |
x1={x1} y1={y1} x2={x2} y2={y2}
|
| 45 |
stroke={color}
|
| 46 |
strokeWidth={2.5}
|
|
@@ -50,26 +59,6 @@ function CurrentEdges({ paperState, dim }) {
|
|
| 50 |
});
|
| 51 |
}
|
| 52 |
|
| 53 |
-
function AnchorCrosses({ paperState, dim }) {
|
| 54 |
-
if (!paperState || !paperState.anchor_points) return null;
|
| 55 |
-
const size = 4;
|
| 56 |
-
return paperState.anchor_points.map((pt, i) => {
|
| 57 |
-
const [cx, cy] = toSvg(pt[0], pt[1], dim);
|
| 58 |
-
return (
|
| 59 |
-
<g key={i}>
|
| 60 |
-
<line
|
| 61 |
-
x1={cx - size} y1={cy} x2={cx + size} y2={cy}
|
| 62 |
-
stroke="#64748b" strokeWidth={1}
|
| 63 |
-
/>
|
| 64 |
-
<line
|
| 65 |
-
x1={cx} y1={cy - size} x2={cx} y2={cy + size}
|
| 66 |
-
stroke="#64748b" strokeWidth={1}
|
| 67 |
-
/>
|
| 68 |
-
</g>
|
| 69 |
-
);
|
| 70 |
-
});
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
export default function CreaseCanvas({ paperState, target, dim = 280, ghostOnly = false }) {
|
| 74 |
const pad = 1;
|
| 75 |
const size = dim;
|
|
@@ -94,10 +83,7 @@ export default function CreaseCanvas({ paperState, target, dim = 280, ghostOnly
|
|
| 94 |
|
| 95 |
{/* Current paper state */}
|
| 96 |
{!ghostOnly && (
|
| 97 |
-
<>
|
| 98 |
-
<CurrentEdges paperState={paperState} dim={size} />
|
| 99 |
-
<AnchorCrosses paperState={paperState} dim={size} />
|
| 100 |
-
</>
|
| 101 |
)}
|
| 102 |
|
| 103 |
{/* Paper border */}
|
|
|
|
| 13 |
return edges_vertices.map((ev, i) => {
|
| 14 |
const asgn = edges_assignment[i];
|
| 15 |
if (asgn === 'B') return null;
|
| 16 |
+
const v1 = vertices_coords[ev[0]];
|
| 17 |
+
const v2 = vertices_coords[ev[1]];
|
| 18 |
+
if (!v1 || !v2) return null;
|
| 19 |
+
const [x1, y1] = toSvg(v1[0], v1[1], dim);
|
| 20 |
+
const [x2, y2] = toSvg(v2[0], v2[1], dim);
|
| 21 |
const color = asgn === 'M' ? MOUNTAIN : VALLEY;
|
| 22 |
return (
|
| 23 |
<line
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
function CurrentEdges({ paperState, dim }) {
|
| 36 |
+
if (!paperState) return null;
|
| 37 |
+
const { vertices_coords, edges_vertices, edges_assignment } = paperState;
|
| 38 |
+
if (!vertices_coords || !edges_vertices || !edges_assignment) return null;
|
| 39 |
+
|
| 40 |
+
return edges_vertices.map((ev, i) => {
|
| 41 |
+
const asgn = edges_assignment[i];
|
| 42 |
+
if (asgn === 'B' || asgn === 'F') return null;
|
| 43 |
+
const v1 = vertices_coords[ev[0]];
|
| 44 |
+
const v2 = vertices_coords[ev[1]];
|
| 45 |
+
if (!v1 || !v2) return null;
|
| 46 |
+
// vertices_coords are 3D [x, y, z] — use only x and y
|
| 47 |
+
const [x1, y1] = toSvg(v1[0], v1[1], dim);
|
| 48 |
+
const [x2, y2] = toSvg(v2[0], v2[1], dim);
|
| 49 |
+
const color = asgn === 'M' ? MOUNTAIN : VALLEY;
|
| 50 |
return (
|
| 51 |
<line
|
| 52 |
+
key={i}
|
| 53 |
x1={x1} y1={y1} x2={x2} y2={y2}
|
| 54 |
stroke={color}
|
| 55 |
strokeWidth={2.5}
|
|
|
|
| 59 |
});
|
| 60 |
}
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
export default function CreaseCanvas({ paperState, target, dim = 280, ghostOnly = false }) {
|
| 63 |
const pad = 1;
|
| 64 |
const size = dim;
|
|
|
|
| 83 |
|
| 84 |
{/* Current paper state */}
|
| 85 |
{!ghostOnly && (
|
| 86 |
+
<CurrentEdges paperState={paperState} dim={size} />
|
|
|
|
|
|
|
|
|
|
| 87 |
)}
|
| 88 |
|
| 89 |
{/* Paper border */}
|