FeatureBoardby Lewis Valentine

Watertight Is a Claim You Have to Keep

A solid is watertight when its surface closes. Mass properties, booleans, STL export and FE meshing all depend on that being true. Here are four separate ways NativeCAD lost it in three weeks, and why the hardest one never showed up as a failed flag.

"Watertight" is one word in the NativeCAD pitch and a standing obligation in the code. A solid is watertight when its surface closes: no gaps, no holes, every edge shared by exactly two faces. Downstream, almost everything depends on it. Mass properties, boolean operations, STL export for printing, and finite-element meshing all assume the boundary actually bounds something.

Over the past three weeks four separate bugs took it away, and each one took it away differently. Sorting them is more useful than listing them, because only one of the four was a case of the geometry being wrong.

1. The geometry was fine. The mesh was too coarse.

Multi-section cubic lofts came back watertight: false every time. Two reproductions with 16-gon sections: non-monotonic radii gave 1.1% volume error against the analytic figure, and a plain monotonic taper gave its own smaller disagreement. Two-section ruled lofts were fine across about thirty uses. So it was specific to the cubic path, and not caused by the bulge or the section count.

The instinct is to suspect the surface maths. It was not the surface maths. Each rail corner was one multi-span B-spline surface, and the tessellator was giving that whole surface a flat five-row interior cap. The geometry was right and the triangles covering it were too few to close.

The fix decomposes each corner into single-span Bezier bands, so the tessellator sees several simple surfaces instead of one complicated one. Both repros went watertight, with volume error dropping from 1.1% to 0.09% and 0.01%. The NIST goldens didn't move, which is the check that matters when you touch tessellation.

Why this one blocked real work

The cubic loft is the only tool in the kernel that makes smooth, curved, tapering side walls. With it unusable, every lofted form falls back to two-section ruled lofts with straight walls. That single bug was the largest driver of blocky output in the whole product.

2. The geometry really was wrong

Mirroring was worse, and honest about it. A source solid of volume 1017.29 mirrored to negative 52.72. Not the negation of the source, just wrong. A second case, a revolved dome, gained 61% volume and grew from 17mm tall to 25.01mm.

That second symptom is the diagnostic one. The mirror plane had normal [0,1,0], so the Z extent must not change at all. It changed. That rules out a pure winding or orientation problem and says the geometry itself is being altered.

It turned out to be three faults wearing one costume:

  • Placement handedness. An AXIS2_PLACEMENT_3D carries an axis and a reference direction, with the third axis implied by their cross product. Mirroring the two stored directions independently negates that implied third axis. This is what moved the Z extent: it flipped which pole a spherical cap fanned from.
  • Self-loop edges. A full circle is one edge whose start and end are the same vertex. The same_sense flip that a reflection needs was being applied to those too, where it shouldn't be.
  • B-spline surfaces. They carry no placement to fix up, so they need an explicit u/v transpose to survive a determinant of −1.

All three had to land together. Fixing any one alone still leaves a broken mirror, which is the usual reason a bug like this survives a first attempt.

3. The solid was right, and everything downstream was wrong

This is the one I keep thinking about.

The per-operator robustness scorecard held the boolean operator at Hobby tier on three WRONG_VOLUME points, all on coplanar boxes at a 1µm separation, with relative errors between 2.5e-5 and 5e-5. It was the single grade blocker, and the gate was exiting non-zero on it.

The boolean was not at fault. Its analytic volume and the test generator's expectation agreed exactly. The problem sat one stage later: snapWeld's 2µm weld radius swallowed the 1µm slab entirely. The B-rep was correct. Mass properties, STL export and the viewer were all reading a mesh that had lost a layer.

The bit that should worry you

Through all of that, the body still reported watertight. It was watertight. A mesh can close perfectly around the wrong volume, so the flag stayed green while every number derived from the mesh was wrong.

The tempting fix is to shrink the weld radius. That trades this failure for a different one, since the radius exists to close real gaps and a smaller one reopens them. What shipped instead was an invariant, with the radius untouched: a weld on an already-closed mesh may not change its enclosed volume.

That holds because welding genuinely coincident duplicate vertices changes the enclosed volume by exactly zero. If a weld moves the volume, it has consumed something real, and it should be refused rather than tuned around. Boolean went from Hobby to Pro and the scorecard gate went green.

4. Nothing was wrong except the answer

The fourth wasn't geometry at all. Two tools could be asked about the same body and disagree: cad_body_topology reported watertight: false while cad_mass_properties reported true.

The reconciliation function short-circuited to false on any negative from the mesh scan, without ever consulting the topological check. So one tool answered from the mesh, the other from the B-rep, and nothing forced them to agree. It now defers to the topological check and falls back to the mesh verdict only if that throws, which makes the disagreement structurally impossible instead of merely unlikely.

No solid was ever malformed by this one. It was purely a reporting bug, and it cost real time, because a false negative on watertightness sends you hunting for a geometry defect that isn't there.

Four layers, one word

Stacked up, the four failures live at four different depths:

  1. Geometry — the surfaces are wrong (the mirror).
  2. Tessellation — the surfaces are right, the triangles don't close (the loft).
  3. Mesh post-processing — the triangles closed, then a later pass ate some (the weld).
  4. Reporting — everything is correct and the answer is still wrong (the reconciliation).

A user hitting any of these sees the same thing: a body that isn't watertight, or is watertight and lies about its volume. The symptom carries no information about which layer failed. That is why each fix here starts with locating the layer before touching anything, and why "the tessellation is too coarse" and "the surface maths is wrong" were worth an afternoon of separating.

All four now have regression tests pinned to measured numbers rather than to the shape of the error message. Claiming watertight output is easy. Keeping the claim true through every code path that can quietly break it is the actual work.


NativeCAD is a parametric B-rep kernel that runs in the browser: STEP AP242 in and out, real solid modeling, no server round-trip. You can try it here, or book a call if you want to talk through a geometry problem of your own.

← Previous Post
A Wrong Answer That Looked Right 98 Times