MCPcopy Create free account
hub / github.com/AngusJohnson/Clipper2 / SimplifyPath

Method SimplifyPath

CSharp/Clipper2Lib/Clipper.cs:939–1003  ·  view source on GitHub ↗
(Path64 path,
      double epsilon, bool isClosedPath = true)

Source from the content-addressed store, hash-verified

937 }
938
939 public static Path64 SimplifyPath(Path64 path,
940 double epsilon, bool isClosedPath = true)
941 {
942 int len = path.Count, high = len - 1;
943 double epsSqr = Sqr(epsilon);
944 if (len < 4) return path;
945
946 bool[] flags = new bool[len];
947 double[] dsq = new double[len];
948 int curr = 0;
949
950 if (isClosedPath)
951 {
952 dsq[0] = PerpendicDistFromLineSqrd(path[0], path[high], path[1]);
953 dsq[high] = PerpendicDistFromLineSqrd(path[high], path[0], path[high - 1]);
954 }
955 else
956 {
957 dsq[0] = double.MaxValue;
958 dsq[high] = double.MaxValue;
959 }
960
961 for (int i = 1; i < high; ++i)
962 dsq[i] = PerpendicDistFromLineSqrd(path[i], path[i - 1], path[i + 1]);
963
964 for (; ; )
965 {
966 if (dsq[curr] > epsSqr)
967 {
968 int start = curr;
969 do
970 {
971 curr = GetNext(curr, high, ref flags);
972 } while (curr != start && dsq[curr] > epsSqr);
973 if (curr == start) break;
974 }
975
976 int prev = GetPrior(curr, high, ref flags);
977 int next = GetNext(curr, high, ref flags);
978 if (next == prev) break;
979
980 int prior2;
981 if (dsq[next] < dsq[curr])
982 {
983 prior2 = prev;
984 prev = curr;
985 curr = next;
986 next = GetNext(next, high, ref flags);
987 }
988 else
989 prior2 = GetPrior(prev, high, ref flags);
990
991 flags[curr] = true;
992 curr = next;
993 next = GetNext(next, high, ref flags);
994 if (isClosedPath || ((curr != high) && (curr != 0)))
995 dsq[curr] = PerpendicDistFromLineSqrd(path[curr], path[prev], path[next]);
996 if (isClosedPath || ((prev != 0) && (prev != high)))

Callers

nothing calls this directly

Calls 5

SqrFunction · 0.85
GetNextFunction · 0.85
GetPriorFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected