Skip to content

Commit

Permalink
fix(hiccup-canvas): update circular arc handling in draw()
Browse files Browse the repository at this point in the history
- actually use CCW shape arg
- add issue references for upcoming fixes
  • Loading branch information
postspectacular committed Oct 10, 2023
1 parent 83d5610 commit 18173c5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/hiccup-canvas/src/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const circularArc = (
r: number,
start = 0,
end = TAU,
antiCCW = false
ccw = false
) => {
ctx.beginPath();
ctx.arc(pos[0], pos[1], r, start, end, antiCCW);
ctx.arc(pos[0], pos[1], r, start, end, ccw);
__endShape(ctx, attribs);
};

Expand Down
16 changes: 15 additions & 1 deletion packages/hiccup-canvas/src/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ export const draw = (
rect(ctx, attribs, shape[2], shape[3], shape[4], shape[5]);
break;
case "circle":
// FIXME need better handling / clarity around arcs & ellipse
// see issues #69 & #418
circularArc(ctx, attribs, shape[2], shape[3]);
break;
case "ellipse":
// FIXME need better handling / clarity around arcs & ellipse
// see issues #69 & #418
ellipticArc(
ctx,
attribs,
Expand All @@ -103,7 +107,17 @@ export const draw = (
);
break;
case "arc":
circularArc(ctx, attribs, shape[2], shape[3], shape[4], shape[5]);
// FIXME need new type ID for circular arcs
// see issues #69 & #418
circularArc(
ctx,
attribs,
shape[2],
shape[3],
shape[4],
shape[5],
shape[6]
);
break;
case "text":
text(ctx, attribs, shape[2], shape[3], shape[4]);
Expand Down
3 changes: 3 additions & 0 deletions packages/hiccup-canvas/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export const path = (
break;
// circular arc rel
// Note: NOT compatible w/ SVG arc segments
// FIXME need new type ID for circular arcs
// see issues #69 & #418
// can use ellipse() for elliptic arcs
case "a":
c = s[2];
c = [a[0] + c[0], a[1] + c[1]];
Expand Down
2 changes: 2 additions & 0 deletions packages/hiccup-canvas/src/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const rect = (
return path(ctx, attribs, [
["M", [pos[0] + r, pos[1]]],
["h", w],
// FIXME need new type ID for circular arcs
// see issues #69 & #418
["a", [r, 0], [r, r], r],
["v", h],
["a", [0, r], [-r, r], r],
Expand Down

0 comments on commit 18173c5

Please sign in to comment.