|
| 1 | +// The installed Manifold wrapper: booleans of solids and their volumes, a |
| 2 | +// mesh in and out, the same input giving the same mesh, an outline extruded |
| 3 | +// and sliced, linalg's operators, the adapted constants. |
| 4 | +import std; |
| 5 | +import mcpplibs.mwrap.manifold; |
| 6 | + |
| 7 | +using manifold::Manifold; |
| 8 | +using manifold::vec3; |
| 9 | + |
| 10 | +namespace { |
| 11 | + |
| 12 | +bool near(double one, double other, double within = 1e-9) { return std::abs(one - other) <= within; } |
| 13 | + |
| 14 | +} // namespace |
| 15 | + |
| 16 | +int main() { |
| 17 | + const Manifold one = Manifold::Cube(vec3(2.0)); |
| 18 | + const Manifold other = one.Translate(vec3(1.0, 0.0, 0.0)); |
| 19 | + if (one.NumVert() != 8 || one.NumTri() != 12 || !near(one.Volume(), 8.0)) return 1; |
| 20 | + if (!near((one + other).Volume(), 12.0) || !near((one - other).Volume(), 4.0) || !near((one ^ other).Volume(), 4.0)) return 2; |
| 21 | + if (!near(one.Boolean(other, manifold::OpType::Intersect).Volume(), 4.0)) return 3; |
| 22 | + |
| 23 | + // A cube with a round hole through it has a handle. |
| 24 | + const Manifold drilled = Manifold::Cube(vec3(2.0), true) - Manifold::Cylinder(4.0, 0.5, 0.5, 32, true); |
| 25 | + if (drilled.Status() != Manifold::Error::NoError || drilled.Genus() != 1 || !(drilled.Volume() < 8.0)) return 4; |
| 26 | + |
| 27 | + // The same input, the same mesh. |
| 28 | + const auto made = [] { return (Manifold::Sphere(1.0, 24) - Manifold::Cube(vec3(1.0))).GetMeshGL(); }; |
| 29 | + const manifold::MeshGL first = made(), second = made(); |
| 30 | + if (first.vertProperties.empty() || first.vertProperties != second.vertProperties || first.triVerts != second.triVerts) return 5; |
| 31 | + |
| 32 | + // A tetrahedron in, a solid out; one triangle short is refused with its reason. |
| 33 | + manifold::MeshGL mesh; |
| 34 | + mesh.numProp = 3; |
| 35 | + mesh.vertProperties = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}; |
| 36 | + mesh.triVerts = {0, 2, 1, 0, 1, 3, 1, 2, 3, 0, 3, 2}; |
| 37 | + if (!near(Manifold(mesh).Volume(), 1.0 / 6.0, 1e-12)) return 6; |
| 38 | + mesh.triVerts.resize(9); |
| 39 | + if (Manifold(mesh).Status() != Manifold::Error::NotManifold) return 7; |
| 40 | + |
| 41 | + // An outline raised and cut again. |
| 42 | + const manifold::Polygons square{{{-1, -1}, {1, -1}, {1, 1}, {-1, 1}}}; |
| 43 | + const Manifold raised = Manifold::Extrude(square, 3.0); |
| 44 | + double area = 0; |
| 45 | + for (const manifold::SimplePolygon& loop : raised.Slice(1.5)) |
| 46 | + for (std::size_t at = 0; at < loop.size(); ++at) area += linalg::cross(loop[at], loop[(at + 1) % loop.size()]) / 2; |
| 47 | + if (!near(raised.Volume(), 12.0) || !near(area, 4.0)) return 8; |
| 48 | + |
| 49 | + // linalg's operators and the constants of internal linkage, adapted. |
| 50 | + const vec3 along(1.0, 2.0, 2.0); |
| 51 | + if (linalg::length(along) != 3.0 || along * 2.0 - along != along) return 9; |
| 52 | + if (manifold::degrees(mcpplibs::mwrap::manifold::kPi) != 180.0 || mcpplibs::mwrap::manifold::DEFAULT_SEGMENTS != 0) return 10; |
| 53 | + |
| 54 | + std::println("Manifold 3.5.5 through import mcpplibs.mwrap.manifold: a drilled cube of volume {:.4f} and genus {}, {} triangles the same twice", drilled.Volume(), drilled.Genus(), |
| 55 | + first.NumTri()); |
| 56 | + return 0; |
| 57 | +} |
0 commit comments