|
|
@ -80,39 +80,34 @@ export class Container
|
|
|
|
this.AppendPartHoles(part);
|
|
|
|
this.AppendPartHoles(part);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NestCache.PartCaled.has(cacheKey)) return false;
|
|
|
|
|
|
|
|
NestCache.PartCaled.add(cacheKey);
|
|
|
|
|
|
|
|
|
|
|
|
let combinedNfp: Paths = NestCache.NFPCache.get(cacheKey);
|
|
|
|
//------------计算nfp------------
|
|
|
|
if (!combinedNfp)
|
|
|
|
//合并(零件和所有已经放置零件的NFP)
|
|
|
|
|
|
|
|
let clipper = new Clipper();
|
|
|
|
|
|
|
|
for (let placedPart of this.Placed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
combinedNfp = [];
|
|
|
|
let nfp = placedPart.State.PlaceOutline.GetOutsideNFP(part.State.PlaceOutline);
|
|
|
|
NestCache.NFPCache.set(cacheKey, []);
|
|
|
|
if (!nfp)
|
|
|
|
//------------计算nfp------------
|
|
|
|
return false;
|
|
|
|
//合并(零件和所有已经放置零件的NFP)
|
|
|
|
let x = placedPart.PlacePosition.x;
|
|
|
|
let clipper = new Clipper();
|
|
|
|
let y = placedPart.PlacePosition.y;
|
|
|
|
for (let placedPart of this.Placed)
|
|
|
|
for (let n of nfp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let nfp = placedPart.State.PlaceOutline.GetOutsideNFP(part.State.PlaceOutline);
|
|
|
|
let f = n.map(v => { return { x: v.x + x, y: v.y + y }; });
|
|
|
|
if (!nfp)
|
|
|
|
clipper.AddPath(f, PolyType.ptSubject, true);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let x = placedPart.PlacePosition.x;
|
|
|
|
|
|
|
|
let y = placedPart.PlacePosition.y;
|
|
|
|
|
|
|
|
for (let n of nfp)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let f = n.map(v => { return { x: v.x + x, y: v.y + y }; });
|
|
|
|
|
|
|
|
clipper.AddPath(f, PolyType.ptSubject, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!clipper.Execute(ClipType.ctUnion, combinedNfp, PolyFillType.pftNonZero, PolyFillType.pftNonZero))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
NestCache.count2++;
|
|
|
|
let combinedNfp = [];
|
|
|
|
|
|
|
|
if (!clipper.Execute(ClipType.ctUnion, combinedNfp, PolyFillType.pftNonZero, PolyFillType.pftNonZero))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (combinedNfp.length === 0) return false;
|
|
|
|
if (combinedNfp.length === 0) return false;
|
|
|
|
|
|
|
|
|
|
|
|
//binNfp 减去 combinedNfp 得到最终的nfp
|
|
|
|
//binNfp 减去 combinedNfp 得到最终的nfp
|
|
|
|
let clipper = new Clipper();
|
|
|
|
clipper = new Clipper();
|
|
|
|
clipper.AddPaths(binNfp, PolyType.ptSubject, true);
|
|
|
|
clipper.AddPaths(binNfp, PolyType.ptSubject, true);
|
|
|
|
clipper.AddPaths(combinedNfp, PolyType.ptClip, true);
|
|
|
|
clipper.AddPaths(combinedNfp, PolyType.ptClip, true);
|
|
|
|
let finalNfp: Paths = [];
|
|
|
|
let finalNfp: Paths = [];
|
|
|
@ -128,10 +123,6 @@ export class Container
|
|
|
|
|
|
|
|
|
|
|
|
if (finalNfp.length === 0)
|
|
|
|
if (finalNfp.length === 0)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
//缓存combinedNfp
|
|
|
|
|
|
|
|
NestCache.NFPCache.set(cacheKey, combinedNfp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 选择零件放置后的最优占地空间(box).
|
|
|
|
* 选择零件放置后的最优占地空间(box).
|
|
|
|
* 使用凸包看起来不是最佳的
|
|
|
|
* 使用凸包看起来不是最佳的
|
|
|
|