commit a2f0631a4f1bafa4325a51c7237edf74f623b1a3
parent 94b664272dee377ce0081f9e22109e074b4401da
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 26 Apr 2023 17:20:35 +0200
Add a point-in-component feature
Diffstat:
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/src/scpr.h b/src/scpr.h
@@ -239,6 +239,13 @@ scpr_polygon_eq
int* is_eq);
SCPR_API res_T
+scpr_point_in_component
+ (const struct scpr_polygon* polygon,
+ const size_t icomponent,
+ const double point[2],
+ int* situation); /* +1: inside, 0: on, -1: outside */
+
+SCPR_API res_T
scpr_polygon_dump_to_obj
(struct scpr_polygon* polygon,
FILE* stream);
@@ -322,12 +329,13 @@ SCPR_API res_T
scpr_intersector_ref_put
(struct scpr_intersector* intersector);
-/* Register a polygon's a polygon or a component for further analysis */
+/* Register a polygon for further analysis */
SCPR_API res_T
scpr_intersector_register_polygon
(struct scpr_intersector* intersector,
struct scpr_polygon* polygon);
+/* Register a polygon's component for further analysis */
SCPR_API res_T
scpr_intersector_register_component
(struct scpr_intersector* intersector,
diff --git a/src/scpr_polygon.c b/src/scpr_polygon.c
@@ -506,6 +506,44 @@ error:
}
res_T
+scpr_point_in_component
+ (const struct scpr_polygon* polygon,
+ const size_t icomponent,
+ const double point[2],
+ int* situation)
+{
+ res_T res = RES_OK;
+ int64_t tmp64[2];
+ Clipper2Lib::Point64 pt;
+ Clipper2Lib::PointInPolygonResult in;
+
+ if(!polygon || !point || !situation || icomponent >= polygon->paths.size()) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ ERR(scpr_device_scale(polygon->device, point, 2, tmp64));
+ TRY(in = Clipper2Lib::PointInPolygon(pt, polygon->paths[icomponent]));
+ enum class PointInPolygonResult { IsOn, IsInside, IsOutside };
+ switch(in) {
+ case Clipper2Lib::PointInPolygonResult::IsOn:
+ *situation = 0;
+ break;
+ case Clipper2Lib::PointInPolygonResult::IsOutside:
+ *situation = -1;
+ break;
+ case Clipper2Lib::PointInPolygonResult::IsInside:
+ *situation = +1;
+ break;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+res_T
scpr_polygon_dump_to_obj
(struct scpr_polygon* polygon,
FILE* stream)