occt: refactor library for Rust FFI compatibility

This commit is contained in:
2025-11-12 00:23:05 +01:00
parent 2b42634d88
commit 29a3ff419d
2 changed files with 34 additions and 17 deletions
+12 -4
View File
@@ -8,10 +8,18 @@
#pragma once #pragma once
#include <gp_Pnt.hxx> #ifdef __cplusplus
extern "C" {
#endif
TopoDS_Shape make_point(double x, double y, double z); typedef struct point_shape point_shape_t;
void coord_point(const TopoDS_Shape& shape, double* x, double* y, double* z);
void clear_point(TopoDS_Shape& shape); point_shape_t* make_point(double x, double y, double z);
void coord_point(const point_shape_t* shape, double* x, double* y, double* z);
void delete_point(point_shape_t* shape);
#ifdef __cplusplus
}
#endif
#endif #endif
+17 -8
View File
@@ -10,20 +10,29 @@
#include <BRepBuilderAPI_MakeVertex.hxx> #include <BRepBuilderAPI_MakeVertex.hxx>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
TopoDS_Shape make_point(double x, double y, double z) { struct point_shape_t {
TopoDS_Shape shape;
};
extern "C" {
point_shape_t* make_point(double x, double y, double z) {
point_shape_t* result = new point_shape_t();
gp_Pnt point(x, y, z); gp_Pnt point(x, y, z);
return BRepBuilderAPI_MakeVertex(point).Vertex(); result->shape = BRepBuilderAPI_MakeVertex(point).Vertex();
} return result;
}
void coord_point(const TopoDS_Shape& shape, double* x, double* y, double* z) { void coord_point(const point_shape_t* shape, double* x, double* y, double* z) {
TopoDS_Vertex vertex = TopoDS::Vertex(shape); if (!shape || !x || !y || !z) return;
TopoDS_Vertex vertex = TopoDS::Vertex(shape->shape);
gp_Pnt point = BRep_Tool::Pnt(vertex); gp_Pnt point = BRep_Tool::Pnt(vertex);
*x = point.X(); *x = point.X();
*y = point.Y(); *y = point.Y();
*z = point.Z(); *z = point.Z();
} }
void delete_shape(TopoDS_Shape* shape) { void delete_point(point_shape_t* shape) {
delete shape; delete shape;
}
} }