Commit 22d30135 by Starbeamrainbowlabs

### Bugfix the new algorithm

parent 04b599af
 ... ... @@ -2,7 +2,7 @@ Ramer Douglas Peucker Demo Line Simplification Demo ... ... @@ -10,7 +10,7 @@
• Points:
• Epsilon:
• Min Area:
... ...
 ... ... @@ -110,10 +110,10 @@ class RDPDemo // Clear the screen canvas.width = canvas.width; if(this.drawSimpleLine) this.draw_line(canvas, context, this.simplePoints, this.simpleLine) if(this.drawRawLine) this.draw_line(canvas, context, this.points, this.rawLine); if(this.drawSimpleLine) this.draw_line(canvas, context, this.simplePoints, this.simpleLine) } draw_line(canvas, context, points, settings) { ... ...
 ... ... @@ -10,10 +10,16 @@ import Vector from './lib/Vector.js'; */ function simplify_line(points, min_area) { let smallest_area = Number.MAX_SAFE_INTEGER, smallest_area_i = 1; // We need 3+ points to use this algorithm! if(points.length < 3) return points; while(smallest_area > min_area) points = points.slice(); // Shallow clone the array while(true) { let smallest_area = Number.MAX_SAFE_INTEGER, smallest_area_i = 1; for(let i = 1; i < points.length - 1; i++) { let next_area = triangle_area(points[i - 1], points[i], points[i + 1]); ... ... @@ -23,9 +29,14 @@ function simplify_line(points, min_area) } } if(smallest_area >= min_area || points.length <= 3) break; // Remove the central point of the smallest triangle points.splice(smallest_area_i, 1); } return points; } /** ... ... @@ -39,7 +50,7 @@ function triangle_area(a, b, c) { return Math.abs( ( a.x * (b.x - c.x) + a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) ) / 2 ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!