Skip to content

Commit

Permalink
feat(bindings): use Vec3 methods over free functs.
Browse files Browse the repository at this point in the history
Changes:
* Updated bindings for Vec3 type (use instance methods instead of free
  funcs)
* Fixed some syntax typos
  • Loading branch information
wpumacay committed Apr 30, 2023
1 parent 8816439 commit 895937f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 3 additions & 6 deletions include/math/vec3_t_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ template <typename T>
class Vector3 {
public:
/// Number of scalars used in the storage of the vector
constexpr static uint32_t BUFFER_SIZE = 3;
static constexpr uint32_t BUFFER_SIZE = 3;
/// Number of scalar dimensions of the vector
constexpr static uint32_t VECTOR_SIZE = 3;
static constexpr uint32_t VECTOR_SIZE = 3;
/// Number of dimensions of this vector (as in np.array.ndim)
static constexpr uint32_t VECTOR_NDIM = 1;

/// Typename of the vector
// Some handy type aliases used throught the codebase
using Type = Vector3<T>;
/// Typename of the scalar used for the vector (float32, float64, etc.)
using ElementType = T;
/// Typename of the internal storage used for the vector
using BufferType = std::array<T, BUFFER_SIZE>;

// Some related types
Expand Down Expand Up @@ -83,7 +81,6 @@ class Vector3 {
m_Elements[2] = vec.z();
}

// cppcheck-suppress noExplicitConstructor
/// COnstructs a vector from an initializer list of the form {x, y, z}
Vector3(const std::initializer_list<T>& values) {
// Complain in case we don't receive exactly 3 values
Expand Down
22 changes: 18 additions & 4 deletions python/math3d/bindings/vec3_py.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,26 @@ auto bindings_vector3(py::module& m, const char* class_name) -> void {
VECTOR_PROPERTY(y)
VECTOR_PROPERTY(z)
VECTOR_OPERATORS(T)
VECTOR_METHODS(T)
.def("cross", [](const Class& self, const Class& other) -> Class {
return ::math::cross<T>(self, other);
})
VECTOR_GETSET_ITEM(3, T)
// clant-format on
.def("dot", [](const Class& self, const Class& other) -> T {
return self.dot(other);
})
.def("norm", [](const Class& self) -> T {
return self.length();
})
.def("squareNorm", [](const Class& self) -> T {
return self.lengthSquare();
})
.def("normalize", [](const Class& self) -> Class {
return self.normalized();
})
.def("normalize_", [](Class& self) -> void {
self.normalize();
})
.def("cross", [](const Class& self, const Class& other) -> Class {
return self.cross(other);
})
.def("numpy", [](const Class& self) -> py::array_t<T> {
return ::math::vec3_to_nparray<T>(self);
})
Expand Down

0 comments on commit 895937f

Please sign in to comment.