private static IEnumerable <HPGLLine> OptimizeDistanze(IEnumerable <HPGLLine> lines) { var newlist = new List <HPGLLine> { lines.First() }; var list = new List <HPGLLine>(); list.AddRange(lines.Skip(1)); while (list.Any()) { Point3D ptfrom = newlist.Last().Commands.Last().PointTo; double maxdist = double.MaxValue; HPGLLine minDistLine = null; foreach (var l in list) { Point3D pt = l.Commands.First().PointFrom; double dx = (pt.X ?? 0.0) - (ptfrom.X ?? 0.0); double dy = (pt.Y ?? 0.0) - (ptfrom.Y ?? 0.0); double dist = Math.Sqrt(dx * dx + dy * dy); if (dist < maxdist) { maxdist = dist; minDistLine = l; } } list.Remove(minDistLine); newlist.Add(minDistLine); } return(newlist); }
private IEnumerable <HPGLLine> OffsetLine(double offset, HPGLLine line) { var newlines = new List <HPGLLine> { line }; var co = new ClipperOffset(); var solution = new List <List <IntPoint> >(); var solution2 = new List <List <IntPoint> >(); solution.Add(line.Commands.Select(x => new IntPoint(_scale * x.PointFrom.X0, _scale * x.PointFrom.Y0)).ToList()); co.AddPaths(solution, JoinType.jtRound, EndType.etClosedPolygon); co.Execute(ref solution2, offset); var existingline = line; foreach (var polygon in solution2) { var newcmds = new List <HPGLCommand>(); HPGLCommand last = null; foreach (var pt in polygon) { var from = new Point3D { X = pt.X / _scale, Y = pt.Y / _scale }; var hpgl = new HPGLCommand { PointFrom = from, CommandType = HPGLCommand.HPGLCommandType.PenDown }; newcmds.Add(hpgl); if (last != null) { last.PointTo = from; } last = hpgl; } last.PointTo = newcmds.First().PointFrom; if (existingline == null) { // add new line existingline = new HPGLLine { PreCommands = new List <HPGLCommand> { new HPGLCommand { CommandType = HPGLCommand.HPGLCommandType.PenUp } }, PostCommands = new List <HPGLCommand>(), ParentLine = line.ParentLine }; newlines.Add(existingline); } existingline.Commands = newcmds; existingline.PreCommands.Last(l => l.IsPenCommand).PointTo = newcmds.First().PointFrom; existingline = null; } return(newlines); }
public bool IsEmbeddedEx(HPGLLine to) { // TODO: we test points only!!! // but it would be necessary to thes the whole line return(_polygon.ArePointsInPolygon(to._polygon.Points)); }
public IList <HPGLCommand> ConvertInvert(IList <HPGLCommand> list) { // split int startidx = 0; var linelist = new List <HPGLLine>(); IEnumerable <HPGLCommand> postCommands = null; IEnumerable <HPGLCommand> preCommands = list.Skip(startidx).TakeWhile(e => !e.IsPenCommand); startidx += preCommands.Count(); while (startidx < list.Count) { HPGLLine line = GetHPGLLine(list, ref startidx); if (startidx >= list.Count && !line.Commands.Any()) { postCommands = line.PreCommands; } else { linelist.Add(line); } } // rearrange var lines = OrderLines(linelist); // rebuild list var newlist = new List <HPGLCommand>(); newlist.AddRange(preCommands); foreach (var line in lines) { newlist.AddRange(line.PreCommands); newlist.AddRange(line.Commands); newlist.AddRange(line.PostCommands); } if (postCommands != null) { newlist.AddRange(postCommands); } return(newlist); }
private static HPGLLine GetHPGLLine(IList <HPGLCommand> list, ref int startidx) { var line = new HPGLLine { PreCommands = list.Skip(startidx).TakeWhile(e => !e.IsPenDownCommand) }; startidx += line.PreCommands.Count(); line.Commands = list.Skip(startidx).TakeWhile(e => e.IsPenDownCommand); startidx += line.Commands.Count(); line.PostCommands = list.Skip(startidx).TakeWhile(e => false); // always empty startidx += line.PostCommands.Count(); return(line); }
public bool IsEmbedded(HPGLLine to) { if (ReferenceEquals(this, to)) { return(false); } bool isRectangleEmbedded = MaxX >= to.MaxX && MinX <= to.MinX && MaxY >= to.MaxY && MinY <= to.MinY; if (!isRectangleEmbedded) { return(false); } return(IsEmbeddedEx(to)); }
public bool IsEmbeddedEx(HPGLLine to) { return(_polygon.ArePointsInPolygon(to._polygon.Points)); }