Skip to content

Commit

Permalink
make the code more beautiful & then uglify it with an explanatory com…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
av8ta committed Jun 3, 2024
1 parent c45b2b4 commit 7a80bb5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions applications/web/src/components/tools/NewLine.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
$: if ($sketchTool !== "line") clearStack()
function pushToStack(point: PointLikeById) {
// point should have the following properties:
// - twoD: an object with x and y properties representing the point in 2D space
// - threeD: an object with x, y, and z properties representing the point in 3D space
// - id: a string representing the id of the point in the sketch
// If the id is nullish we call addPointToSketch to create a new point in the sketch.
if (!point) return
if (!point.id) point.id = addPointToSketch(sketchIndex, point.twoD, false)
point.id = point.id ?? addPointToSketch(sketchIndex, point.twoD, false)
stack.push(point)
}
Expand All @@ -29,11 +34,11 @@
case 1: // can't create a line with only one point!
break
default:
const previousPoint = stack[stack.length - 2]
addLineToSketch(sketchIndex, +previousPoint.id!, +point!.id!)
popFromStack()
popFromStack()
// leave the last point on the stack in case we want to create another line from that point
const endPoint = popFromStack()
const startPoint = popFromStack()
addLineToSketch(sketchIndex, +startPoint.id, +endPoint.id)
// leave the current point on the stack in case we want to create another line from here
pushToStack(point)
break
}
Expand Down

0 comments on commit 7a80bb5

Please sign in to comment.