fix for some pool nesting errors

This commit is contained in:
Stewart Allen 2020-10-30 20:47:45 -04:00
commit 6cbf5abba0
3 changed files with 13 additions and 14 deletions

View file

@ -87,12 +87,13 @@
* @param {Bounds} parent
* @returns {boolean} true if fully inside parent bounds
*/
PRO.isNested = function(parent) {
PRO.isNested = function(parent, tolerance) {
let grace = tolerance || CONF.precision_bounds;
return (
this.minx >= parent.minx - CONF.precision_bounds && // min-x
this.maxx <= parent.maxx + CONF.precision_bounds && // max-x
this.miny >= parent.miny - CONF.precision_bounds && // min-y
this.maxy <= parent.maxy + CONF.precision_bounds // max-y
this.minx >= parent.minx - grace && // min-x
this.maxx <= parent.maxx + grace && // max-x
this.miny >= parent.miny - grace && // min-y
this.maxy <= parent.maxy + grace // max-y
);
};

View file

@ -828,10 +828,9 @@
*/
PRO.isInside = function(poly, tolerance) {
// throw new Error("isInside");
if (!(
// poly.overlaps(this) &&
this.bounds.isNested(poly.bounds)
)) return false;
if (!this.bounds.isNested(poly.bounds, tolerance * 3)) {
return false;
}
let mid,
midcheck,

View file

@ -995,7 +995,8 @@
* @param {Function} emitter called to emit each polygon
* @param {number} offset tool diameter used for this depth-first cut
*
* used for CAM depth first layer output
* used for CAM depth first layer output. included here for convenience
* because it relies heavily on other functions in the print library.
*/
function poly2polyDepthFirstEmit(array, startPoint, emitter, offset) {
let layers = [],
@ -1012,7 +1013,7 @@
// sort by area descending
return p2.area() - p1.area();
}).forEach(function (poly) {
// a polygon should be made into a pool if:
// a polygon should be made into a pool if any is true:
// - it is open
// - it has more than one sibling
// - it has no parent (top/outer most)
@ -1022,7 +1023,7 @@
poly.pool = [];
poly.poolsDown = [];
} else {
// otherwise walk up the parent tree to find a pool to join
// otherwise search the poly's parents (same layer) to find a pool to join
let search = poly.parent;
// walk up until pool found
while (search && !search.pool) {
@ -1105,8 +1106,6 @@
function polygonFitsIn(inside, outside, tolerance) {
return inside.isInside(outside, tolerance);
// return inside.area() <= outside.area() + tolerance &&
// (polygonWithinOffset(inside, outside, tolerance) || inside.isInside(outside, tolerance));
}
function polygonWithinOffset(poly1, poly2, offset) {