//Is a polygon One inside polygon Two? private static bool IsPolygonInsidePolygon(List <MyVector2> polyOne, List <MyVector2> polyTwo) { bool isInside = false; for (int i = 0; i < polyOne.Count; i++) { if (Intersections.PointPolygon(polyTwo, polyOne[i])) { //Is inside if at least one point is inside the polygon. We run this method after we have tested //if the polygons are intersecting isInside = true; break; } } return(isInside); }
//Mark entry exit points private static void MarkEntryExit(List <ClipVertex> poly, List <MyVector2> clipPolyVector) { //First see if the first vertex starts inside or outside (we can use the original list) bool isInside = Intersections.PointPolygon(clipPolyVector, poly[0].coordinate); //Debug.Log(isInside); ClipVertex currentVertex = poly[0]; ClipVertex firstVertex = currentVertex; int safety = 0; while (true) { if (currentVertex.isIntersection) { //If we were outside, this is an entry currentVertex.isEntry = isInside ? false : true; //Now we know we are either inside or outside isInside = !isInside; } currentVertex = currentVertex.next; //We have travelled around the entire polygon if (currentVertex.Equals(firstVertex)) { break; } safety += 1; if (safety > 100000) { Debug.Log("Endless loop in mark entry exit"); break; } } }