diff --git a/src/shapes.js b/src/shapes.js index 213b02be1da496e96afbaed22131e2f802236130..dbfa79c981b709725b85f07f2b63401a2b978fc9 100644 --- a/src/shapes.js +++ b/src/shapes.js @@ -16,7 +16,8 @@ function getDistance(p1, p2) { return Math.hypot(x1 - x0, y1 - y0) } -function vectorLength([x, y]) { +function vectorLen(v) { + const [x, y] = v return Math.hypot(x, y) } @@ -26,7 +27,7 @@ function diffVector([x0, y0], [x1, y1]) { function angleBetweenVectors(p1, p2) { const [[x0, y0], [x1, y1]] = [p1, p2] - return Math.acos((x0 * x1 + y0 * y1) / (vectorLength(p1) * vectorLength(p2))) + return Math.acos((x0 * x1 + y0 * y1) / (vectorLen(p1) * vectorLen(p2))) } function boundingCoords(points) { @@ -127,7 +128,6 @@ function couldBeLine(points) { ) const pivot = points[0] let cumulativeThreshold = 0 - for (let i = 2; i < points.length; i++) { const prev = points[i - 1] const curr = points[i] @@ -136,7 +136,7 @@ function couldBeLine(points) { const angle = angleBetweenVectors(d1, d2) if (Math.abs(angle) > LINE_ANGLE_THRESHOLD) { - const d2Len = vectorLength(d2) + const d2Len = vectorLen(d2) if (cumulativeThreshold < vectorThreshold && d2Len < vectorThreshold) { cumulativeThreshold += d2Len continue