Skip to content

Commit

Permalink
feat: exposes allocation functions via C bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
NickUfer committed Sep 30, 2024
1 parent 3c8d486 commit 6274467
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bindings/c/include/manifold/manifoldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,18 @@ size_t manifold_box_size();
size_t manifold_rect_size();
size_t manifold_curvature_size();

// allocation

ManifoldManifold *manifold_alloc_manifold();
ManifoldManifoldVec *manifold_alloc_manifold_vec();
ManifoldCrossSection *manifold_alloc_cross_section();
ManifoldCrossSectionVec *manifold_alloc_cross_section_vec();
ManifoldSimplePolygon *manifold_alloc_simple_polygon();
ManifoldPolygons *manifold_alloc_polygons();
ManifoldMeshGL *manifold_alloc_meshgl();
ManifoldBox *manifold_alloc_box();
ManifoldRect *manifold_alloc_rect();

// destruction

void manifold_destruct_manifold(ManifoldManifold *m);
Expand Down
29 changes: 29 additions & 0 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,35 @@ size_t manifold_meshgl_size() { return sizeof(MeshGL); }
size_t manifold_box_size() { return sizeof(Box); }
size_t manifold_rect_size() { return sizeof(Rect); }

// allocation
ManifoldManifold* manifold_alloc_manifold() {
return to_c(static_cast<Manifold *>(malloc(manifold_manifold_size())));
}
ManifoldManifoldVec* manifold_alloc_manifold_vec() {
return to_c(static_cast<std::vector<Manifold> *>(malloc(manifold_manifold_vec_size())));
}
ManifoldCrossSection* manifold_alloc_cross_section() {
return to_c(static_cast<CrossSection *>(malloc(manifold_cross_section_size())));
}
ManifoldCrossSectionVec* manifold_alloc_cross_section_vec() {
return to_c(static_cast<std::vector<CrossSection> *>(malloc(manifold_cross_section_vec_size())));
}
ManifoldSimplePolygon* manifold_alloc_simple_polygon() {
return to_c(static_cast<SimplePolygon *>(malloc(manifold_simple_polygon_size())));
}
ManifoldPolygons* manifold_alloc_polygons() {
return to_c(static_cast<std::vector<SimplePolygon> *>(malloc(manifold_polygons_size())));
}
ManifoldMeshGL* manifold_alloc_meshgl() {
return to_c(static_cast<MeshGL *>(malloc(manifold_meshgl_size())));
}
ManifoldBox* manifold_alloc_box() {
return to_c(static_cast<Box *>(malloc(manifold_box_size())));
}
ManifoldRect* manifold_alloc_rect() {
return to_c(static_cast<Rect *>(malloc(manifold_rect_size())));
}

// pointer free + destruction
void manifold_delete_cross_section(ManifoldCrossSection *c) {
delete from_c(c);
Expand Down

0 comments on commit 6274467

Please sign in to comment.