You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
|
|
namespace DeepNestLib
|
|
{
|
|
public class RawDetail
|
|
{
|
|
public List<LocalContour> Outers = new List<LocalContour>();
|
|
public List<LocalContour> Holes = new List<LocalContour>();
|
|
|
|
public RectangleF BoundingBox()
|
|
{
|
|
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 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;
|
|
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);
|
|
}
|
|
}
|
|
return po;
|
|
}
|
|
|
|
public void Offset(double v1, double v2)
|
|
{
|
|
for(int i=0;i<Outers.Count;i++)
|
|
{
|
|
var nn = Outers[i];
|
|
for(int j=0;j<nn.Points.Count;j++)
|
|
{
|
|
PointF pt = nn.Points[j];
|
|
nn.Points[j] = PointF.Add(pt, new SizeF((float)v1, (float)v2));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |