Skip to content

Commit

Permalink
fel88#12 upd (hull clipping + simplification draw)
Browse files Browse the repository at this point in the history
# Conflicts:
#	DeepNestLib/Background.cs
#	DeepNestLib/DeepNestLib.csproj
#	DeepNestLib/DxfParser.cs
#	DeepNestLib/NFP.cs
#	DeepNestLib/NestingContext.cs
#	DeepNestLib/RawDetail.cs
#	DeepNestLib/SvgNest.cs
#	DeepNestLib/SvgNestConfig.cs
#	DeepNestLib/SvgPoint.cs
#	DeepNestPort/Form1.Designer.cs
#	DeepNestPort/Form1.cs
#	DeepNestPort/Form1.resx
  • Loading branch information
fel88 authored and 9swampy committed Jul 3, 2021
1 parent 65bef76 commit 7f1fc87
Show file tree
Hide file tree
Showing 8 changed files with 522 additions and 398 deletions.
2 changes: 1 addition & 1 deletion DeepNestLib/NFP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public NFP()
{
this.points = new SvgPoint[0];
}

public NFP(IEnumerable<SvgPoint> points)
{
this.points = points.DeepClone();
Expand Down
47 changes: 7 additions & 40 deletions DeepNestLib/NestingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,49 +323,15 @@ public void LoadInputData(string path, int count)

public bool TryImportFromRawDetail(RawDetail raw, int src, out NFP loadedNfp)
{
NFP po = null;
List<NFP> nfps = new List<NFP>();
foreach (var item in raw.Outers)
loadedNfp = raw.ToNfp();
if (loadedNfp == null)
{
var nn = new NFP();
nfps.Add(nn);
foreach (var pitem in item.Points)
{
nn.AddPoint(new SvgPoint(pitem.X, pitem.Y));
}
}

if (nfps.Any())
{
var tt = nfps.OrderByDescending(z => z.Area).First();
po = tt; // Reference caution needed here; should be cloning not messing with the original object?
po.Name = raw.Name;

foreach (var r in nfps)
{
if (r == tt)
{
continue;
}

if (po.Children == null)
{
po.Children = new List<NFP>();
}

po.Children.Add(r);
}

po.Source = src;
Polygons.Add(po);
loadedNfp = po;
return true;
}
else
{
loadedNfp = null;
return false;
}

loadedNfp.Source = src;
Polygons.Add(loadedNfp);
return true;
}

public int GetNextSource()
Expand All @@ -376,6 +342,7 @@ public int GetNextSource()
}
return 0;
}

public int GetNextSheetSource()
{
if (Sheets.Any())
Expand Down
64 changes: 58 additions & 6 deletions DeepNestLib/RawDetail.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
namespace DeepNestLib
{
using System.Collections.Generic;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;

public class RawDetail
public class RawDetail
{
public List<LocalContour> Outers = new List<LocalContour>();
public List<LocalContour> Holes = new List<LocalContour>();

public RectangleF BoundingBox()
{
public List<LocalContour> Outers = new List<LocalContour>();
public List<LocalContour> Holes = new List<LocalContour>();
GraphicsPath gp = new GraphicsPath();
foreach (var item in Outers)
{
gp.AddPolygon(item.Points.ToArray());
}

return gp.GetBounds();
}

public string Name { get; set; }

public NFP ToNfp()
{
NFP po = null;
List<NFP> nfps = new List<NFP>();
foreach (var item in this.Outers)
{
var nn = new NFP();
nfps.Add(nn);
foreach (var pitem in item.Points)
{
nn.AddPoint(new SvgPoint(pitem.X, pitem.Y));
}
}

if (nfps.Any())
{
var tt = nfps.OrderByDescending(z => z.Area).First();
po = tt; // Reference caution needed here; should be cloning not messing with the original object?
po.Name = Name;

foreach (var r in nfps)
{
if (r == tt)
{
continue;
}

if (po.Children == null)
{
po.Children = new List<NFP>();
}
po.Children.Add(r);
}
}

public string Name { get; set; }
return po;
}
}
}
}
3 changes: 3 additions & 0 deletions DeepNestLib/SvgNestConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class SvgNestConfig
public double TimeRatio = 0.5;
public bool MergeLines = false;

// port features (don't exist in the original DeepNest project)
public bool clipByHull = false;

public double CurveTolerance
{
get
Expand Down
Loading

0 comments on commit 7f1fc87

Please sign in to comment.