Пример #1
0
        /// <summary>
        /// Checks if the other group's outer perimeter is inside this group's perimeter.  Inclusive of the two groups
        /// sharing vertices.
        /// </summary>
        /// <param name="otherGroup"></param>
        /// <returns>True if the other group is inside this group, false otherwise.</returns>
        public bool IsOtherGroupInThisGroup(ConnectedNodeGroup otherGroup)
        {
            HashSet <Vector2> sharedVertices = this.GetSharedVertices(otherGroup);

            if (sharedVertices.Count == 0)
            {
                return(GeometryFuncs.IsPolyInPoly(otherGroup.outerPerimSimplified, this.outerPerimSimplified));
            }
            else
            {
                bool isInside = true;
                foreach (PolygonSplittingGraphNode node in otherGroup.nodes.Values)
                {
                    var nodeCoord = new Vector2(node.x, node.y);
                    if (sharedVertices.Contains(nodeCoord))
                    {
                        continue;
                    }
                    if (!GeometryFuncs.IsPointInPoly(nodeCoord, this.outerPerimSimplified))
                    {
                        isInside = false;
                        break;
                    }
                }
                return(isInside);
            }
        }
Пример #2
0
        /// <summary>
        /// Checks which potential holes could be contained within this polygon and adds them
        /// to holes if they pass the IsPolyInPoly check.
        /// </summary>
        /// <param name="potentialHoles"></param>
        /// <returns></returns>
        private List <Vector2>[] _GetContainedHoles(List <Vector2>[] potentialHoles)
        {
            var confirmedHoles = new List <List <Vector2> >();

            foreach (List <Vector2> hole in potentialHoles)
            {
                HashSet <Vector2> sharedVertices;
                if (GeometryFuncs.IsPolyInPoly(hole.ToArray(), this._outerPerim))
                {
                    confirmedHoles.Add(hole);
                }
                else if ((sharedVertices = this._GetHoleSharedVertices(hole)).Count > 0)
                {
                    int holeVerticesInPoly = 0; //guilty until proven innocent, to prevent snake poly from containing hole
                    foreach (Vector2 holeVertex in hole)
                    {
                        if (sharedVertices.Contains(holeVertex))
                        {
                            continue;
                        }
                        if (GeometryFuncs.IsPointInPoly(holeVertex, this._outerPerim) &&
                            !GeometryFuncs.IsPointOnPolyBoundary(holeVertex, this._outerPerim))
                        {
                            holeVerticesInPoly++;
                        }
                    }
                    if (holeVerticesInPoly > 0)
                    {
                        confirmedHoles.Add(hole);
                    }
                }
            }
            return(confirmedHoles.ToArray());
        }