diff options
author | Marius Kintel <marius@kintel.net> | 2011-12-21 21:20:27 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-12-21 21:20:27 (GMT) |
commit | 51c28e8a5ba7a3d4897389498e0a2aa606e78cf9 (patch) | |
tree | 9ed1cc93bf534bc6b2e2bf8fd15e20abae97aa29 /src | |
parent | 2bfd2a379d8748902ed5a48f9e8a536907f641d5 (diff) |
fix for normal fix: would fail in some extreme cases (e.g. if there are
components with very different orders of magnitude, as may happen when floating point errors fail to produce a 0)
Diffstat (limited to 'src')
-rw-r--r-- | src/export.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/export.cc b/src/export.cc index 89f60af..99bce98 100644 --- a/src/export.cc +++ b/src/export.cc @@ -90,12 +90,14 @@ void export_stl(CGAL_Nef_polyhedron *root_N, std::ostream &output, QProgressDial // of vs1-vs2 and vs1-vs3. This has no effect on the resulting unit // normal vector. double dn[6] = { x1-x2, y1-y2, z1-z2, x1-x3, y1-y3, z1-z3 }; - double mindn = 1; - for (int i = 0; i < 6; ++i) { - double dx = abs(dn[i]); - if (dx < mindn && dx != 0) mindn = dx; + double maxdn = 0; + int i; + for (i = 0; i < 6; ++i) { + double dx = dn[i]; + if (dx < 0) dx = -dx; + if (dx > maxdn) maxdn = dx; } - for (int i = 0; i < 6; ++i) dn[i] /= mindn; + for (i = 0; i < 6; ++i) dn[i] /= maxdn; double nx = dn[1]*dn[5] - dn[2]*dn[4]; double ny = dn[2]*dn[3] - dn[0]*dn[5]; double nz = dn[0]*dn[4] - dn[1]*dn[3]; |