private static bool CanSee(int i, int j, Vertices vertices) { bool flag = BayazitDecomposer.Reflex(i, vertices); bool result; if (flag) { bool flag2 = BayazitDecomposer.LeftOn(BayazitDecomposer.At(i, vertices), BayazitDecomposer.At(i - 1, vertices), BayazitDecomposer.At(j, vertices)) && BayazitDecomposer.RightOn(BayazitDecomposer.At(i, vertices), BayazitDecomposer.At(i + 1, vertices), BayazitDecomposer.At(j, vertices)); if (flag2) { result = false; return(result); } } else { bool flag3 = BayazitDecomposer.RightOn(BayazitDecomposer.At(i, vertices), BayazitDecomposer.At(i + 1, vertices), BayazitDecomposer.At(j, vertices)) || BayazitDecomposer.LeftOn(BayazitDecomposer.At(i, vertices), BayazitDecomposer.At(i - 1, vertices), BayazitDecomposer.At(j, vertices)); if (flag3) { result = false; return(result); } } bool flag4 = BayazitDecomposer.Reflex(j, vertices); if (flag4) { bool flag5 = BayazitDecomposer.LeftOn(BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(j - 1, vertices), BayazitDecomposer.At(i, vertices)) && BayazitDecomposer.RightOn(BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(j + 1, vertices), BayazitDecomposer.At(i, vertices)); if (flag5) { result = false; return(result); } } else { bool flag6 = BayazitDecomposer.RightOn(BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(j + 1, vertices), BayazitDecomposer.At(i, vertices)) || BayazitDecomposer.LeftOn(BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(j - 1, vertices), BayazitDecomposer.At(i, vertices)); if (flag6) { result = false; return(result); } } for (int k = 0; k < vertices.Count; k++) { bool flag7 = (k + 1) % vertices.Count == i || k == i || (k + 1) % vertices.Count == j || k == j; if (!flag7) { TSVector2 tSVector; bool flag8 = LineTools.LineIntersect(BayazitDecomposer.At(i, vertices), BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(k, vertices), BayazitDecomposer.At(k + 1, vertices), out tSVector); if (flag8) { result = false; return(result); } } } result = true; return(result); }
private static Vertices Copy(int i, int j, Vertices vertices) { while (j < i) { j += vertices.Count; } Vertices vertices2 = new Vertices(j); while (i <= j) { vertices2.Add(BayazitDecomposer.At(i, vertices)); i++; } return(vertices2); }
// TS - public static List<Vertices> ConvexPartition(Vertices vertices, TriangulationAlgorithm algorithm, bool discardAndFixInvalid = true, FP tolerance = 0.001f) public static List <Vertices> ConvexPartition(Vertices vertices, TriangulationAlgorithm algorithm, bool discardAndFixInvalid, FP tolerance) { if (vertices.Count <= 3) { return new List <Vertices> { vertices } } ; List <Vertices> results; switch (algorithm) { case TriangulationAlgorithm.Earclip: if (Settings.SkipSanityChecks) { Debug.Assert(!vertices.IsCounterClockWise(), "The Earclip algorithm expects the polygon to be clockwise."); } else { if (vertices.IsCounterClockWise()) { Vertices temp = new Vertices(vertices); temp.Reverse(); results = EarclipDecomposer.ConvexPartition(temp, tolerance); } else { results = EarclipDecomposer.ConvexPartition(vertices, tolerance); } } break; case TriangulationAlgorithm.Bayazit: if (Settings.SkipSanityChecks) { Debug.Assert(vertices.IsCounterClockWise(), "The polygon is not counter clockwise. This is needed for Bayazit to work correctly."); } else { if (!vertices.IsCounterClockWise()) { Vertices temp = new Vertices(vertices); temp.Reverse(); results = BayazitDecomposer.ConvexPartition(temp); } else { results = BayazitDecomposer.ConvexPartition(vertices); } } break; case TriangulationAlgorithm.Flipcode: if (Settings.SkipSanityChecks) { Debug.Assert(vertices.IsCounterClockWise(), "The polygon is not counter clockwise. This is needed for Bayazit to work correctly."); } else { if (!vertices.IsCounterClockWise()) { Vertices temp = new Vertices(vertices); temp.Reverse(); results = FlipcodeDecomposer.ConvexPartition(temp); } else { results = FlipcodeDecomposer.ConvexPartition(vertices); } } break; case TriangulationAlgorithm.Seidel: results = SeidelDecomposer.ConvexPartition(vertices, tolerance); break; case TriangulationAlgorithm.SeidelTrapezoids: results = SeidelDecomposer.ConvexPartitionTrapezoid(vertices, tolerance); break; case TriangulationAlgorithm.Delauny: results = CDTDecomposer.ConvexPartition(vertices); break; default: throw new ArgumentOutOfRangeException("algorithm"); } if (discardAndFixInvalid) { for (int i = results.Count - 1; i >= 0; i--) { Vertices polygon = results[i]; if (!ValidatePolygon(polygon)) { results.RemoveAt(i); } } } return(results); }
public static List <Vertices> ConvexPartition(Vertices vertices, TriangulationAlgorithm algorithm, bool discardAndFixInvalid, FP tolerance) { bool flag = vertices.Count <= 3; List <Vertices> result; if (flag) { result = new List <Vertices> { vertices }; } else { List <Vertices> list; switch (algorithm) { case TriangulationAlgorithm.Earclip: { bool flag2 = vertices.IsCounterClockWise(); if (flag2) { Vertices vertices2 = new Vertices(vertices); vertices2.Reverse(); list = EarclipDecomposer.ConvexPartition(vertices2, tolerance); } else { list = EarclipDecomposer.ConvexPartition(vertices, tolerance); } break; } case TriangulationAlgorithm.Bayazit: { bool flag3 = !vertices.IsCounterClockWise(); if (flag3) { Vertices vertices3 = new Vertices(vertices); vertices3.Reverse(); list = BayazitDecomposer.ConvexPartition(vertices3); } else { list = BayazitDecomposer.ConvexPartition(vertices); } break; } case TriangulationAlgorithm.Flipcode: { bool flag4 = !vertices.IsCounterClockWise(); if (flag4) { Vertices vertices4 = new Vertices(vertices); vertices4.Reverse(); list = FlipcodeDecomposer.ConvexPartition(vertices4); } else { list = FlipcodeDecomposer.ConvexPartition(vertices); } break; } case TriangulationAlgorithm.Seidel: list = SeidelDecomposer.ConvexPartition(vertices, tolerance); break; case TriangulationAlgorithm.SeidelTrapezoids: list = SeidelDecomposer.ConvexPartitionTrapezoid(vertices, tolerance); break; case TriangulationAlgorithm.Delauny: list = CDTDecomposer.ConvexPartition(vertices); break; default: throw new ArgumentOutOfRangeException("algorithm"); } if (discardAndFixInvalid) { for (int i = list.Count - 1; i >= 0; i--) { Vertices polygon = list[i]; bool flag5 = !Triangulate.ValidatePolygon(polygon); if (flag5) { list.RemoveAt(i); } } } result = list; } return(result); }
public static List <Vertices> ConvexPartition(Vertices vertices) { Debug.Assert(vertices.Count > 3); Debug.Assert(vertices.IsCounterClockWise()); return(BayazitDecomposer.TriangulatePolygon(vertices)); }
private static bool Right(int i, Vertices vertices) { return(BayazitDecomposer.Right(BayazitDecomposer.At(i - 1, vertices), BayazitDecomposer.At(i, vertices), BayazitDecomposer.At(i + 1, vertices))); }
private static bool Reflex(int i, Vertices vertices) { return(BayazitDecomposer.Right(i, vertices)); }
private static List <Vertices> TriangulatePolygon(Vertices vertices) { List <Vertices> list = new List <Vertices>(); TSVector2 value = default(TSVector2); TSVector2 value2 = default(TSVector2); int num = 0; int i = 0; List <Vertices> result; for (int j = 0; j < vertices.Count; j++) { bool flag = BayazitDecomposer.Reflex(j, vertices); if (flag) { FP y2; FP y = y2 = FP.MaxValue; for (int k = 0; k < vertices.Count; k++) { bool flag2 = BayazitDecomposer.Left(BayazitDecomposer.At(j - 1, vertices), BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(k, vertices)) && BayazitDecomposer.RightOn(BayazitDecomposer.At(j - 1, vertices), BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(k - 1, vertices)); if (flag2) { TSVector2 tSVector = LineTools.LineIntersect(BayazitDecomposer.At(j - 1, vertices), BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(k, vertices), BayazitDecomposer.At(k - 1, vertices)); bool flag3 = BayazitDecomposer.Right(BayazitDecomposer.At(j + 1, vertices), BayazitDecomposer.At(j, vertices), tSVector); if (flag3) { FP fP = BayazitDecomposer.SquareDist(BayazitDecomposer.At(j, vertices), tSVector); bool flag4 = fP < y2; if (flag4) { y2 = fP; value = tSVector; num = k; } } } bool flag5 = BayazitDecomposer.Left(BayazitDecomposer.At(j + 1, vertices), BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(k + 1, vertices)) && BayazitDecomposer.RightOn(BayazitDecomposer.At(j + 1, vertices), BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(k, vertices)); if (flag5) { TSVector2 tSVector = LineTools.LineIntersect(BayazitDecomposer.At(j + 1, vertices), BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(k, vertices), BayazitDecomposer.At(k + 1, vertices)); bool flag6 = BayazitDecomposer.Left(BayazitDecomposer.At(j - 1, vertices), BayazitDecomposer.At(j, vertices), tSVector); if (flag6) { FP fP = BayazitDecomposer.SquareDist(BayazitDecomposer.At(j, vertices), tSVector); bool flag7 = fP < y; if (flag7) { y = fP; i = k; value2 = tSVector; } } } } bool flag8 = num == (i + 1) % vertices.Count; Vertices vertices2; Vertices vertices3; if (flag8) { TSVector2 item = (value + value2) / 2; vertices2 = BayazitDecomposer.Copy(j, i, vertices); vertices2.Add(item); vertices3 = BayazitDecomposer.Copy(num, j, vertices); vertices3.Add(item); } else { FP y3 = 0; FP value3 = num; while (i < num) { i += vertices.Count; } for (int l = num; l <= i; l++) { bool flag9 = BayazitDecomposer.CanSee(j, l, vertices); if (flag9) { FP fP2 = 1 / (BayazitDecomposer.SquareDist(BayazitDecomposer.At(j, vertices), BayazitDecomposer.At(l, vertices)) + 1); bool flag10 = BayazitDecomposer.Reflex(l, vertices); if (flag10) { bool flag11 = BayazitDecomposer.RightOn(BayazitDecomposer.At(l - 1, vertices), BayazitDecomposer.At(l, vertices), BayazitDecomposer.At(j, vertices)) && BayazitDecomposer.LeftOn(BayazitDecomposer.At(l + 1, vertices), BayazitDecomposer.At(l, vertices), BayazitDecomposer.At(j, vertices)); if (flag11) { fP2 += 3; } else { fP2 += 2; } } else { fP2 += 1; } bool flag12 = fP2 > y3; if (flag12) { value3 = l; y3 = fP2; } } } vertices2 = BayazitDecomposer.Copy(j, (int)((long)value3), vertices); vertices3 = BayazitDecomposer.Copy((int)((long)value3), j, vertices); } list.AddRange(BayazitDecomposer.TriangulatePolygon(vertices2)); list.AddRange(BayazitDecomposer.TriangulatePolygon(vertices3)); result = list; return(result); } } bool flag13 = vertices.Count > Settings.MaxPolygonVertices; if (flag13) { Vertices vertices2 = BayazitDecomposer.Copy(0, vertices.Count / 2, vertices); Vertices vertices3 = BayazitDecomposer.Copy(vertices.Count / 2, 0, vertices); list.AddRange(BayazitDecomposer.TriangulatePolygon(vertices2)); list.AddRange(BayazitDecomposer.TriangulatePolygon(vertices3)); } else { list.Add(vertices); } result = list; return(result); }