Esempio n. 1
0
        internal void AddChild(ClipperPolyNode child)
        {
            int cnt = Children.Count;

            Children.Add(child);
            child.Parent = this;
            child.Index  = cnt;
        }
Esempio n. 2
0
        private bool IsHoleNode()
        {
            bool            result = true;
            ClipperPolyNode node   = Parent;

            while (node != null)
            {
                result = !result;
                node   = node.Parent;
            }
            return(result);
        }
Esempio n. 3
0
        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);
                }
            }
        }