rewrite gpu flatness detection to use same algorithm as cpu code
This commit is contained in:
parent
0ff04f7161
commit
7642aaab7b
1 changed files with 29 additions and 13 deletions
|
|
@ -265,24 +265,40 @@ export class Topo {
|
||||||
// drop interior points along a continuous slope
|
// drop interior points along a continuous slope
|
||||||
for (let poly of lines) {
|
for (let poly of lines) {
|
||||||
let { points } = poly;
|
let { points } = poly;
|
||||||
|
if (points.length < 2) continue;
|
||||||
let merged = [ points[0] ];
|
let merged = [ points[0] ];
|
||||||
let lp = points[1];
|
let lastP = points[0];
|
||||||
let dz = points[0].z - lp.z;
|
let latent = null;
|
||||||
for (let i=2; i<points.length; i++) {
|
let lastSlope = undefined;
|
||||||
let np = points[i];
|
for (let i=1; i<points.length; i++) {
|
||||||
let ndz = np.z - lp.z;
|
let newP = points[i];
|
||||||
if (Math.abs(dz - ndz) > flatness) {
|
const dl = (newP.x - lastP.x) || (newP.y - lastP.y);
|
||||||
// slope changed
|
const dz = newP.z - lastP.z;
|
||||||
merged.push(lp);
|
const slope = Math.atan2(dz, dl);
|
||||||
dz = ndz;
|
if (curvesOnly && Math.abs(dz) < flatness) {
|
||||||
} else if (curvesOnly && Math.abs(ndz) < flatness) {
|
// end current segment with latent if present
|
||||||
|
if (latent) {
|
||||||
|
merged.push(latent);
|
||||||
|
latent = null;
|
||||||
|
}
|
||||||
// add empty points as path separators
|
// add empty points as path separators
|
||||||
merged.push(undefined);
|
merged.push(undefined);
|
||||||
|
lastSlope = undefined;
|
||||||
|
} else if (lastSlope !== undefined && Math.abs(lastSlope - slope) < flatness) {
|
||||||
|
latent = newP;
|
||||||
|
} else {
|
||||||
|
if (latent) {
|
||||||
|
merged.push(latent);
|
||||||
|
latent = null;
|
||||||
|
}
|
||||||
|
merged.push(newP);
|
||||||
|
lastSlope = slope;
|
||||||
}
|
}
|
||||||
lp = np;
|
lastP = newP;
|
||||||
}
|
}
|
||||||
if (merged.peek() !== lp) {
|
// add final latent point if present
|
||||||
merged.push(lp);
|
if (latent && merged.peek() !== latent) {
|
||||||
|
merged.push(latent);
|
||||||
}
|
}
|
||||||
poly.points = merged;
|
poly.points = merged;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue