Skip to content

Commit

Permalink
fix: Remove needles origin adjustment for bezier interpolation
Browse files Browse the repository at this point in the history
- It seemed needed but the real issue was that the logic was invalid
  • Loading branch information
miyanokomiya committed Feb 27, 2024
1 parent 38041a9 commit 8b4d4b9
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/geo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,25 +1637,17 @@ export function getBezierInterpolation(
const len = points.length
if (len < 3) return []

// This algorithm appears dependent on the absolute position of the line.
// => Remove the absolute position effect for consistency.
const origin = points[0]
const adjustedPoints = points.map((p) => sub(p, origin))

const A = solveBezierInterpolationEquations(adjustedPoints)
const A = solveBezierInterpolationEquations(points)
const B: IVec2[] = []
for (let i = 0; i < adjustedPoints.length - 2; i++) {
B[i] = sub(multi(adjustedPoints[i + 1], 2), A[i + 1])
for (let i = 0; i < points.length - 2; i++) {
B[i] = sub(multi(points[i + 1], 2), A[i + 1])
}
B[adjustedPoints.length - 2] = multi(
add(
A[adjustedPoints.length - 2],
adjustedPoints[adjustedPoints.length - 1]
),
B[points.length - 2] = multi(
add(A[points.length - 2], points[points.length - 1]),
1 / 2
)

return A.map((a, i) => [add(a, origin), add(B[i], origin)])
return A.map((a, i) => [a, B[i]])
}

/**
Expand Down

0 comments on commit 8b4d4b9

Please sign in to comment.