Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions include/BoundingBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"

#include "./Vector3.hpp"

namespace raylib {
/**
* Bounding box type
Expand All @@ -25,8 +27,12 @@ class BoundingBox : public ::BoundingBox {
constexpr BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
constexpr BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}

GETTERSETTER(::Vector3, Min, min)
GETTERSETTER(::Vector3, Max, max)
// return the best we have
// receive the worst
GETTER(Vector3, Min, min)
SETTER(::Vector3, Min, min)
GETTER(Vector3, Max, max)
SETTER(::Vector3, Max, max)

BoundingBox& operator=(const ::BoundingBox& box) {
set(box);
Expand Down
18 changes: 15 additions & 3 deletions include/raylib-cpp-utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,32 @@
}
#endif

#ifndef GETTERSETTER
#ifndef SETTER
/**
* A utility to build get and set methods on top of a property.
*
* @param type The type of the property.
* @param method The human-readable name for the method.
* @param name The machine-readable name of the property.
*/
#define GETTERSETTER(type, method, name) \
GETTER(type, method, name) \
#define SETTER(type, method, name) \
/** Sets the name value for the object. @param value The value of which to set name to. */ \
void Set##method(type value) { \
name = value; \
}
#endif

#ifndef GETTERSETTER
/**
* A utility to build get and set methods on top of a property.
*
* @param type The type of the property.
* @param method The human-readable name for the method.
* @param name The machine-readable name of the property.
*/
#define GETTERSETTER(type, method, name) \
GETTER(type, method, name) \
SETTER(type, method, name)
#endif

#endif // RAYLIB_CPP_INCLUDE_RAYLIB_CPP_UTILS_HPP_
20 changes: 20 additions & 0 deletions tests/raylib_cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ int main(int argc, char* argv[]) {
AssertEqual(text.ToString().substr(0, 5), "Lorem");
}

// BoundingBox
{
::Vector3 min = {1, 2, 3};
::Vector3 max = {4, 5, 6};
raylib::BoundingBox boundingBox(min, max);
raylib::Vector3 newMin = boundingBox.GetMin();
raylib::Vector3 newMax = boundingBox.GetMax();

AssertEqual(newMin.GetX(), min.x);
AssertEqual(newMin.GetY(), min.y);
AssertEqual(newMin.GetZ(), min.z);

AssertEqual(newMax.GetX(), max.x);
AssertEqual(newMax.GetY(), max.y);
AssertEqual(newMax.GetZ(), max.z);

boundingBox.SetMin({9, 8, 7});
AssertEqual(boundingBox.GetMin(), (raylib::Vector3{9, 8, 7}));
}

TraceLog(LOG_INFO, "TEST: raylib-cpp test");
TraceLog(LOG_INFO, "---------------------");
return 0;
Expand Down
Loading