| 20 | public static class ClipperFileIO |
| 21 | { |
| 22 | public static Paths64 PathFromStr(string? s) |
| 23 | { |
| 24 | if (s == null) return new Paths64(); |
| 25 | Path64 p = new Path64(); |
| 26 | Paths64 pp = new Paths64(); |
| 27 | int len = s.Length, i = 0; |
| 28 | while (i < len) |
| 29 | { |
| 30 | while (s[i] < 33 && i < len) i++; |
| 31 | if (i >= len) break; |
| 32 | //get X ... |
| 33 | bool isNeg = s[i] == 45; |
| 34 | if (isNeg) i++; |
| 35 | if (i >= len || s[i] < 48 || s[i] > 57) break; |
| 36 | int j = i + 1; |
| 37 | while (j < len && s[j] > 47 && s[j] < 58) j++; |
| 38 | if (!long.TryParse(s.Substring(i, j - i), out long x)) break; |
| 39 | if (isNeg) x = -x; |
| 40 | //skip space or comma between X & Y ... |
| 41 | i = j; |
| 42 | while (i < len && (s[i] == 32 || s[i] == 44)) i++; |
| 43 | //get Y ... |
| 44 | if (i >= len) break; |
| 45 | isNeg = s[i] == 45; |
| 46 | if (isNeg) i++; |
| 47 | if (i >= len || s[i] < 48 || s[i] > 57) break; |
| 48 | j = i + 1; |
| 49 | while (j < len && s[j] > 47 && s[j] < 58) j++; |
| 50 | if (!long.TryParse(s.Substring(i,j-i), out long y)) break; |
| 51 | if (isNeg) y = -y; |
| 52 | p.Add(new Point64(x, y)); |
| 53 | //skip trailing space, comma ... |
| 54 | i = j; |
| 55 | int nlCnt = 0; |
| 56 | while (i < len && (s[i] < 33 || s[i] == 44)) |
| 57 | { |
| 58 | if (i >= len) break; |
| 59 | if (s[i] == 10) |
| 60 | { |
| 61 | nlCnt++; |
| 62 | if (nlCnt == 2) |
| 63 | { |
| 64 | if (p.Count > 0) pp.Add(p); |
| 65 | p = new Path64(); |
| 66 | } |
| 67 | } |
| 68 | i++; |
| 69 | } |
| 70 | } |
| 71 | if (p.Count > 0) pp.Add(p); |
| 72 | return pp; |
| 73 | } |
| 74 | //------------------------------------------------------------------------------ |
| 75 | |
| 76 | public static bool LoadTestNum(string filename, int num, |