private bool SearchForOutstandingVertex(Vertices hullArea, out TSVector2 outstanding) { TSVector2 tSVector = TSVector2.zero; bool result = false; bool flag = hullArea.Count > 2; if (flag) { int num = hullArea.Count - 1; TSVector2 tSVector2 = hullArea[0]; TSVector2 tSVector3 = hullArea[num]; for (int i = 1; i < num; i++) { TSVector2 tSVector4 = hullArea[i]; bool flag2 = LineTools.DistanceBetweenPointAndLineSegment(ref tSVector4, ref tSVector2, ref tSVector3) >= this._hullTolerance; if (flag2) { tSVector = hullArea[i]; result = true; break; } } } outstanding = tSVector; return(result); }
private bool DistanceToHullAcceptable(Vertices polygon, TSVector2 point, bool higherDetail) { bool flag = polygon == null; if (flag) { throw new ArgumentNullException("polygon", "'polygon' can't be null."); } bool flag2 = polygon.Count < 3; if (flag2) { throw new ArgumentException("'polygon.Count' can't be less then 3."); } TSVector2 tSVector = polygon[polygon.Count - 1]; bool result; if (higherDetail) { for (int i = 0; i < polygon.Count; i++) { TSVector2 value = polygon[i]; bool flag3 = LineTools.DistanceBetweenPointAndLineSegment(ref point, ref value, ref tSVector) <= this._hullTolerance || TSVector2.Distance(point, value) <= this._hullTolerance; if (flag3) { result = false; return(result); } tSVector = polygon[i]; } result = true; } else { for (int j = 0; j < polygon.Count; j++) { TSVector2 value = polygon[j]; bool flag4 = LineTools.DistanceBetweenPointAndLineSegment(ref point, ref value, ref tSVector) <= this._hullTolerance; if (flag4) { result = false; return(result); } tSVector = polygon[j]; } result = true; } return(result); }
private static void SimplifySection(Vertices vertices, int i, int j, bool[] usePoint, FP distanceTolerance) { if ((i + 1) == j) { return; } TSVector2 a = vertices[i]; TSVector2 b = vertices[j]; FP maxDistance = -1.0; int maxIndex = i; for (int k = i + 1; k < j; k++) { TSVector2 point = vertices[k]; FP distance = LineTools.DistanceBetweenPointAndLineSegment(ref point, ref a, ref b); if (distance > maxDistance) { maxDistance = distance; maxIndex = k; } } if (maxDistance <= distanceTolerance) { for (int k = i + 1; k < j; k++) { usePoint[k] = false; } } else { SimplifySection(vertices, i, maxIndex, usePoint, distanceTolerance); SimplifySection(vertices, maxIndex, j, usePoint, distanceTolerance); } }
private static void SimplifySection(Vertices vertices, int i, int j, bool[] usePoint, FP distanceTolerance) { bool flag = i + 1 == j; if (!flag) { TSVector2 tSVector = vertices[i]; TSVector2 tSVector2 = vertices[j]; FP fP = -1.0; int num = i; for (int k = i + 1; k < j; k++) { TSVector2 tSVector3 = vertices[k]; FP fP2 = LineTools.DistanceBetweenPointAndLineSegment(ref tSVector3, ref tSVector, ref tSVector2); bool flag2 = fP2 > fP; if (flag2) { fP = fP2; num = k; } } bool flag3 = fP <= distanceTolerance; if (flag3) { for (int l = i + 1; l < j; l++) { usePoint[l] = false; } } else { SimplifyTools.SimplifySection(vertices, i, num, usePoint, distanceTolerance); SimplifyTools.SimplifySection(vertices, num, j, usePoint, distanceTolerance); } } }
private bool SplitPolygonEdge(Vertices polygon, TSVector2 coordInsideThePolygon, out int vertex1Index, out int vertex2Index) { int num = 0; int index = 0; bool flag = false; FP y = FP.MaxValue; bool flag2 = false; TSVector2 zero = TSVector2.zero; List <FP> list = this.SearchCrossingEdges(polygon, (int)((long)coordInsideThePolygon.y)); vertex1Index = 0; vertex2Index = 0; zero.y = coordInsideThePolygon.y; bool flag3 = list != null && list.Count > 1 && list.Count % 2 == 0; bool result; if (flag3) { for (int i = 0; i < list.Count; i++) { bool flag4 = list[i] < coordInsideThePolygon.x; if (flag4) { FP fP = coordInsideThePolygon.x - list[i]; bool flag5 = fP < y; if (flag5) { y = fP; zero.x = list[i]; flag2 = true; } } } bool flag6 = flag2; if (flag6) { y = FP.MaxValue; int num2 = polygon.Count - 1; for (int j = 0; j < polygon.Count; j++) { TSVector2 tSVector = polygon[j]; TSVector2 tSVector2 = polygon[num2]; FP fP = LineTools.DistanceBetweenPointAndLineSegment(ref zero, ref tSVector, ref tSVector2); bool flag7 = fP < y; if (flag7) { y = fP; num = j; index = num2; flag = true; } num2 = j; } bool flag8 = flag; if (flag8) { TSVector2 value = polygon[index] - polygon[num]; value.Normalize(); TSVector2 value2 = polygon[num]; FP fP = TSVector2.Distance(value2, zero); vertex1Index = num; vertex2Index = num + 1; polygon.Insert(num, fP * value + polygon[vertex1Index]); polygon.Insert(num, fP * value + polygon[vertex2Index]); result = true; return(result); } } } result = false; return(result); }