Skip to content
This repository has been archived by the owner on Feb 22, 2021. It is now read-only.

Commit

Permalink
Use namespaces instead of underscore prefix for module bind classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Xrayez committed May 11, 2020
1 parent 4dd2e42 commit c8d396c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 54 deletions.
94 changes: 49 additions & 45 deletions 2d/bind/geometry_tools_bind.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
#include "geometry_tools_bind.h"

_GeometryTools2D *_GeometryTools2D::singleton = nullptr;
namespace module_bind {

Array _GeometryTools2D::merge_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = GeometryTools2D::merge_polygons(p_polygon_a, p_polygon_b, p_params);
GeometryTools2D *GeometryTools2D::singleton = nullptr;

Array GeometryTools2D::merge_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = ::GeometryTools2D::merge_polygons(p_polygon_a, p_polygon_b, p_params);
Array ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
}
return ret;
}

Array _GeometryTools2D::clip_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = GeometryTools2D::clip_polygons(p_polygon_a, p_polygon_b, p_params);
Array GeometryTools2D::clip_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = ::GeometryTools2D::clip_polygons(p_polygon_a, p_polygon_b, p_params);
Array ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
}
return ret;
}

Array _GeometryTools2D::intersect_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = GeometryTools2D::intersect_polygons(p_polygon_a, p_polygon_b, p_params);
Array GeometryTools2D::intersect_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = ::GeometryTools2D::intersect_polygons(p_polygon_a, p_polygon_b, p_params);
Array ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
}
return ret;
}

Array _GeometryTools2D::exclude_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = GeometryTools2D::exclude_polygons(p_polygon_a, p_polygon_b, p_params);
Array GeometryTools2D::exclude_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polys = ::GeometryTools2D::exclude_polygons(p_polygon_a, p_polygon_b, p_params);
Array ret;
for (int i = 0; i < polys.size(); ++i) {
ret.push_back(polys[i]);
}
return ret;
}

Array _GeometryTools2D::merge_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Array GeometryTools2D::merge_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Vector2> > polygons_a;
for (int i = 0; i < p_polygons_a.size(); ++i) {
polygons_a.push_back(p_polygons_a[i]);
Expand All @@ -47,15 +49,15 @@ Array _GeometryTools2D::merge_polygons_array(Array p_polygons_a, Array p_polygon
for (int i = 0; i < p_polygons_b.size(); ++i) {
polygons_b.push_back(p_polygons_b[i]);
}
Vector<Vector<Vector2> > solution = GeometryTools2D::merge_polygons_array(polygons_a, polygons_b, p_params);
Vector<Vector<Vector2> > solution = ::GeometryTools2D::merge_polygons_array(polygons_a, polygons_b, p_params);
Array ret;
for (int i = 0; i < solution.size(); ++i) {
ret.push_back(solution[i]);
}
return ret;
}

Array _GeometryTools2D::clip_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Array GeometryTools2D::clip_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Vector2> > polygons_a;
for (int i = 0; i < p_polygons_a.size(); ++i) {
polygons_a.push_back(p_polygons_a[i]);
Expand All @@ -64,15 +66,15 @@ Array _GeometryTools2D::clip_polygons_array(Array p_polygons_a, Array p_polygons
for (int i = 0; i < p_polygons_b.size(); ++i) {
polygons_b.push_back(p_polygons_b[i]);
}
Vector<Vector<Vector2> > solution = GeometryTools2D::clip_polygons_array(polygons_a, polygons_b, p_params);
Vector<Vector<Vector2> > solution = ::GeometryTools2D::clip_polygons_array(polygons_a, polygons_b, p_params);
Array ret;
for (int i = 0; i < solution.size(); ++i) {
ret.push_back(solution[i]);
}
return ret;
}

Array _GeometryTools2D::intersect_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Array GeometryTools2D::intersect_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Vector2> > polygons_a;
for (int i = 0; i < p_polygons_a.size(); ++i) {
polygons_a.push_back(p_polygons_a[i]);
Expand All @@ -81,15 +83,15 @@ Array _GeometryTools2D::intersect_polygons_array(Array p_polygons_a, Array p_pol
for (int i = 0; i < p_polygons_b.size(); ++i) {
polygons_b.push_back(p_polygons_b[i]);
}
Vector<Vector<Vector2> > solution = GeometryTools2D::intersect_polygons_array(polygons_a, polygons_b, p_params);
Vector<Vector<Vector2> > solution = ::GeometryTools2D::intersect_polygons_array(polygons_a, polygons_b, p_params);
Array ret;
for (int i = 0; i < solution.size(); ++i) {
ret.push_back(solution[i]);
}
return ret;
}

Array _GeometryTools2D::exclude_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Array GeometryTools2D::exclude_polygons_array(Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Vector2> > polygons_a;
for (int i = 0; i < p_polygons_a.size(); ++i) {
polygons_a.push_back(p_polygons_a[i]);
Expand All @@ -98,15 +100,15 @@ Array _GeometryTools2D::exclude_polygons_array(Array p_polygons_a, Array p_polyg
for (int i = 0; i < p_polygons_b.size(); ++i) {
polygons_b.push_back(p_polygons_b[i]);
}
Vector<Vector<Vector2> > solution = GeometryTools2D::exclude_polygons_array(polygons_a, polygons_b, p_params);
Vector<Vector<Vector2> > solution = ::GeometryTools2D::exclude_polygons_array(polygons_a, polygons_b, p_params);
Array ret;
for (int i = 0; i < solution.size(); ++i) {
ret.push_back(solution[i]);
}
return ret;
}

Ref<PolyNode2D> _GeometryTools2D::polygons_boolean(PolyBooleanBase2D::Operation p_op, Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Ref<PolyNode2D> GeometryTools2D::polygons_boolean(PolyBooleanBase2D::Operation p_op, Array p_polygons_a, Array p_polygons_b, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polygons_a;
for (int i = 0; i < p_polygons_a.size(); i++) {
polygons_a.push_back(p_polygons_a[i]);
Expand All @@ -115,28 +117,28 @@ Ref<PolyNode2D> _GeometryTools2D::polygons_boolean(PolyBooleanBase2D::Operation
for (int i = 0; i < p_polygons_b.size(); i++) {
polygons_b.push_back(p_polygons_b[i]);
}
return GeometryTools2D::polygons_boolean(p_op, polygons_a, polygons_b, p_params);
return ::GeometryTools2D::polygons_boolean(p_op, polygons_a, polygons_b, p_params);
}

Array _GeometryTools2D::clip_polyline_with_polygon(const Vector<Point2> &p_polyline, const Vector<Point2> &p_polygon, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polylines = GeometryTools2D::clip_polyline_with_polygon(p_polyline, p_polygon, p_params);
Array GeometryTools2D::clip_polyline_with_polygon(const Vector<Point2> &p_polyline, const Vector<Point2> &p_polygon, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polylines = ::GeometryTools2D::clip_polyline_with_polygon(p_polyline, p_polygon, p_params);
Array ret;
for (int i = 0; i < polylines.size(); ++i) {
ret.push_back(polylines[i]);
}
return ret;
}

Array _GeometryTools2D::intersect_polyline_with_polygon(const Vector<Point2> &p_polyline, const Vector<Point2> &p_polygon, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polylines = GeometryTools2D::intersect_polyline_with_polygon(p_polyline, p_polygon, p_params);
Array GeometryTools2D::intersect_polyline_with_polygon(const Vector<Point2> &p_polyline, const Vector<Point2> &p_polygon, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polylines = ::GeometryTools2D::intersect_polyline_with_polygon(p_polyline, p_polygon, p_params);
Array ret;
for (int i = 0; i < polylines.size(); ++i) {
ret.push_back(polylines[i]);
}
return ret;
}

Array _GeometryTools2D::clip_polylines_with_polygons_array(const Array &p_polylines, const Array &p_polygons, const Ref<PolyBooleanParameters2D> &p_params) const {
Array GeometryTools2D::clip_polylines_with_polygons_array(const Array &p_polylines, const Array &p_polygons, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polylines;
for (int i = 0; i < p_polylines.size(); i++) {
polylines.push_back(p_polylines[i]);
Expand All @@ -145,15 +147,15 @@ Array _GeometryTools2D::clip_polylines_with_polygons_array(const Array &p_polyli
for (int i = 0; i < p_polygons.size(); i++) {
polygons.push_back(p_polygons[i]);
}
Vector<Vector<Vector2> > solution = GeometryTools2D::clip_polylines_with_polygons_array(polylines, polygons, p_params);
Vector<Vector<Vector2> > solution = ::GeometryTools2D::clip_polylines_with_polygons_array(polylines, polygons, p_params);
Array ret;
for (int i = 0; i < solution.size(); ++i) {
ret.push_back(solution[i]);
}
return ret;
}

Array _GeometryTools2D::intersect_polylines_with_polygons_array(const Array &p_polylines, const Array &p_polygons, const Ref<PolyBooleanParameters2D> &p_params) const {
Array GeometryTools2D::intersect_polylines_with_polygons_array(const Array &p_polylines, const Array &p_polygons, const Ref<PolyBooleanParameters2D> &p_params) const {
Vector<Vector<Point2> > polylines;
for (int i = 0; i < p_polylines.size(); i++) {
polylines.push_back(p_polylines[i]);
Expand All @@ -162,39 +164,41 @@ Array _GeometryTools2D::intersect_polylines_with_polygons_array(const Array &p_p
for (int i = 0; i < p_polygons.size(); i++) {
polygons.push_back(p_polygons[i]);
}
Vector<Vector<Vector2> > solution = GeometryTools2D::intersect_polylines_with_polygons_array(polylines, polygons, p_params);
Vector<Vector<Vector2> > solution = ::GeometryTools2D::intersect_polylines_with_polygons_array(polylines, polygons, p_params);
Array ret;
for (int i = 0; i < solution.size(); ++i) {
ret.push_back(solution[i]);
}
return ret;
}

real_t _GeometryTools2D::polygon_area(const Vector<Vector2> &p_polygon) {
return GeometryTools2D::polygon_area(p_polygon);
real_t GeometryTools2D::polygon_area(const Vector<Vector2> &p_polygon) {
return ::GeometryTools2D::polygon_area(p_polygon);
}

void _GeometryTools2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b", "params"), &_GeometryTools2D::merge_polygons, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b", "params"), &_GeometryTools2D::clip_polygons, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polygons", "polygon_a", "polygon_b", "params"), &_GeometryTools2D::intersect_polygons, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("exclude_polygons", "polygon_a", "polygon_b", "params"), &_GeometryTools2D::exclude_polygons, DEFVAL(Variant()));
void GeometryTools2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b", "params"), &GeometryTools2D::merge_polygons, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b", "params"), &GeometryTools2D::clip_polygons, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polygons", "polygon_a", "polygon_b", "params"), &GeometryTools2D::intersect_polygons, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("exclude_polygons", "polygon_a", "polygon_b", "params"), &GeometryTools2D::exclude_polygons, DEFVAL(Variant()));

ClassDB::bind_method(D_METHOD("merge_polygons_array", "polygons_a", "polygons_b", "params"), &_GeometryTools2D::merge_polygons_array, DEFVAL(Variant()), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("clip_polygons_array", "polygons_a", "polygons_b", "params"), &_GeometryTools2D::clip_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polygons_array", "polygons_a", "polygons_b", "params"), &_GeometryTools2D::intersect_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("exclude_polygons_array", "polygons_a", "polygons_b", "params"), &_GeometryTools2D::exclude_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("merge_polygons_array", "polygons_a", "polygons_b", "params"), &GeometryTools2D::merge_polygons_array, DEFVAL(Variant()), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("clip_polygons_array", "polygons_a", "polygons_b", "params"), &GeometryTools2D::clip_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polygons_array", "polygons_a", "polygons_b", "params"), &GeometryTools2D::intersect_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("exclude_polygons_array", "polygons_a", "polygons_b", "params"), &GeometryTools2D::exclude_polygons_array, DEFVAL(Variant()));

ClassDB::bind_method(D_METHOD("polygons_boolean", "operation", "polygons_a", "polygons_b", "params"), &_GeometryTools2D::polygons_boolean, DEFVAL(Variant()), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("polygons_boolean", "operation", "polygons_a", "polygons_b", "params"), &GeometryTools2D::polygons_boolean, DEFVAL(Variant()), DEFVAL(Variant()));

ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon", "polyline", "polygon", "params"), &_GeometryTools2D::clip_polyline_with_polygon, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon", "polyline", "polygon", "params"), &_GeometryTools2D::intersect_polyline_with_polygon, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("clip_polylines_with_polygons_array", "polylines", "polygons", "params"), &_GeometryTools2D::clip_polylines_with_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polylines_with_polygons_array", "polylines", "polygons", "params"), &_GeometryTools2D::intersect_polylines_with_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon", "polyline", "polygon", "params"), &GeometryTools2D::clip_polyline_with_polygon, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon", "polyline", "polygon", "params"), &GeometryTools2D::intersect_polyline_with_polygon, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("clip_polylines_with_polygons_array", "polylines", "polygons", "params"), &GeometryTools2D::clip_polylines_with_polygons_array, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("intersect_polylines_with_polygons_array", "polylines", "polygons", "params"), &GeometryTools2D::intersect_polylines_with_polygons_array, DEFVAL(Variant()));

ClassDB::bind_method(D_METHOD("polygon_area", "polygon"), &_GeometryTools2D::polygon_area);
ClassDB::bind_method(D_METHOD("polygon_area", "polygon"), &GeometryTools2D::polygon_area);
}

_GeometryTools2D::_GeometryTools2D() {
GeometryTools2D::GeometryTools2D() {
singleton = this;
}

} // namespace module_bind
14 changes: 9 additions & 5 deletions 2d/bind/geometry_tools_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@

#include "modules/geomtools/2d/geometry_tools.h"

class _GeometryTools2D : public Object {
GDCLASS(_GeometryTools2D, Object);
namespace module_bind {

class GeometryTools2D : public Object {
GDCLASS(GeometryTools2D, Object);

private:
static _GeometryTools2D *singleton;
static GeometryTools2D *singleton;

protected:
static void _bind_methods();

public:
static _GeometryTools2D *get_singleton() { return singleton; }
static GeometryTools2D *get_singleton() { return singleton; }

public:
Array merge_polygons(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b, const Ref<PolyBooleanParameters2D> &p_params) const;
Expand All @@ -35,9 +37,11 @@ class _GeometryTools2D : public Object {

real_t polygon_area(const Vector<Vector2> &p_polygon);

_GeometryTools2D();
GeometryTools2D();
};

VARIANT_ENUM_CAST(PolyBooleanBase2D::Operation);

} // namespace module_bind

#endif // GODOT_GEOMETRY_TOOLS_BIND_H
8 changes: 4 additions & 4 deletions register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "2d/bind/geometry_tools_bind.h"
#include "2d/geometry_tools.h"

static _GeometryTools2D *_geometry_tools = nullptr;
static module_bind::GeometryTools2D *_geometry_tools = nullptr;

void register_geomtools_types() {
_geometry_tools = memnew(_GeometryTools2D);
_geometry_tools = memnew(module_bind::GeometryTools2D);
GeometryTools2D::initialize();

ClassDB::register_class<_GeometryTools2D>();
Engine::get_singleton()->add_singleton(Engine::Singleton("GeometryTools2D", _GeometryTools2D::get_singleton()));
ClassDB::register_class<module_bind::GeometryTools2D>();
Engine::get_singleton()->add_singleton(Engine::Singleton("GeometryTools2D", module_bind::GeometryTools2D::get_singleton()));

ClassDB::register_class<PolyBooleanParameters2D>();
ClassDB::register_class<PolyNode2D>();
Expand Down

0 comments on commit c8d396c

Please sign in to comment.