change fingerprinting algorithm
This commit is contained in:
parent
c3eb7ce810
commit
aeb8d9512a
6 changed files with 79 additions and 20 deletions
|
|
@ -58,6 +58,17 @@
|
|||
UTIL.isCloseTo(this.maxy, bounds.maxy, margin);
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Number} absolute delta in x,y coordinate space
|
||||
*/
|
||||
PRO.delta = function(bounds) {
|
||||
return
|
||||
Math.abs(this.minx - bounds.minx) +
|
||||
Math.abs(this.miny - bounds.miny) +
|
||||
Math.abs(this.maxx - bounds.maxx) +
|
||||
Math.abs(this.maxy - bounds.maxy);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Bounds} b
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@
|
|||
const pa = this.points,
|
||||
pln = pa.length,
|
||||
open = this.open,
|
||||
newp = newPolygon(),
|
||||
newp = newPolygon().copyZ(this.z),
|
||||
min = dist || BASE.config.precision_merge;
|
||||
let lo;
|
||||
newp.push(lo = pa[0]);
|
||||
|
|
@ -519,7 +519,7 @@
|
|||
redo |= ang[0] > 90;
|
||||
}
|
||||
if (redo) {
|
||||
const newp = newPolygon();
|
||||
const newp = newPolygon().copyZ(this.z);
|
||||
// newp.debug = this.debug = true;
|
||||
newp.open = open;
|
||||
for (let i=0; i<pln; i++) {
|
||||
|
|
@ -803,7 +803,7 @@
|
|||
* @returns {Polygon}
|
||||
*/
|
||||
PRO.clone = function(deep) {
|
||||
let np = newPolygon(),
|
||||
let np = newPolygon().copyZ(this.z),
|
||||
ln = this.length,
|
||||
i = 0;
|
||||
|
||||
|
|
@ -820,6 +820,25 @@
|
|||
return np;
|
||||
};
|
||||
|
||||
// special shallow for-render-or-read-only cloning
|
||||
PRO.cloneZ = function(z, stop) {
|
||||
let p = newPolygon();
|
||||
p.z = z;
|
||||
p.open = this.open;
|
||||
p.points = this.points;
|
||||
if (this.inner) {
|
||||
p.inner = this.inner.map(p => p.cloneZ(z, true));
|
||||
}
|
||||
return p;
|
||||
};
|
||||
|
||||
PRO.copyZ = function(z) {
|
||||
if (z !== undefined) {
|
||||
this.z = z;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* set all points' z value
|
||||
*
|
||||
|
|
@ -839,7 +858,7 @@
|
|||
* @returns {number} z value of first point
|
||||
*/
|
||||
PRO.getZ = function(i) {
|
||||
return this.points[i || 0].z;
|
||||
return this.z !== undefined ? this.z : this.points[i || 0].z;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -871,37 +871,62 @@
|
|||
flatten(polys).sort((a,b) => {
|
||||
return a.area() > b.area();
|
||||
}).forEach(p => {
|
||||
finger.push(p.area());
|
||||
finger.push(p.perimeter());
|
||||
finger.push(p.bounds);
|
||||
// finger.push(p.area());
|
||||
// finger.push(p.perimeter());
|
||||
// finger.push(p.bounds);
|
||||
finger.push({
|
||||
c: p.circularityDeep(),
|
||||
p: p.perimeterDeep(),
|
||||
b: p.bounds
|
||||
});
|
||||
});
|
||||
return finger;
|
||||
}
|
||||
|
||||
// compare fingerprint arrays
|
||||
function fingerprintCompare(a, b) {
|
||||
// true if array is the same object
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
// fail on missing array
|
||||
if (!a || !b) {
|
||||
return false;
|
||||
}
|
||||
// require identical length arrays
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i=0; i<a.length; i += 3) {
|
||||
if (Math.abs(a[i] - b[i]) > 0.001) {
|
||||
for (let i=0; i<a.length; i++) {
|
||||
let ra = a[i];
|
||||
let rb = b[i];
|
||||
// test circularity
|
||||
if (Math.abs(ra.c - rb.c) > 0.001) {
|
||||
return false;
|
||||
}
|
||||
if (Math.abs(a[i+1] - b[i+1]) > 0.0001) {
|
||||
// test perimeter
|
||||
if (Math.abs(ra.p - rb.p) > 0.001) {
|
||||
return false;
|
||||
}
|
||||
if (Math.abs(a[i+2].centerx() - b[i+2].centerx()) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
if (Math.abs(a[i+2].centery() - b[i+2].centery()) > 0.0001) {
|
||||
// test bounds
|
||||
if (ra.b.delta(rb.b) > 0.001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// for (let i=0; i<a.length; i += 3) {
|
||||
// if (Math.abs(a[i] - b[i]) > 0.001) {
|
||||
// return false;
|
||||
// }
|
||||
// if (Math.abs(a[i+1] - b[i+1]) > 0.0001) {
|
||||
// return false;
|
||||
// }
|
||||
// if (Math.abs(a[i+2].centerx() - b[i+2].centerx()) > 0.0001) {
|
||||
// return false;
|
||||
// }
|
||||
// if (Math.abs(a[i+2].centery() - b[i+2].centery()) > 0.0001) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue