star-cpr

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

commit d710029da754b33bb63b40e32c9d913a583827f1
parent 54ef2f36c5b07656e805c9091a5af88255d0cc50
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 26 Aug 2016 15:46:33 +0200

Fix the AABB computations

Diffstat:
Msrc/cpr_mesh.c | 16++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/cpr_mesh.c b/src/cpr_mesh.c @@ -119,7 +119,7 @@ poly_setup(struct poly* poly, const struct cpr_polygon* desc) if(res != RES_OK) goto error; d2_splat(poly->lower, DBL_MAX); - d2_splat(poly->upper, DBL_MIN); + d2_splat(poly->upper,-DBL_MAX); FOR_EACH(ivert, 0, desc->nvertices) { double* pos = darray_double_data_get(&poly->coords) + ivert*2; desc->get_position(ivert, pos, desc->context); @@ -132,7 +132,7 @@ exit: error: darray_double_clear(&poly->coords); d2_splat(poly->lower, DBL_MAX); - d2_splat(poly->upper, DBL_MIN); + d2_splat(poly->upper,-DBL_MAX); goto exit; } @@ -186,13 +186,12 @@ register_paths struct darray_size_t* indices, /* Index buffer */ struct htable_vertex* vertices, /* Map a vertex to its index */ const double extend[2], /* Scale to apply to the cInt coordinates */ - struct polygon* polygon, /* Use to triangulate the clipped polygons */ - struct darray_double* scratch) /* Temporary container */ + struct polygon* polygon) /* Use to triangulate the clipped polygons */ { size_t ivert; size_t ipath; res_T res = RES_OK; - ASSERT(coords && indices && vertices && scratch); + ASSERT(coords && indices && vertices); FOR_EACH(ipath, 0, paths.size()) { if(paths[ipath].size() == 3) { @@ -210,7 +209,6 @@ register_paths /* Define the contour of the polygon to triangulate */ POLYGON(clear(polygon)); - darray_double_clear(scratch); FOR_EACH(ivert, 0, paths[ipath].size()) { float fpos[3] = {0.f, 0.f, 0.f}; double pos[2]; @@ -249,7 +247,7 @@ mesh_compute_aabb(const struct cpr_mesh* mesh, double lower[2], double upper[2]) CPR(mesh_get_triangles_count(mesh, &ntris)); d2_splat(lower, DBL_MAX); - d2_splat(upper, DBL_MIN); + d2_splat(upper,-DBL_MAX); FOR_EACH(itri, 0, ntris) { size_t ids[3], ivert; @@ -432,7 +430,6 @@ cpr_mesh_clip(struct cpr_mesh* mesh, struct cpr_polygon* poly_desc) double lower[2], upper[2], extend[2]; struct poly poly; struct polygon* polygon = NULL; /* Use to triangulate clipped polygons */ - struct darray_double polycoords; /* Clipped polygon to triangulate */ struct darray_double coords; /* Coordinates of the clipped mesh */ struct darray_size_t indices; /* Indices of the clipped mesh */ struct htable_vertex vertices; /* Map a coordinate to its index */ @@ -447,7 +444,6 @@ cpr_mesh_clip(struct cpr_mesh* mesh, struct cpr_polygon* poly_desc) if(!mesh || !poly_desc) return RES_BAD_ARG; - darray_double_init(mesh->allocator, &polycoords); darray_double_init(mesh->allocator, &coords); darray_size_t_init(mesh->allocator, &indices); htable_vertex_init(mesh->allocator, &vertices); @@ -504,7 +500,7 @@ cpr_mesh_clip(struct cpr_mesh* mesh, struct cpr_polygon* poly_desc) /* Register the polygons */ res = register_paths - (output, &coords, &indices, &vertices, extend, polygon, &polycoords); + (output, &coords, &indices, &vertices, extend, polygon); if(res != RES_OK) goto error; }