star-cpr

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

commit a8a6aeffbaabe5af8733717e9e54a7ec2d83bde0
parent 3dbf6253d07b1433f727e0ee62974c08398cd9d8
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu,  7 Sep 2023 10:14:10 +0200

Add is_cw and reverse to allow component orientation management

Diffstat:
Msrc/scpr.h | 13+++++++++++++
Msrc/scpr_polygon.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/src/scpr.h b/src/scpr.h @@ -230,6 +230,19 @@ scpr_polygon_get_position const size_t ivert, double position[2]); +/* Get the polygon component orientation. + * Only meaningful for simple polygons. */ +SCPR_API res_T +scpr_polygon_is_component_cw + (const struct scpr_polygon* polygon, + const size_t icomponent, + int* cw); + +SCPR_API res_T +scpr_polygon_reverse_component + (struct scpr_polygon* polygon, + const size_t icomponent); + /* Logical comparison for polygons. * Component order and orientation are not considered. */ SCPR_API res_T diff --git a/src/scpr_polygon.c b/src/scpr_polygon.c @@ -456,6 +456,55 @@ error: } res_T +scpr_polygon_is_component_cw + (const struct scpr_polygon* polygon, + const size_t icomponent, + int* cw) +{ + res_T res = RES_OK; + + if(!polygon || !cw || icomponent > polygon->paths.size()) { + res = RES_BAD_ARG; + goto error; + } + + *cw = !Clipper2Lib::IsPositive(polygon->paths[icomponent]); + +exit: + return res; +error: + goto exit; +} + +res_T +scpr_polygon_reverse_component + (struct scpr_polygon* polygon, + const size_t icomponent) +{ + res_T res = RES_OK; + Clipper2Lib::Point64* data; + size_t i, j; + + if(!polygon || icomponent > polygon->paths.size()) { + res = RES_BAD_ARG; + goto error; + } + + i = 0; + j = polygon->paths[icomponent].size(); + data = polygon->paths[icomponent].data(); + while(i != j && i != --j) { + SWAP(Clipper2Lib::Point64, data[i], data[j]); + i++; /* Not in SWAP macro! */ + } + +exit: + return res; +error: + goto exit; +} + +res_T scpr_polygon_eq (const struct scpr_polygon* polygon1, const struct scpr_polygon* polygon2,