star-cpr

Clip 2D meshes with 2D polygons
git clone git://git.meso-star.fr/star-cpr.git
Log | Files | Refs | README | LICENSE

commit 54ef2f36c5b07656e805c9091a5af88255d0cc50
parent be5cf33acb117cb1af85bbb3a02b55c80f79d61c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 26 Aug 2016 14:53:11 +0200

Fix the double <-> cInt conversions

If the double to convert was normalized to 1, its cInt value was null.

Diffstat:
Msrc/cpr_mesh.c | 10++++++----
Msrc/test_cpr_clip.c | 3+++
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/cpr_mesh.c b/src/cpr_mesh.c @@ -64,7 +64,8 @@ double_to_cInt(const double d, const double scale) ASSERT(scale > 0); ucast.d = 1 + fabs(d / scale); - i = (ucast.i & 0x000FFFFFFFFFFFFF) >> 1; + i = (((ucast.i >> 52) & 0x7FF) - 1023) << 52; + i = (ucast.i & 0x000FFFFFFFFFFFFF) | i; return dbl < 0 ? -i : i; } @@ -73,9 +74,10 @@ cInt_to_double(const ClipperLib::cInt i, const double scale) { double dbl; union { int64_t i; double d; } ucast; - assert(scale > 0); + ASSERT(scale > 0); - ucast.i = 0x3FF0000000000000 | (llabs(i) << 1); + ucast.i = llabs(i); + ucast.i = ((1023 + (ucast.i >> 52)) << 52) | (ucast.i & 0x000FFFFFFFFFFFFF); dbl = (ucast.d - 1) * scale; return i < 0 ? -dbl : dbl; } @@ -150,7 +152,7 @@ register_vertex /* FIXME dirty hack */ v.pos[0] = (float)v.pos[0]; - v.pos[1] = (float)v.pos[1]; + v.pos[1] = (float)v.pos[1]; pid = htable_vertex_find(vertices, &v); diff --git a/src/test_cpr_clip.c b/src/test_cpr_clip.c @@ -80,6 +80,8 @@ test_triangle(struct cpr_mesh* mesh) CHECK(cpr_mesh_clip(NULL, &poly), RES_BAD_ARG); CHECK(cpr_mesh_clip(mesh, &poly), RES_OK); + /*dump_obj(stdout, mesh);*/ + CHECK(cpr_mesh_get_triangles_count(mesh, &ntris), RES_OK); CHECK(ntris, 3); } @@ -181,3 +183,4 @@ main(int argc, char** argv) CHECK(mem_allocated_size(), 0); return 0; } +