Skip to content

Commit

Permalink
Reverted unification of positive and negative zeros when loaded
Browse files Browse the repository at this point in the history
from an STL file.

Conflicts:

	xs/src/admesh/stlinit.c
  • Loading branch information
bubnikv authored and alranel committed Mar 8, 2017
1 parent bb214b0 commit 412498b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions xs/src/admesh/stlinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,28 @@ stl_read(stl_file *stl, int first_facet, int first) {
}
#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);
Expand Down

0 comments on commit 412498b

Please sign in to comment.