C++ mesh bounds: why min() breaks negative coordinates
A mesh can pass a positive-coordinate test and still acquire a bounding box that reaches toward zero when every vertex moves into negative space. In our Qwen3.8-27B workday test, that was not a rendering problem. It was a C++ initialization error, accompanied by a parser that accepted invalid input too quietly.
This companion focuses on the repair and the checks behind it. The full episode also covers other programming and 3D tasks; a successful bounds fix should not be read as a claim that the model succeeded at everything.
https://www.youtube.com/watch?v=c3y4O8EerXo
The smallest value is not always the lowest value
An axis-aligned bounding box, or AABB, records the smallest and largest coordinate on each axis. The original tool initialized its minimum with max() and its maximum with min(). The names look symmetrical, but floating-point limits are not symmetrical in that way.
For the tested double representation, std::numeric_limits<double>::min() is a small positive normalized number. It is not the most negative finite number. The C++ working draft distinguishes this from lowest(), which supplies the lowest finite value. See the numeric limits definitions.
If the running maximum begins positive, comparing it with only negative coordinates never replaces it. The baseline log showed the maximum as 2.22507e-308 on all three axes for the negative-translation case.
The submitted patch made this targeted change:
// Bounds constructor: initialize each axis before accumulating points.
minimum.fill(std::numeric_limits<double>::max());
maximum.fill(std::numeric_limits<double>::lowest());
That repairs the initialization for finite coordinates. It does not, by itself, define what an empty mesh means or make malformed input safe to accept.
Fix the input contract, not just the visible symptom
The work order required invalid input to produce a nonzero exit code, a clear diagnostic, and no bounding box on standard output. Valid input had to keep its existing CLI and output format.
The original loop read triples directly from the input stream. That made two behaviors easy to overlook: a failed extraction could end the loop without turning the program into a failure, and whitespace-based extraction could assemble a point across separate incomplete lines.
The replacement processed one line at a time. It skipped blank lines, required three coordinates, rejected extra content, checked coordinates for finiteness, and tracked whether any points had been accepted. An empty or whitespace-only file became an error rather than a pair of initialization sentinels printed as geometry.
The ordering mattered. The program accumulated bounds internally, but printed them only after validating the input. A later malformed line therefore did not leave a partial, apparently successful result on stdout.
A compact regression set
The independent checks covered seven cases:
- A mesh translated entirely into negative coordinates.
- Valid input containing blank lines.
- Empty input.
- An incomplete point.
- Two incomplete lines that must not become two valid points.
- A nonfinite coordinate.
- Trailing junk after coordinates.
Before editing, only the valid-with-blank-lines case passed. After the patch, all seven passed. Separately, the agent's own suite reported 11 passing tests after compilation. Those are different suites, not an 18-point benchmark or 18 independent proofs of correctness.
For a small negative-coordinate regression, the submitted tests used these points:
-1 -6 -3
-2 -4 -4
-1 -4 -9
The expected two output lines were:
-2 -6 -9
-1 -4 -3
For malformed inputs, checking only the exit status is incomplete. Assert that stdout is empty and stderr contains a useful error too. Otherwise downstream tooling may accidentally consume a partial result.
What this says about using a coding agent
The useful unit of evidence was the sequence: reproduce the reported defect, inspect a small diff, rebuild after the final edit, and evaluate the artifact against separate checks. A confident explanation alone would not demonstrate the repair.
This was one local run using the Unsloth UD-Q3_K_XL GGUF of Qwen3.8-27B through Pi and llama.cpp. The harness exposed text and tool results. These results are about this task and configuration, not a universal reliability score or a comparison with other models.
If you maintain importers, geometry tools, or release CLIs, take the reusable test pattern: exercise the opposite sign range, distinguish valid empty-looking whitespace from an empty dataset, and specify what failure must not output. Those details make an agent's patch much easier to review.
AI assistance disclosure: This article was prepared with AI assistance and checked against the episode's work order, submitted patch, recorded test logs, and published video. The article's explanations extend the short video; no additional model run is claimed.
About the author
- Fluid Coding & AI shares practical explainers on AI coding tools, coding agents, and local language models. Companion articles provide useful takeaways and links to our YouTube videos: https://www.youtube.com/channel/UC33TW-QudYXRE-zIIh00NKA
Comments
Join the discussionNo comments yet. Be the first to comment.