refactor: name the tolerances (scad::tol) instead of repeating their numbers

include/scad/core/tolerance.hpp holds 38 constants, each named for what it is a tolerance for, with a how-to-choose
comment and a table. 116 sites in 56 files use them; every constant has exactly the value of the literal it replaces,
so nothing computes differently (ctest and the golden parity tests unchanged). About 110 literals stay where they
are on purpose: OCCT mirror bindings, solver constants that already have local names, relative-times-floor
combinations, raster/render epsilons.

Six ambiguous sites are listed in the CHANGELOG-free note of the commit for the owner:
extrude_until.cpp:68 (1e-8 sine test), :193 (extent below 1e-12 uses kDegenerateNorm), probes.cpp:207,228,
bind_surface.cpp:75 (interpolation default 1e-5 vs kSplineInterpolation 1e-6), tracking.hpp:148 (tracked_shell tol),
BuildCurves3d at 1e-6 (kernel/curves.cpp:177) and 1e-7 (tracking_lofts.cpp:254).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NiJingzhe
2026-10-29 16:58:17 +08:00
parent 764e4a3324
commit b4f8067f26
57 changed files with 275 additions and 115 deletions
+3 -2
View File
@@ -1,5 +1,6 @@
#include "bindings.hpp"
#include "scad/core/tolerance.hpp"
#include "scad/core/coordinate_system.hpp"
#include <cmath>
#include <cstdio>
@@ -36,14 +37,14 @@ void bind_core(py::module_& m) {
.def("norm", [](const PyVec3& p) { return p.v.norm(); })
.def("normalized",
[](const PyVec3& p) {
if (p.v.norm() <= 1e-15)
if (p.v.norm() <= scad::tol::kZeroDirectionNorm)
throw scad::ValueError("Cannot normalize a zero-length vector");
return PyVec3{p.v.normalized()};
})
.def("getAngle",
[](const PyVec3& p, const scad::Vec3& o) {
const double sn = p.v.norm(), on = o.norm();
if (sn <= 1e-15 || on <= 1e-15)
if (sn <= scad::tol::kZeroDirectionNorm || on <= scad::tol::kZeroDirectionNorm)
throw scad::ValueError("Cannot compute angle with a zero-length vector");
return std::acos(std::max(-1.0, std::min(1.0, p.v.dot(o) / (sn * on))));
})