diff --git a/packages/graphics/src/Graphics.js b/packages/graphics/src/Graphics.js index 18f1460..780fdcf 100644 --- a/packages/graphics/src/Graphics.js +++ b/packages/graphics/src/Graphics.js @@ -534,6 +534,7 @@ const startX = cx + (Math.cos(startAngle) * radius); const startY = cy + (Math.sin(startAngle) * radius); + const eps = this.geometry.closePointEps; // If the currentPath exists, take its points. Otherwise call `moveTo` to start a path. let points = this.currentPath ? this.currentPath.points : null; @@ -546,7 +547,7 @@ const xDiff = Math.abs(points[points.length - 2] - startX); const yDiff = Math.abs(points[points.length - 1] - startY); - if (xDiff < 0.001 && yDiff < 0.001) + if (xDiff < eps && yDiff < eps) { // If the point is very close, we don't add it, since this would lead to artifacts // during tessellation due to floating point imprecision. diff --git a/packages/graphics/src/Graphics.js b/packages/graphics/src/Graphics.js index 18f1460..780fdcf 100644 --- a/packages/graphics/src/Graphics.js +++ b/packages/graphics/src/Graphics.js @@ -534,6 +534,7 @@ const startX = cx + (Math.cos(startAngle) * radius); const startY = cy + (Math.sin(startAngle) * radius); + const eps = this.geometry.closePointEps; // If the currentPath exists, take its points. Otherwise call `moveTo` to start a path. let points = this.currentPath ? this.currentPath.points : null; @@ -546,7 +547,7 @@ const xDiff = Math.abs(points[points.length - 2] - startX); const yDiff = Math.abs(points[points.length - 1] - startY); - if (xDiff < 0.001 && yDiff < 0.001) + if (xDiff < eps && yDiff < eps) { // If the point is very close, we don't add it, since this would lead to artifacts // during tessellation due to floating point imprecision. diff --git a/packages/graphics/src/GraphicsGeometry.js b/packages/graphics/src/GraphicsGeometry.js index ca3c86e..85dae91 100644 --- a/packages/graphics/src/GraphicsGeometry.js +++ b/packages/graphics/src/GraphicsGeometry.js @@ -197,6 +197,14 @@ this.indicesUint16 = null; this.uvsFloat32 = null; + + /** + * Minimal distance between points that are considered different. + * Affects line tesselation. + * + * @member {number} + */ + this.closePointEps = 1e-4; } /** diff --git a/packages/graphics/src/Graphics.js b/packages/graphics/src/Graphics.js index 18f1460..780fdcf 100644 --- a/packages/graphics/src/Graphics.js +++ b/packages/graphics/src/Graphics.js @@ -534,6 +534,7 @@ const startX = cx + (Math.cos(startAngle) * radius); const startY = cy + (Math.sin(startAngle) * radius); + const eps = this.geometry.closePointEps; // If the currentPath exists, take its points. Otherwise call `moveTo` to start a path. let points = this.currentPath ? this.currentPath.points : null; @@ -546,7 +547,7 @@ const xDiff = Math.abs(points[points.length - 2] - startX); const yDiff = Math.abs(points[points.length - 1] - startY); - if (xDiff < 0.001 && yDiff < 0.001) + if (xDiff < eps && yDiff < eps) { // If the point is very close, we don't add it, since this would lead to artifacts // during tessellation due to floating point imprecision. diff --git a/packages/graphics/src/GraphicsGeometry.js b/packages/graphics/src/GraphicsGeometry.js index ca3c86e..85dae91 100644 --- a/packages/graphics/src/GraphicsGeometry.js +++ b/packages/graphics/src/GraphicsGeometry.js @@ -197,6 +197,14 @@ this.indicesUint16 = null; this.uvsFloat32 = null; + + /** + * Minimal distance between points that are considered different. + * Affects line tesselation. + * + * @member {number} + */ + this.closePointEps = 1e-4; } /** diff --git a/packages/graphics/src/utils/buildLine.js b/packages/graphics/src/utils/buildLine.js index 221d2d8..ebb02cd 100644 --- a/packages/graphics/src/utils/buildLine.js +++ b/packages/graphics/src/utils/buildLine.js @@ -36,6 +36,7 @@ { const shape = graphicsData.shape; let points = graphicsData.points || shape.points.slice(); + const eps = graphicsGeometry.closePointEps; if (points.length === 0) { @@ -57,7 +58,8 @@ const firstPoint = new Point(points[0], points[1]); const lastPoint = new Point(points[points.length - 2], points[points.length - 1]); const closedShape = shape.type !== SHAPES.POLY || shape.closeStroke; - const closedPath = firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y; + const closedPath = Math.abs(firstPoint.x - lastPoint.x) < eps + && Math.abs(firstPoint.y - lastPoint.y) < eps; // if the first point is the last point - gonna have issues :) if (closedShape)