commit ec498207cd1ca73395ce4ede7e884a66217d090b
parent 80ea91f02d9e14fa40a04c47b1be3cbbcba32572
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 27 Jan 2023 16:37:46 +0100
Adapt to Clipper2 now raising an exception on range errors
The range limit is not what was anticipated, forcing us to change star-cpr own limit
Diffstat:
3 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/src/scpr.h b/src/scpr.h
@@ -84,10 +84,9 @@ scpr_polygon_ref_put
/* To ensure constant precision, vertice coordinates are truncated, and have a
* limited range. Range checking along with the associated truncation process
* occur at vertices setup.
- * The range of the coordinates is [-INT64_MAX*10E-6 +INT64_MAX*10E-6], that is
- * [-9223372036854.775807 +9223372036854.775807] or approximately
- * [-9.2E12 +9.2E12], and vertex coordinates are truncated past the 6th decimal
- * place. It is an error to use out-of-range values.
+ * The range of the coordinates is [-INT64_MAX*0.25E-6 +INT64_MAX*0.25E-6], that
+ * is approximately [-2.3E18 + 2.3E18], and vertex coordinates are truncated
+ * past the 6th decimal place. It is an error to use out-of-range values.
* Truncated coordinates can be retrieved using the appropriate getters. */
SCPR_API res_T
scpr_polygon_setup_indexed_vertices
@@ -122,6 +121,8 @@ scpr_polygon_get_position
const size_t ivert,
double position[2]);
+/* Logical comparison for polygons.
+ * Component order and orientation are not considered. */
SCPR_API res_T
scpr_polygon_eq
(const struct scpr_polygon* polygon1,
@@ -150,7 +151,7 @@ scpr_mesh_setup_indexed_vertices
void (*get_position)(const size_t ivert, double pos[2], void* ctx),
void* data); /* Client data set as the last param of the callbacks */
-/* Clip the mesh against the polygon contour */
+/* Clip the mesh against the polygon using the EvenOdd filling rule */
SCPR_API res_T
scpr_mesh_clip
(struct scpr_mesh* mesh, /* Candidate mesh to clip */
diff --git a/src/scpr_polygon.c b/src/scpr_polygon.c
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "clipper2/clipper.core.h"
+#include <clipper2/clipper.h>
#include "scpr.h"
#include "scpr_c.h"
@@ -33,8 +33,8 @@
* This parameter defines both the floating point precision for the coordinates
* and the range of the coordinates.
* With a precision of 0, coordinates are truncated to the nearest integer and
- * the coordinate range is [-INT64_MAX +INT64_MAX] (that is
- * [-9223372036854775807 +9223372036854775807] or ~ [-9.2E18 + 9.2E18]).
+ * the coordinate range is [-INT64_MAX/4 +INT64_MAX/4] (that is approximately
+ * [-2.3E18 + 2.3E18]).
* Increasing precision by 1 adds 1 more decimal place to the coordinate
* precision and divides the coordinate range by 10. */
#define PRECISION 6
@@ -75,6 +75,7 @@ path_is_eq
int opposite_cw;
ASSERT(p1 && p2);
sz = p1->size();
+
if(sz != p2->size()) {
return 0;
}
diff --git a/src/test_scpr_offset.c b/src/test_scpr_offset.c
@@ -36,13 +36,19 @@ test_single(void)
const double coords2[] = {
0.12345678901234, 0.0,
0.0, 1.0,
- 1.0, 9223372036854,
+ 1.0, 2305843009213,
1.0, 0.0
};
+ const double coords2_reverse[] = {
+ 0.12345678901234, 0.0,
+ 1.0, 0.0,
+ 1.0, 2305843009213,
+ 0.0, 1.0
+ };
const double coords3[] = {
9223372036855, 0.0,
0.0, 1.0,
- 1.0, 9223372036854,
+ 1.0, 2305843009214,
1.0, 0.0
};
double** coords;
@@ -121,6 +127,13 @@ test_single(void)
CHK(scpr_polygon_eq(polygon, expected, &eq) == RES_OK);
CHK(eq);
+ /* Check non-effect of CW/CCW */
+ memcpy(*coords, coords2_reverse, 2*nverts[0]*sizeof(**coords));
+ CHK(scpr_polygon_setup_indexed_vertices(expected, ncomps, pget_nverts, pget_pos, &ctx)
+ == RES_OK);
+ CHK(scpr_polygon_eq(polygon, expected, &eq) == RES_OK);
+ CHK(eq);
+
/* Check out of range */
memcpy(*coords, coords3, 2*nverts[0]*sizeof(**coords));
CHK(scpr_polygon_setup_indexed_vertices(expected, ncomps, pget_nverts, pget_pos, &ctx)