|
| 1 | +Carry-patch: add CLIPPER2_NO_IOSTREAM macro guards to Clipper2's |
| 2 | +public headers so manifold can build Clipper2 without iostream when |
| 3 | +MANIFOLD_NO_IOSTREAM is set (e.g., for wasm32-unknown-unknown |
| 4 | +consumers via the wasm-cxx-shim integration). |
| 5 | + |
| 6 | +Tracks AngusJohnson/Clipper2#1094 — once that lands and manifold's |
| 7 | +Clipper2 SHA pin moves past it, this patch drops. |
| 8 | + |
| 9 | +Generated against Clipper2 SHA 46f639177fe418f9689e8ddb74f08a870c71f5b4 |
| 10 | +(the SHA manifoldDeps.cmake currently pins). The headers at this SHA |
| 11 | +are byte-identical to upstream main, so the patch tracks #1094's diff |
| 12 | +exactly. |
| 13 | + |
| 14 | +Apply with: git apply -p1 0001-clipper2-no-iostream.patch |
| 15 | + |
| 16 | +diff --git a/CPP/Clipper2Lib/include/clipper2/clipper.core.h b/CPP/Clipper2Lib/include/clipper2/clipper.core.h |
| 17 | +index 99a5205..d3af0a0 100644 |
| 18 | +--- a/CPP/Clipper2Lib/include/clipper2/clipper.core.h |
| 19 | ++++ b/CPP/Clipper2Lib/include/clipper2/clipper.core.h |
| 20 | +@@ -14,7 +14,9 @@ |
| 21 | + #include <cstdint> |
| 22 | + #include <vector> |
| 23 | + #include <string> |
| 24 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 25 | + #include <iostream> |
| 26 | ++#endif |
| 27 | + #include <algorithm> |
| 28 | + #include <numeric> |
| 29 | + #include <cmath> |
| 30 | +@@ -166,11 +168,13 @@ namespace Clipper2Lib |
| 31 | + |
| 32 | + void SetZ(const z_type z_value) { z = z_value; } |
| 33 | + |
| 34 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 35 | + friend std::ostream& operator<<(std::ostream& os, const Point& point) |
| 36 | + { |
| 37 | + os << point.x << "," << point.y << "," << point.z; |
| 38 | + return os; |
| 39 | + } |
| 40 | ++#endif |
| 41 | + |
| 42 | + #else |
| 43 | + |
| 44 | +@@ -203,11 +207,13 @@ namespace Clipper2Lib |
| 45 | + return Point(x * scale, y * scale); |
| 46 | + } |
| 47 | + |
| 48 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 49 | + friend std::ostream& operator<<(std::ostream& os, const Point& point) |
| 50 | + { |
| 51 | + os << point.x << "," << point.y; |
| 52 | + return os; |
| 53 | + } |
| 54 | ++#endif |
| 55 | + #endif |
| 56 | + |
| 57 | + friend bool operator==(const Point& a, const Point& b) |
| 58 | +@@ -396,10 +402,12 @@ namespace Clipper2Lib |
| 59 | + return result; |
| 60 | + } |
| 61 | + |
| 62 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 63 | + friend std::ostream& operator<<(std::ostream& os, const Rect<T>& rect) { |
| 64 | + os << "(" << rect.left << "," << rect.top << "," << rect.right << "," << rect.bottom << ") "; |
| 65 | + return os; |
| 66 | + } |
| 67 | ++#endif |
| 68 | + }; |
| 69 | + |
| 70 | + template <typename T1, typename T2> |
| 71 | +@@ -498,6 +506,7 @@ namespace Clipper2Lib |
| 72 | + return Rect<T>(xmin, ymin, xmax, ymax); |
| 73 | + } |
| 74 | + |
| 75 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 76 | + template <typename T> |
| 77 | + std::ostream& operator << (std::ostream& outstream, const Path<T>& path) |
| 78 | + { |
| 79 | +@@ -518,6 +527,7 @@ namespace Clipper2Lib |
| 80 | + outstream << p; |
| 81 | + return outstream; |
| 82 | + } |
| 83 | ++#endif |
| 84 | + |
| 85 | + |
| 86 | + template <typename T1, typename T2> |
| 87 | +diff --git a/CPP/Clipper2Lib/include/clipper2/clipper.h b/CPP/Clipper2Lib/include/clipper2/clipper.h |
| 88 | +index fe1e299..deb1f7b 100644 |
| 89 | +--- a/CPP/Clipper2Lib/include/clipper2/clipper.h |
| 90 | ++++ b/CPP/Clipper2Lib/include/clipper2/clipper.h |
| 91 | +@@ -309,6 +309,7 @@ namespace Clipper2Lib { |
| 92 | + return true; |
| 93 | + } |
| 94 | + |
| 95 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 96 | + static void OutlinePolyPath(std::ostream& os, |
| 97 | + size_t idx, bool isHole, size_t count, const std::string& preamble) |
| 98 | + { |
| 99 | +@@ -338,6 +339,7 @@ namespace Clipper2Lib { |
| 100 | + if (pp.Child(i)->Count()) |
| 101 | + details::OutlinePolyPathD(os, *pp.Child(i), i, preamble + " "); |
| 102 | + } |
| 103 | ++#endif |
| 104 | + |
| 105 | + template<typename T, typename U> |
| 106 | + inline constexpr void MakePathGeneric(const T an_array, |
| 107 | +@@ -377,6 +379,7 @@ namespace Clipper2Lib { |
| 108 | + |
| 109 | + } // end details namespace |
| 110 | + |
| 111 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 112 | + inline std::ostream& operator<< (std::ostream& os, const PolyTree64& pp) |
| 113 | + { |
| 114 | + std::string plural = (pp.Count() == 1) ? " polygon." : " polygons."; |
| 115 | +@@ -399,6 +402,7 @@ namespace Clipper2Lib { |
| 116 | + if (!pp.Level()) os << std::endl; |
| 117 | + return os; |
| 118 | + } |
| 119 | ++#endif |
| 120 | + |
| 121 | + inline Paths64 PolyTreeToPaths64(const PolyTree64& polytree) |
| 122 | + { |
0 commit comments