ianalin123 commited on
Commit
8da8915
·
1 Parent(s): c46fef8

fix(canvas): adapt CreaseCanvas to engine FOLD-format paper_state

Browse files

paper_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.

Files changed (1) hide show
  1. 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 [v1x, v1y] = vertices_coords[ev[0]];
17
- const [v2x, v2y] = vertices_coords[ev[1]];
18
- const [x1, y1] = toSvg(v1x, v1y, dim);
19
- const [x2, y2] = toSvg(v2x, v2y, dim);
 
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 || !paperState.edges) return null;
36
- return paperState.edges.map((edge) => {
37
- if (edge.assignment === 'B') return null;
38
- const [x1, y1] = toSvg(edge.v1[0], edge.v1[1], dim);
39
- const [x2, y2] = toSvg(edge.v2[0], edge.v2[1], dim);
40
- const color = edge.assignment === 'M' ? MOUNTAIN : VALLEY;
 
 
 
 
 
 
 
 
41
  return (
42
  <line
43
- key={edge.id}
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 */}