Exemplo n.º 1
0
        private static bool IsConvex(LinkedListNode <EarPoint> ele, EarPolygon poly)
        {
            LinkedListNode <EarPoint> a = poly.Previous(ele);
            LinkedListNode <EarPoint> b = ele;
            LinkedListNode <EarPoint> c = poly.Next(ele);

            return(GeoPolygonUtils.IsConvex(a.Value.mPoint, b.Value.mPoint, c.Value.mPoint));
        }
 private static bool IsEdgeRemovable(List <Vector2> vertes, HalfEdge edge)
 {
     if (edge.mPartner == null)
     {
         return(false);
     }
     return(GeoPolygonUtils.IsConvex(vertes[edge.mIndex], vertes[edge.mPartner.mNext.mNext.mIndex], vertes[edge.mNext.mNext.mIndex]) &&
            GeoPolygonUtils.IsConvex(vertes[edge.mPartner.mIndex], vertes[edge.mNext.mNext.mIndex], vertes[edge.mPartner.mNext.mNext.mIndex]));
 }
        private static void UpdateEdge(HalfEdge edgeToRemove, KeyedPriorityQueue <int, HalfEdge, float> priorityQueue, HashSet <EdgeID> deletedEdgeSet, List <Vector2> pointList)
        {
            HalfEdge left   = GetUndeletedLeft(edgeToRemove, deletedEdgeSet);
            HalfEdge right  = GetUndeletedRight(edgeToRemove, deletedEdgeSet);
            HalfEdge reLeft = RepresentActive(left);

            if (priorityQueue.Contain(reLeft.mKey))
            {
                // Check if this is still removable
                HalfEdge leftOfLeft = GetUndeletedLeft(left.mPartner, deletedEdgeSet);
                if ((leftOfLeft.mPartner != null && (leftOfLeft.mPartner.mKey == right.mKey || leftOfLeft.mPartner.mKey == edgeToRemove.mKey)) ||
                    !GeoPolygonUtils.IsConvex(pointList[edgeToRemove.mIndex], pointList[right.mNext.mIndex], pointList[leftOfLeft.mIndex]))
                {
                    priorityQueue.Remove(reLeft.mKey);
                }
                else
                {
                    // Need to update the priority
                    float pri = GetSmallestAdjacentAngleOnEdge(left, deletedEdgeSet, pointList);
                    priorityQueue.Remove(reLeft.mKey);
                    priorityQueue.Enqueue(reLeft.mKey, reLeft, pri);
                }
            }
            HalfEdge reRight = RepresentActive(right);

            if (priorityQueue.Contain(reRight.mKey))
            {
                HalfEdge rightOfRight = GetUndeletedRight(right, deletedEdgeSet);
                if ((rightOfRight.mPartner != null && (rightOfRight.mPartner.mKey == left.mKey || rightOfRight.mKey == edgeToRemove.mKey)) ||
                    !GeoPolygonUtils.IsConvex(pointList[edgeToRemove.mIndex], pointList[rightOfRight.mNext.mIndex], pointList[left.mIndex]))
                {
                    priorityQueue.Remove(reRight.mKey);
                }
                else
                {
                    priorityQueue.Remove(reRight.mKey);
                    priorityQueue.Enqueue(reRight.mKey, reRight, GetSmallestAdjacentAngleOnEdge(right, deletedEdgeSet, pointList));
                }
            }
        }