move fingerprinting into polygons utility class
This commit is contained in:
parent
6c0d804f8c
commit
674bb48689
6 changed files with 98 additions and 59 deletions
|
|
@ -37,7 +37,9 @@ var gs_base_polygons = exports;
|
|||
toClipper : toClipper,
|
||||
fromClipperNode : fromClipperNode,
|
||||
fromClipperTree : fromClipperTree,
|
||||
cleanClipperTree : cleanClipperTree
|
||||
cleanClipperTree : cleanClipperTree,
|
||||
fingerprintCompare: fingerprintCompare,
|
||||
fingerprint: fingerprint
|
||||
};
|
||||
|
||||
/** ******************************************************************
|
||||
|
|
@ -803,4 +805,36 @@ var gs_base_polygons = exports;
|
|||
return points;
|
||||
}
|
||||
|
||||
function fingerprint(polys) {
|
||||
let finger = [];
|
||||
flatten(polys).sort((a,b) => {
|
||||
return a.area() > b.area();
|
||||
}).forEach(p => {
|
||||
finger.push(p.area());
|
||||
finger.push(p.perimeter());
|
||||
});
|
||||
return finger;
|
||||
}
|
||||
|
||||
function fingerprintCompare(a, b) {
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (!a || !b) {
|
||||
return false;
|
||||
}
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i=0; i<a.length; i += 2) {
|
||||
if (Math.abs(a[i] - b[i]) > 0.001) {
|
||||
return false;
|
||||
}
|
||||
if (Math.abs(a[i+1] - b[i+1]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue