Skip to content

Commit

Permalink
Handle straight arc in Arc.toCenterParameterization
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Mar 4, 2024
1 parent 40ed523 commit cffd0e8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ export namespace Arc {
args: [radii, xAxisRotation, largeArcFlag, sweepFlag],
} = arc

if (scalar.approx(radii[0], 0) || scalar.approx(radii[1], 0)) {
// Treat as a straight line (B 2.5. Step 1)
const v = vec2.sub(start, point)
const xAxisRotation = vec2.angle(v)
const rx = vec2.len(v) / 2

return {
center: vec2.lerp(start, point, 0.5),
radii: [rx, 0] as vec2,
angles: [0, 180] as AngleRange,
xAxisRotation,
sweep: true,
}
}

const [x1p, y1p] = vec2.rotate(
vec2.scale(vec2.sub(start, point), 0.5),
-xAxisRotation
Expand Down Expand Up @@ -74,6 +89,10 @@ export namespace Arc {
sweep: deltaAngle > 0,
}

/**
* Ensures the radii are large enough
* https://svgwg.org/svg2-draft/implnote.html#ArcCorrectionOutOfRangeRadii
**/
function correctRadii(signedRadii: vec2, p: vec2): vec2 {
const [signedRx, signedRy] = signedRadii
const [x1p, y1p] = p
Expand Down

0 comments on commit cffd0e8

Please sign in to comment.