// Polygon Slice - TODO: Return No Polygon if it's eaten by polygon slice static public Slice2D PolygonSlice(Polygon2D polygon, Polygon2D slicePolygon) { List <Polygon2D> holes = polygon.holesList; polygon = new Polygon2D(new List <Vector2D>(polygon.pointsList)); polygon.holesList = holes; slicePolygon = new Polygon2D(new List <Vector2D>(slicePolygon.pointsList)); Slice2D result = Slice2D.Create(null, polygon); Slicer2D.SliceType tempSliceType = Slicer2D.complexSliceType; Slicer2D.complexSliceType = Slicer2D.SliceType.SliceHole; slicePolygon.Normalize(); polygon.Normalize(); // Eat a polygon completely // Complex Slicer does not register slice in this case if (slicePolygon.PolyInPoly(polygon) == true) { result.AddPolygon(polygon); return(result); } // Cut a hole inside (how does this work if it collides with other hole?) if (polygon.PolyInPoly(slicePolygon) == true) { polygon.AddHole(slicePolygon); result.AddPolygon(polygon); Math2D.Distance distance = Math2D.Distance.PolygonToPolygon(polygon, slicePolygon); if (distance != null && distance.value < precision) { return(SlicePolygonFromEdge(polygon, slicePolygon)); } return(result); } // Act as Regular Slice Vector2D startPoint = null; foreach (Vector2D id in slicePolygon.pointsList) { if (polygon.PointInPoly(id) == false) { startPoint = id; break; } } if (startPoint == null) { if (Math2D.PolyIntersectPoly(polygon, slicePolygon)) { return(SlicePolygonFromEdge(polygon, slicePolygon)); } if (Slicer2D.Debug.enabled) { Debug.LogWarning("Starting Point Error In PolygonSlice"); } return(result); } slicePolygon.pointsList = Vector2DList.GetListStartingPoint(slicePolygon.pointsList, startPoint); /* * List<Vector2D> s = new List<Vector2D> (); * foreach (Pair2D pair in Pair2D.GetList(polygonSlice.pointsList, false)) { * List<Vector2D> stackList = polygon.GetListSliceIntersectPoly(pair); * stackList = Vector2DList.GetListSortedToPoint (stackList, pair.A); * Vector2D old = pair.A; * s.Add (old); * * foreach (Vector2D id in stackList) { * s.Add (new Vector2D((old.GetX() + id.GetX()) / 2, (old.GetY() + id.GetY()) / 2)); * old = id; * } * } * * polygonSlice.pointsList = s; */ slicePolygon.AddPoint(startPoint); // Not Necessary if (polygon.SliceIntersectPoly(slicePolygon.pointsList) == false) { return(result); } // Slice More Times? result = ComplexSlicer.Slice(polygon, new List <Vector2D> (slicePolygon.pointsList)); if (result.GetPolygons().Count < 1) { if (Slicer2D.Debug.enabled) { Debug.LogWarning("Slicer2D: Returns Empty Polygon Slice"); } } Slicer2D.complexSliceType = tempSliceType; return(result); }
// Polygon Slice - TODO: Return No Polygon if it's eaten by polygon slice static public Slice2D Slice(Polygon2D polygon, Polygon2D polygonSlice) { Slice2D result = Slice2D.Create(polygon); Slicer2D.SliceType tempSliceType = Slicer2D.complexSliceType; Slicer2D.complexSliceType = Slicer2D.SliceType.SliceHole; polygonSlice.Normalize(); polygon.Normalize(); // Eat a polygon completely // Complex Slicer does not register slice in this case if (polygonSlice.PolyInPoly(polygon) == true) { result.AddPolygon(polygon); return(result); } if (polygon.PolyInPoly(polygonSlice) == true) { polygon.AddHole(polygonSlice); result.AddPolygon(polygon); return(result); } // Act as Regular Slice Vector2D startPoint = null; foreach (Vector2D id in polygonSlice.pointsList) { if (polygon.PointInPoly(id) == false) { startPoint = id; break; } } if (startPoint == null) { if (Slicer2D.Debug.enabled) { Debug.LogWarning("Starting Point Error In PolygonSlice"); } return(result); } polygonSlice.pointsList = Vector2DList.GetListStartingPoint(polygonSlice.pointsList, startPoint); /* * List<Vector2D> s = new List<Vector2D> (); * foreach (Pair2D pair in Pair2D.GetList(polygonSlice.pointsList, false)) { * List<Vector2D> stackList = polygon.GetListSliceIntersectPoly(pair); * stackList = Vector2DList.GetListSortedToPoint (stackList, pair.A); * Vector2D old = pair.A; * s.Add (old); * * foreach (Vector2D id in stackList) { * s.Add (new Vector2D((old.GetX() + id.GetX()) / 2, (old.GetY() + id.GetY()) / 2)); * old = id; * } * } * * polygonSlice.pointsList = s; */ polygonSlice.AddPoint(startPoint); // Not Necessary if (polygon.SliceIntersectPoly(polygonSlice.pointsList) == false) { return(result); } // Slice More Times? result = ComplexSlicer.Slice(polygon, new List <Vector2D> (polygonSlice.pointsList)); if (result.polygons.Count < 1) { if (Slicer2D.Debug.enabled) { Debug.LogWarning("Slicer2D: Returns Empty Polygon Slice"); } } Slicer2D.complexSliceType = tempSliceType; return(result); }
// Polygon Slice - TODO: Return No Polygon if it's eaten by polygon slice static public Slice2D Slice(Polygon polygon, Polygon polygonSlice) { Slice2D result = Slice2D.Create(); Slicer2D.SliceType tempSliceType = Slicer2D.complexSliceType; Slicer2D.complexSliceType = Slicer2D.SliceType.SliceHole; polygonSlice.Normalize(); polygon.Normalize(); // Eat a polygon completely // Complex Slicer does not register slice in this case if (polygonSlice.PolyInPoly(polygon) == true) { result.AddPolygon(polygon); return(result); } if (polygon.PolyInPoly(polygonSlice) == true) { polygon.AddHole(polygonSlice); result.AddPolygon(polygon); return(result); } // Act as Regular Slice Vector2f startPoint = null; foreach (Vector2f id in polygonSlice.pointsList) { if (polygon.PointInPoly(id) == false) { startPoint = id; break; } } if (startPoint == null) { Debug.LogError("Slicer2D: Starting Point Error In PolygonSlice"); return(result); } polygonSlice.pointsList = VectorList2f.GetListStartingPoint(polygonSlice.pointsList, startPoint); polygonSlice.AddPoint(startPoint); //List<Vector2f> s = new List<Vector2f> (); //foreach (Pair2f pair in Pair2f.GetList(polygonSlice.pointsList, false)) { // List<Vector2f> stackList = polygon.GetListSliceIntersectPoly(pair); // stackList = VectorList2f.GetListSortedToPoint (stackList, pair.A); // s.Add (pair.A); //foreach (Vector2f id in stackList) // s.Add (id); //} //polygonSlice.pointsList = s; // Not necessary if (polygon.SliceIntersectPoly(polygonSlice.pointsList) == false) { return(result); } result = ComplexSlicer.Slice(polygon, new List <Vector2f> (polygonSlice.pointsList)); //if (result.polygons.Count < 1) //debug用 消しても大丈夫そう // Debug.LogError ("Slicer2D: Returns Empty Polygon Slice"); Slicer2D.complexSliceType = tempSliceType; return(result); }