Skip to content

Commit

Permalink
break and mend rope
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisShank committed Nov 24, 2024
1 parent 25d53ec commit 07ef31d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/arrows/event-propagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export class EventPropagator extends FolkRope {
return this.#expression;
}
set expression(expression) {
this.stroke = 'black';
this.mend();
this.#expression = expression;
try {
this.#function = new Function('$source', '$target', '$event', expression);
} catch (error) {
console.warn('Failed to parse expression:', error);
// Use no-op function when parsing fails
this.stroke = 'red';
this.break();
this.#function = () => {};
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/arrows/fc-rope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ export class FolkRope extends AbstractArrow {
for (let i = 0; i < this.#points.length; i++) {
const p = this.#points[i];

const prev = i > 0 ? this.#points[i - 1] : null;

if (prev) {
if (p.prev) {
this.#context.beginPath();
this.#context.moveTo(prev.pos.x, prev.pos.y);
this.#context.moveTo(p.prev.pos.x, p.prev.pos.y);
this.#context.lineTo(p.pos.x, p.pos.y);
this.#context.lineWidth = 2;
this.#context.strokeStyle = this.#stroke;
Expand Down Expand Up @@ -265,4 +263,18 @@ export class FolkRope extends AbstractArrow {
}
}
}

break(index = Math.floor(this.#points.length / 2)) {
if (this.#points.length === 0) return;

this.#points[index].next = null;
this.#points[index + 1].prev = null;
}

mend(index = Math.floor(this.#points.length / 2)) {
if (this.#points.length === 0) return;

this.#points[index].next = this.#points[index + 1];
this.#points[index + 1].prev = this.#points[index];
}
}

0 comments on commit 07ef31d

Please sign in to comment.