You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
543 B
JavaScript
26 lines
543 B
JavaScript
function distance([x1, y1], [x2, y2]) {
|
|
return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
|
|
}
|
|
|
|
export function simplifyCurve(curve, minDistance) {
|
|
if (curve.length === 0) return []
|
|
|
|
const newCurve = [curve[0]]
|
|
|
|
let lastPt = curve[0]
|
|
for (let i = 1; i < curve.length; i++) {
|
|
const pt = curve[i]
|
|
|
|
if (distance(lastPt, pt) >= minDistance) {
|
|
newCurve.push(pt)
|
|
lastPt = pt
|
|
}
|
|
}
|
|
|
|
if (lastPt !== curve.at(-1)) {
|
|
newCurve.push(curve.at(-1))
|
|
}
|
|
|
|
return newCurve
|
|
}
|