|
| 1 | +Carry-patch: add a CLIPPER2_NO_IOSTREAM build option (off by default) |
| 2 | +that strips iostream-using overloads from Clipper2's public headers, |
| 3 | +and propagate the macro through Clipper2's PUBLIC compile definitions |
| 4 | +so consumers see it. Lets manifold pass MANIFOLD_NO_IOSTREAM=ON |
| 5 | +through to the bundled Clipper2 (e.g., for wasm32-unknown-unknown |
| 6 | +consumers via the wasm-cxx-shim integration). |
| 7 | + |
| 8 | +Tracks AngusJohnson/Clipper2#1094 — once that lands and manifold's |
| 9 | +Clipper2 SHA pin moves past it, this patch drops. |
| 10 | + |
| 11 | +Generated against Clipper2 SHA 46f639177fe418f9689e8ddb74f08a870c71f5b4 |
| 12 | +(the SHA manifoldDeps.cmake currently pins). The headers at this SHA |
| 13 | +are byte-identical to upstream main, so the patch tracks #1094's diff |
| 14 | +exactly. |
| 15 | + |
| 16 | +Apply with: git apply -p1 0001-clipper2-no-iostream.patch |
| 17 | + |
| 18 | + |
| 19 | +diff --git a/CPP/CMakeLists.txt b/CPP/CMakeLists.txt |
| 20 | +index 7642e86..b327296 100644 |
| 21 | +--- a/CPP/CMakeLists.txt |
| 22 | ++++ b/CPP/CMakeLists.txt |
| 23 | +@@ -17,6 +17,7 @@ option(CLIPPER2_HI_PRECISION "Caution: enabling this will compromise performance |
| 24 | + option(CLIPPER2_UTILS "Build utilities" ON) |
| 25 | + option(CLIPPER2_EXAMPLES "Build examples" ON) |
| 26 | + option(CLIPPER2_TESTS "Build tests" ON) |
| 27 | ++option(CLIPPER2_NO_IOSTREAM "Disable iostream-using header overloads" OFF) |
| 28 | + option(USE_EXTERNAL_GTEST "Use system-wide installed GoogleTest" OFF) |
| 29 | + option(USE_EXTERNAL_GBENCHMARK "Use the googlebenchmark" OFF) |
| 30 | + option(BUILD_SHARED_LIBS "Build shared libs" OFF) |
| 31 | +@@ -69,6 +70,7 @@ if (NOT (CLIPPER2_USINGZ STREQUAL "ONLY")) |
| 32 | + Clipper2 PUBLIC |
| 33 | + CLIPPER2_MAX_DECIMAL_PRECISION=${CLIPPER2_MAX_DECIMAL_PRECISION} |
| 34 | + $<$<BOOL:${CLIPPER2_HI_PRECISION}>:CLIPPER2_HI_PRECISION> |
| 35 | ++ $<$<BOOL:${CLIPPER2_NO_IOSTREAM}>:CLIPPER2_NO_IOSTREAM> |
| 36 | + ) |
| 37 | + |
| 38 | + target_include_directories( |
| 39 | +@@ -95,6 +97,7 @@ if (NOT (CLIPPER2_USINGZ STREQUAL "OFF")) |
| 40 | + USINGZ |
| 41 | + CLIPPER2_MAX_DECIMAL_PRECISION=${CLIPPER2_MAX_DECIMAL_PRECISION} |
| 42 | + $<$<BOOL:${CLIPPER2_HI_PRECISION}>:CLIPPER2_HI_PRECISION> |
| 43 | ++ $<$<BOOL:${CLIPPER2_NO_IOSTREAM}>:CLIPPER2_NO_IOSTREAM> |
| 44 | + ) |
| 45 | + target_include_directories( |
| 46 | + Clipper2Z PUBLIC |
| 47 | +diff --git a/CPP/Clipper2Lib/include/clipper2/clipper.core.h b/CPP/Clipper2Lib/include/clipper2/clipper.core.h |
| 48 | +index 99a5205..d3af0a0 100644 |
| 49 | +--- a/CPP/Clipper2Lib/include/clipper2/clipper.core.h |
| 50 | ++++ b/CPP/Clipper2Lib/include/clipper2/clipper.core.h |
| 51 | +@@ -14,7 +14,9 @@ |
| 52 | + #include <cstdint> |
| 53 | + #include <vector> |
| 54 | + #include <string> |
| 55 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 56 | + #include <iostream> |
| 57 | ++#endif |
| 58 | + #include <algorithm> |
| 59 | + #include <numeric> |
| 60 | + #include <cmath> |
| 61 | +@@ -166,11 +168,13 @@ namespace Clipper2Lib |
| 62 | + |
| 63 | + void SetZ(const z_type z_value) { z = z_value; } |
| 64 | + |
| 65 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 66 | + friend std::ostream& operator<<(std::ostream& os, const Point& point) |
| 67 | + { |
| 68 | + os << point.x << "," << point.y << "," << point.z; |
| 69 | + return os; |
| 70 | + } |
| 71 | ++#endif |
| 72 | + |
| 73 | + #else |
| 74 | + |
| 75 | +@@ -203,11 +207,13 @@ namespace Clipper2Lib |
| 76 | + return Point(x * scale, y * scale); |
| 77 | + } |
| 78 | + |
| 79 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 80 | + friend std::ostream& operator<<(std::ostream& os, const Point& point) |
| 81 | + { |
| 82 | + os << point.x << "," << point.y; |
| 83 | + return os; |
| 84 | + } |
| 85 | ++#endif |
| 86 | + #endif |
| 87 | + |
| 88 | + friend bool operator==(const Point& a, const Point& b) |
| 89 | +@@ -396,10 +402,12 @@ namespace Clipper2Lib |
| 90 | + return result; |
| 91 | + } |
| 92 | + |
| 93 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 94 | + friend std::ostream& operator<<(std::ostream& os, const Rect<T>& rect) { |
| 95 | + os << "(" << rect.left << "," << rect.top << "," << rect.right << "," << rect.bottom << ") "; |
| 96 | + return os; |
| 97 | + } |
| 98 | ++#endif |
| 99 | + }; |
| 100 | + |
| 101 | + template <typename T1, typename T2> |
| 102 | +@@ -498,6 +506,7 @@ namespace Clipper2Lib |
| 103 | + return Rect<T>(xmin, ymin, xmax, ymax); |
| 104 | + } |
| 105 | + |
| 106 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 107 | + template <typename T> |
| 108 | + std::ostream& operator << (std::ostream& outstream, const Path<T>& path) |
| 109 | + { |
| 110 | +@@ -518,6 +527,7 @@ namespace Clipper2Lib |
| 111 | + outstream << p; |
| 112 | + return outstream; |
| 113 | + } |
| 114 | ++#endif |
| 115 | + |
| 116 | + |
| 117 | + template <typename T1, typename T2> |
| 118 | +diff --git a/CPP/Clipper2Lib/include/clipper2/clipper.h b/CPP/Clipper2Lib/include/clipper2/clipper.h |
| 119 | +index fe1e299..deb1f7b 100644 |
| 120 | +--- a/CPP/Clipper2Lib/include/clipper2/clipper.h |
| 121 | ++++ b/CPP/Clipper2Lib/include/clipper2/clipper.h |
| 122 | +@@ -309,6 +309,7 @@ namespace Clipper2Lib { |
| 123 | + return true; |
| 124 | + } |
| 125 | + |
| 126 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 127 | + static void OutlinePolyPath(std::ostream& os, |
| 128 | + size_t idx, bool isHole, size_t count, const std::string& preamble) |
| 129 | + { |
| 130 | +@@ -338,6 +339,7 @@ namespace Clipper2Lib { |
| 131 | + if (pp.Child(i)->Count()) |
| 132 | + details::OutlinePolyPathD(os, *pp.Child(i), i, preamble + " "); |
| 133 | + } |
| 134 | ++#endif |
| 135 | + |
| 136 | + template<typename T, typename U> |
| 137 | + inline constexpr void MakePathGeneric(const T an_array, |
| 138 | +@@ -377,6 +379,7 @@ namespace Clipper2Lib { |
| 139 | + |
| 140 | + } // end details namespace |
| 141 | + |
| 142 | ++#ifndef CLIPPER2_NO_IOSTREAM |
| 143 | + inline std::ostream& operator<< (std::ostream& os, const PolyTree64& pp) |
| 144 | + { |
| 145 | + std::string plural = (pp.Count() == 1) ? " polygon." : " polygons."; |
| 146 | +@@ -399,6 +402,7 @@ namespace Clipper2Lib { |
| 147 | + if (!pp.Level()) os << std::endl; |
| 148 | + return os; |
| 149 | + } |
| 150 | ++#endif |
| 151 | + |
| 152 | + inline Paths64 PolyTreeToPaths64(const PolyTree64& polytree) |
| 153 | + { |
0 commit comments