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
#include <gp_Pnt.hxx>
#ifdef __cplusplus
extern "C" {
#endif
TopoDS_Shape make_point(double x, double y, double z);
void coord_point(const TopoDS_Shape& shape, double* x, double* y, double* z);
void clear_point(TopoDS_Shape& shape);
typedef struct point_shape point_shape_t;
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
+22 -13
View File
@@ -10,20 +10,29 @@
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <gp_Pnt.hxx>
TopoDS_Shape make_point(double x, double y, double z) {
gp_Pnt point(x, y, z);
return BRepBuilderAPI_MakeVertex(point).Vertex();
}
struct point_shape_t {
TopoDS_Shape shape;
};
void coord_point(const TopoDS_Shape& shape, double* x, double* y, double* z) {
TopoDS_Vertex vertex = TopoDS::Vertex(shape);
gp_Pnt point = BRep_Tool::Pnt(vertex);
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);
result->shape = BRepBuilderAPI_MakeVertex(point).Vertex();
return result;
}
*x = point.X();
*y = point.Y();
*z = point.Z();
}
void coord_point(const point_shape_t* shape, double* x, double* y, double* z) {
if (!shape || !x || !y || !z) return;
void delete_shape(TopoDS_Shape* shape) {
delete shape;
TopoDS_Vertex vertex = TopoDS::Vertex(shape->shape);
gp_Pnt point = BRep_Tool::Pnt(vertex);
*x = point.X();
*y = point.Y();
*z = point.Z();
}
void delete_point(point_shape_t* shape) {
delete shape;
}
}