private static List <Vector2> ExpandPolygon(List <Vector2> original, float length = 1.0f) { List <Vector2> tempOrigin = new List <Vector2>(); tempOrigin.AddRange(original); if (GeoPolygonUtils.CalcualetArea(tempOrigin) < 0) { tempOrigin.Reverse(); } List <Vector2> result = new List <Vector2>(); for (int i = 0; i < tempOrigin.Count; ++i) { int j = i + 1; if (j == tempOrigin.Count) { j = 0; } int k = i - 1; if (k == -1) { k = tempOrigin.Count - 1; } Vector2 vk = tempOrigin[k] - tempOrigin[i]; Vector2 vj = tempOrigin[j] - tempOrigin[i]; Vector2 dir = vk.normalized + vj.normalized; dir.Normalize(); if (GeoPolygonUtils.IsConvexAngle(tempOrigin[k], tempOrigin[i], dir + tempOrigin[i])) { dir = -dir; } result.Add(tempOrigin[i] + dir * length); } return(result); }
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.IsConvexAngle(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.IsConvexAngle(vertes[edge.mIndex], vertes[edge.mPartner.mNext.mNext.mIndex], vertes[edge.mNext.mNext.mIndex]) && GeoPolygonUtils.IsConvexAngle(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.IsConvexAngle(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.IsConvexAngle(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)); } } }
private void AddPoint(GeoPointsArray2 polygon2, Vector2 p) { int cnt = polygon2.Count; List <bool> convexMask = new List <bool>(); for (int i = 0; i < cnt; ++i) { int j = i + 1; if (j == cnt) { j = 0; } convexMask.Add(GeoPolygonUtils.IsConvexAngle(polygon2[i], polygon2[j], p)); } int start = -1; int end = -1; for (int i = 0; i < cnt; i++) { int j = i + 1; if (j == cnt) { j = 0; } if (start == -1 && convexMask[i] == false && convexMask[j] == true) { start = j; } if (end == -1 && convexMask[i] == true && convexMask[j] == false) { end = j; } if (start != -1 && end != -1) { break; } } if (start != -1 && end != -1) { GeoPointsArray2 other = new GeoPointsArray2(); if (start <= end) { for (int i = start; i <= end; ++i) { other.Add(polygon2[i]); } } else { for (int i = start; i < cnt; ++i) { other.Add(polygon2[i]); } for (int i = 0; i <= end; ++i) { other.Add(polygon2[i]); } } other.Add(p); polygon2.Clear(); polygon2.mPointArray.AddRange(other.mPointArray); } }
private bool IsConvex(int i, int j, int k) { return(GeoPolygonUtils.IsConvexAngle(mPoints[i], mPoints[j], mPoints[k])); }