add hard edge simplification
This commit is contained in:
parent
455e401794
commit
d85da1c3a3
51
src/main.js
51
src/main.js
|
|
@ -10,7 +10,7 @@ let canvases = [];
|
||||||
let mode = "draw"
|
let mode = "draw"
|
||||||
|
|
||||||
let minSegmentSize = 5;
|
let minSegmentSize = 5;
|
||||||
let maxSmoothAngle = 0.2;
|
let maxSmoothAngle = 0.6;
|
||||||
|
|
||||||
let tools = {
|
let tools = {
|
||||||
select: {
|
select: {
|
||||||
|
|
@ -99,34 +99,26 @@ class Shape {
|
||||||
}
|
}
|
||||||
simplify(mode="smooth") {
|
simplify(mode="smooth") {
|
||||||
// Mode can be corners, smooth or auto
|
// Mode can be corners, smooth or auto
|
||||||
// let maxIndex;
|
if (mode=="corners") {
|
||||||
// for (let j=0; j<5; j++) {
|
let angles;
|
||||||
// if (this.curves.length < 3) return;
|
while (this.curves.length > 3) {
|
||||||
// maxIndex = this.curves.length-1;
|
angles = [2*Math.PI]
|
||||||
// for (let i=1; i<maxIndex; i++) {
|
for (let i=1; i<this.curves.length-1; i++) {
|
||||||
// let P1 = this.curves[i]
|
let P1 = this.curves[i]
|
||||||
// let P2 = this.curves[i-1]
|
let P2 = this.curves[i-1]
|
||||||
// let P3 = this.curves[i+1]
|
let P3 = this.curves[i+1]
|
||||||
// let angle = Math.atan2(P3.y - P1.y, P3.x - P1.x) -
|
let angle = Math.atan2(P3.y - P1.y, P3.x - P1.x) -
|
||||||
// Math.atan2(P2.y - P1.y, P2.x - P1.x);
|
Math.atan2(P2.y - P1.y, P2.x - P1.x);
|
||||||
// angle = Math.PI - Math.abs(angle)
|
angles[i] = Math.abs(Math.PI - Math.abs(angle))
|
||||||
// if (Math.abs(angle) < maxSmoothAngle) {
|
}
|
||||||
// if (mode=="corners") {
|
let smallestAngle = Math.min(...angles)
|
||||||
// this.curves.splice(i,1)
|
if (smallestAngle < maxSmoothAngle) {
|
||||||
// } else if (mode=="smooth") {
|
this.curves.splice(angles.indexOf(smallestAngle), 1)
|
||||||
// P3.cp1x = P1.x;
|
} else {
|
||||||
// P3.cp1y = P1.y;
|
break;
|
||||||
// P3.cp2x = P1.x;
|
}
|
||||||
// P3.cp2y = P1.y;
|
}
|
||||||
// this.curves.splice(i,1)
|
} else if (mode=="smooth") {
|
||||||
// }
|
|
||||||
// i;
|
|
||||||
// maxIndex--;
|
|
||||||
// console.log(angle)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
let error = 30;
|
let error = 30;
|
||||||
let points = [[this.startx, this.starty]]
|
let points = [[this.startx, this.starty]]
|
||||||
for (let curve of this.curves) {
|
for (let curve of this.curves) {
|
||||||
|
|
@ -139,6 +131,7 @@ class Shape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class GraphicsObject {
|
class GraphicsObject {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue