Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2017-03-03 14:54:00 +0300
committerbubnikv <bubnikv@gmail.com>2017-03-03 14:54:00 +0300
commit930e6752d9f60b2c90e1a729e31bf5ff876a7001 (patch)
treee5a2e22d92505fde0b64069a8ab3c775a139252f /xs
parent4d00aa180036c74d494b7762ac7512c67849c4b2 (diff)
Reverted unification of positive and negative zeros when loaded
from an STL file.
Diffstat (limited to 'xs')
-rw-r--r--xs/src/admesh/stlinit.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/xs/src/admesh/stlinit.c b/xs/src/admesh/stlinit.c
index f797004fb..2e55462df 100644
--- a/xs/src/admesh/stlinit.c
+++ b/xs/src/admesh/stlinit.c
@@ -308,6 +308,29 @@ stl_read(stl_file *stl, int first_facet, int first) {
printf("stl_read: facet %d.z = %e\r\n", j, facet.vertex[j].z);
}
#endif
+
+#if 1
+ {
+ // Positive and negative zeros are possible in the floats, which are considered equal by the FP unit.
+ // When using a memcmp on raw floats, those numbers report to be different.
+ // Unify all +0 and -0 to +0 to make the floats equal under memcmp.
+ uint32_t *f = (uint32_t*)&facet;
+ for (int j = 0; j < 12; ++ j, ++ f) // 3x vertex + normal: 4x3 = 12 floats
+ if (*f == 0x80000000)
+ // Negative zero, switch to positive zero.
+ *f = 0;
+ }
+#else
+ {
+ // Due to the nature of the floating point numbers, close to zero values may be represented with singificantly higher precision
+ // than the rest of the vertices. Round them to zero.
+ float *f = (float*)&facet;
+ for (int j = 0; j < 12; ++ j, ++ f) // 3x vertex + normal: 4x3 = 12 floats
+ if (*f > -1e-12f && *f < 1e-12f)
+ // Negative zero, switch to positive zero.
+ *f = 0;
+ }
+#endif
/* Write the facet into memory. */
memcpy(stl->facet_start+i, &facet, SIZEOF_STL_FACET);
stl_facet_stats(stl, facet, first);