public void AddPaths(List <List <ClipperIntPoint> > paths, ClipperJoinType joinType, ClipperEndType endType) { foreach (var p in paths) { AddPath(p, joinType, endType); } }
public void AddPath(List <ClipperIntPoint> path, ClipperJoinType joinType, ClipperEndType endType) { var highI = path.Count - 1; if (highI < 0) { return; } var newNode = new ClipperPolyNode { JoinType = joinType, EndType = endType }; //strip duplicate points from path and also get index to the lowest point ... if (endType == ClipperEndType.ClosedLine || endType == ClipperEndType.ClosedPolygon) { while (highI > 0 && path[0] == path[highI]) { highI--; } } newNode.Polygon.Capacity = highI + 1; newNode.Polygon.Add(path[0]); int j = 0, k = 0; for (var i = 1; i <= highI; i++) { if (newNode.Polygon[j] != path[i]) { j++; newNode.Polygon.Add(path[i]); if (path[i].Y > newNode.Polygon[k].Y || (path[i].Y == newNode.Polygon[k].Y && path[i].X < newNode.Polygon[k].X)) { k = j; } } } if (endType == ClipperEndType.ClosedPolygon && j < 2) { return; } polyNodes.AddChild(newNode); //if this path's lowest pt is lower than all the others then update m_lowest if (endType != ClipperEndType.ClosedPolygon) { return; } if (lowest.X < 0) { lowest = new ClipperIntPoint(polyNodes.ChildCount - 1, k); } else { var ip = polyNodes.Children[(int)lowest.X].Polygon[(int)lowest.Y]; if (newNode.Polygon[k].Y > ip.Y || (newNode.Polygon[k].Y == ip.Y && newNode.Polygon[k].X < ip.X)) { lowest = new ClipperIntPoint(polyNodes.ChildCount - 1, k); } } }