diff --git a/src/common/geometry.js b/src/common/geometry.js index 5b92744..a46534e 100644 --- a/src/common/geometry.js +++ b/src/common/geometry.js @@ -365,6 +365,13 @@ export const downsample = (vertices, tolerance = 0.0001) => { return result } +// Normalize the theta value to the range [0, 2*pi) +export const normalizeTheta = (theta) => { + const TWO_PI = Math.PI * 2 + + return ((theta % TWO_PI) + TWO_PI) % TWO_PI +} + // Convert x,y vertices to theta, rho vertices export const toThetaRho = (subsampledVertices, maxRadius, rhoMax) => { let vertices = [] @@ -389,8 +396,7 @@ export const toThetaRho = (subsampledVertices, maxRadius, rhoMax) => { subsampledVertices[next].x, subsampledVertices[next].y, ) - // Convert to [0, 2pi] - rawTheta = (rawTheta + 2.0 * Math.PI) % (2.0 * Math.PI) + rawTheta = normalizeTheta(rawTheta) // Compute the difference to the last point. let deltaTheta = rawTheta - previousRawTheta @@ -407,7 +413,7 @@ export const toThetaRho = (subsampledVertices, maxRadius, rhoMax) => { previousRawTheta = rawTheta previousTheta = theta - vertices.push(new Victor(theta, rho)) + vertices.push(new Victor(normalizeTheta(theta), rho)) } return vertices diff --git a/src/features/export/ScaraGCodeExporter.js b/src/features/export/ScaraGCodeExporter.js index d39b9eb..7ab227a 100644 --- a/src/features/export/ScaraGCodeExporter.js +++ b/src/features/export/ScaraGCodeExporter.js @@ -8,20 +8,6 @@ export default class ScaraGCodeExporter extends GCodeExporter { this.offsetY = 0 } - // collects stats for use in PRE and POST blocks - collectStats(vertices) { - return { - mintheta: Math.min(...vertices.map((v) => v.x)), - minrho: Math.min(...vertices.map((v) => v.y)), - maxtheta: Math.max(...vertices.map((v) => v.x)), - maxrho: Math.max(...vertices.map((v) => v.y)), - starttheta: vertices[0].x, - startrho: vertices[0].y, - endtheta: vertices[vertices.length - 1].x, - endrho: vertices[vertices.length - 1].y, - } - } - // transforms vertices into a SCARA GCode format transformVertices(vertices) { vertices = toScaraGcode(