Esempio n. 1
0
 public static PolygonPath FromTree(PolygonTree tree, NodeType nodeType = NodeType.Any)
 {
     return(new PolygonPath(tree.Children.Count)
     {
         { tree, nodeType }
     });
 }
Esempio n. 2
0
        public void Execute(ref PolygonTree solution, double delta)
        {
            solution.Clear();
            FixOrientations();
            DoOffset(delta);

            //now clean up 'corners' ...
            var clipper = new Clipper();

            if (delta > 0)
            {
                clipper.Execute(
                    ClipOperation.Union,
                    _destinationPolygons,
                    null,
                    solution,
                    false,
                    PolygonFillType.Positive, PolygonFillType.Positive);
            }
            else
            {
                var r     = Clipper.GetBounds(_destinationPolygons);
                var outer = new Polygon
                {
                    new IntPoint(r.Left - 10, r.Bottom + 10),
                    new IntPoint(r.Right + 10, r.Bottom + 10),
                    new IntPoint(r.Right + 10, r.Top - 10),
                    new IntPoint(r.Left - 10, r.Top - 10)
                };

                clipper.ReverseOrientation = true;

                clipper.Execute(
                    ClipOperation.Union,
                    new PolygonPath(outer),
                    null,
                    solution,
                    false,
                    PolygonFillType.Negative,
                    PolygonFillType.Negative);

                // remove the outer PolygonNode rectangle ...
                if (solution.Children.Count == 1 && solution.Children[0].Children.Count > 0)
                {
                    var outerNode = solution.Children[0];
                    solution.Children.Capacity  = outerNode.Children.Count;
                    solution.Children[0]        = outerNode.Children[0];
                    solution.Children[0].Parent = solution;
                    for (var i = 1; i < outerNode.Children.Count; i++)
                    {
                        solution.AddChild(outerNode.Children[i]);
                    }
                }
                else
                {
                    solution.Clear();
                }
            }
        }