Exemple #1
0
        private static void AddNodeToPath(PolygonNode node, NodeType nodeType, PolygonPath paths)
        {
            var match = true;

            switch (nodeType)
            {
            case NodeType.Open: return;

            case NodeType.Closed: match = !node.IsOpen; break;

            case NodeType.Any:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(nodeType), nodeType, null);
            }

            if (node.Polygon.Count > 0 && match)
            {
                paths.Add(node.Polygon);
            }

            foreach (var childNode in node.Children)
            {
                AddNodeToPath(childNode, nodeType, paths);
            }
        }
Exemple #2
0
        private void Add(PolygonNode treeNode, NodeType nodeType)
        {
            var match = true;

            switch (nodeType)
            {
            case NodeType.Open: return;

            case NodeType.Closed: match = !treeNode.IsOpen; break;
            }

            if (treeNode.Polygon.Count > 0 && match)
            {
                Add(treeNode.Polygon);
            }

            foreach (var polyNode in treeNode.Children)
            {
                Add(polyNode, nodeType);
            }
        }
Exemple #3
0
        public void AddPath(Polygon path, JoinType joinType, EndType endType)
        {
            var highI = path.Count - 1;

            if (highI < 0)
            {
                return;
            }

            var newNode = new PolygonNode
            {
                JoinType = joinType,
                EndType  = endType
            };

            //strip duplicate points from path and also get index to the lowest point ...
            if (endType == EndType.ClosedLine || endType == EndType.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])
                {
                    continue;
                }

                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 == EndType.ClosedPolygon && j < 2)
            {
                return;
            }

            _polygonNodes.AddChild(newNode);

            //if this path's lowest point is lower than all the others then update _lowest
            if (endType != EndType.ClosedPolygon)
            {
                return;
            }

            if (_lowestX < 0)
            {
                _lowestX = _polygonNodes.Children.Count - 1;
                _lowestY = k;
            }
            else
            {
                var ip = _polygonNodes.Children[_lowestX].Polygon[_lowestY];

                if (newNode.Polygon[k].Y > ip.Y ||
                    newNode.Polygon[k].Y == ip.Y &&
                    newNode.Polygon[k].X < ip.X)
                {
                    _lowestX = _polygonNodes.Children.Count - 1;
                    _lowestY = k;
                }
            }
        }
Exemple #4
0
 internal void AddChild(PolygonNode child)
 {
     Children.Add(child);
 }
Exemple #5
0
 internal void AddChild(PolygonNode child)
 {
     child.Parent = this;
     child.Index  = Children.Count;
     Children.Add(child);
 }