diff --git a/doc/python/magnum.math.rst b/doc/python/magnum.math.rst index 64fb74e..62af181 100644 --- a/doc/python/magnum.math.rst +++ b/doc/python/magnum.math.rst @@ -212,8 +212,8 @@ - :py:`mat[a][b] = c` on matrices doesn't do the expected thing, use :py:`mat[a, b] = c` instead - - :cpp:`Math::BoolVector::set()` doesn't exist, use ``[]`` instead - - While both boolean and bitwise operations on :cpp:`Math::BoolVector` + - :cpp:`Math::BitVector::set()` doesn't exist, use ``[]`` instead + - While both boolean and bitwise operations on :cpp:`Math::BitVector` behave the same to ensure consistency in generic code, this is not possible to do in Python. Here the boolean operations behave like if :py:`any()` was applied before doing the operation. diff --git a/src/python/magnum/__init__.py b/src/python/magnum/__init__.py index 2a47011..399b1ad 100644 --- a/src/python/magnum/__init__.py +++ b/src/python/magnum/__init__.py @@ -51,7 +51,7 @@ if 'scenegraph' in globals(): __all__ = [ 'Deg', 'Rad', - 'BoolVector2', 'BoolVector3', 'BoolVector4', + 'BitVector2', 'BitVector3', 'BitVector4', 'Vector2', 'Vector3', 'Vector4', 'Vector2d', 'Vector3d', 'Vector4d', 'Vector2i', 'Vector3i', 'Vector4i', diff --git a/src/python/magnum/math.cpp b/src/python/magnum/math.cpp index d261ec5..5c0e3e0 100644 --- a/src/python/magnum/math.cpp +++ b/src/python/magnum/math.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -447,10 +447,10 @@ void math(py::module_& root, py::module_& m) { py::implicitly_convertible(); py::implicitly_convertible(); - /* BoolVector */ - py::class_> boolVector2{root, "BoolVector2", "Two-component bool vector"}; - py::class_> boolVector3{root, "BoolVector3", "Three-component bool vector"}; - py::class_> boolVector4{root, "BoolVector4", "Four-component bool vector"}; + /* BitVector */ + py::class_> boolVector2{root, "BitVector2", "Two-component bool vector"}; + py::class_> boolVector3{root, "BitVector3", "Three-component bool vector"}; + py::class_> boolVector4{root, "BitVector4", "Four-component bool vector"}; boolVector(m, boolVector2); boolVector(m, boolVector3); boolVector(m, boolVector4); diff --git a/src/python/magnum/math.matrix.h b/src/python/magnum/math.matrix.h index 6a26103..683fce0 100644 --- a/src/python/magnum/math.matrix.h +++ b/src/python/magnum/math.matrix.h @@ -173,7 +173,7 @@ template void rectangularMatrix(py::class_& c) { Type construction by slicing or expanding differently sized matrices row() / setRow() (function? that's ugly. property? not sure how) - component-wise operations (would need BoolVector6 ... BoolVector16) + component-wise operations (would need BitVector6 ... BitVector16) ij() (doesn't make sense in generic code as we don't have Matrix1) */ diff --git a/src/python/magnum/math.vector.h b/src/python/magnum/math.vector.h index a38803e..a1d2a21 100644 --- a/src/python/magnum/math.vector.h +++ b/src/python/magnum/math.vector.h @@ -223,8 +223,8 @@ template void vector(py::module_& m, py::class_& c) { .def("lerp", [](const T& a, const T& b, Double t) { return T{Math::lerp(a, b, t)}; }, "Linear interpolation of two values", py::arg("a"), py::arg("b"), py::arg("t")) - /* The BoolVector overload has to be before the bool to match first */ - .def("lerp", [](const T& a, const T& b, Math::BoolVector t) { + /* The BitVector overload has to be before the bool to match first */ + .def("lerp", [](const T& a, const T& b, Math::BitVector t) { return T{Math::lerp(a, b, t)}; }, "Linear interpolation of two values", py::arg("a"), py::arg("b"), py::arg("t")) .def("lerp", [](const T& a, const T& b, bool t) { diff --git a/src/python/magnum/test/test_math.py b/src/python/magnum/test/test_math.py index 5798515..187534f 100644 --- a/src/python/magnum/test/test_math.py +++ b/src/python/magnum/test/test_math.py @@ -69,39 +69,39 @@ class Angle(unittest.TestCase): def test_repr(self): self.assertEqual(repr(Deg(45.3)), 'Deg(45.3)') -class BoolVector(unittest.TestCase): +class BitVector(unittest.TestCase): def test_init(self): - a = BoolVector2() - b = BoolVector2.zero_init() - c = BoolVector2(0b11) + a = BitVector2() + b = BitVector2.zero_init() + c = BitVector2(0b11) self.assertFalse(a.any()) self.assertTrue(c.all()) - self.assertEqual(a, BoolVector2(0b00)) - self.assertEqual(b, BoolVector2(0b00)) - self.assertEqual(c, BoolVector2(0b11)) + self.assertEqual(a, BitVector2(0b00)) + self.assertEqual(b, BitVector2(0b00)) + self.assertEqual(c, BitVector2(0b11)) def test_length(self): - self.assertEqual(BoolVector3.__len__(), 3) - #self.assertEqual(len(BoolVector3), 3) TODO: Y not? - self.assertEqual(len(BoolVector4()), 4) + self.assertEqual(BitVector3.__len__(), 3) + #self.assertEqual(len(BitVector3), 3) TODO: Y not? + self.assertEqual(len(BitVector4()), 4) def test_set_get(self): - a = BoolVector4(0b1010) + a = BitVector4(0b1010) self.assertEqual(a[1], 1) a[2] = True - self.assertEqual(a, BoolVector4(0b1110)) + self.assertEqual(a, BitVector4(0b1110)) def test_iterate(self): - a = [i for i in BoolVector4(0b1010)] + a = [i for i in BitVector4(0b1010)] self.assertEqual(a, [False, True, False, True]) def test_ops(self): - a = BoolVector3(0b101) | BoolVector3(0b010) - self.assertEqual(a, BoolVector3(0b111)) + a = BitVector3(0b101) | BitVector3(0b010) + self.assertEqual(a, BitVector3(0b111)) def test_repr(self): - self.assertEqual(repr(BoolVector4(0b0101)), 'BoolVector(0b0101)') + self.assertEqual(repr(BitVector4(0b0101)), 'BitVector(0b0101)') class Constants(unittest.TestCase): def test(self): @@ -177,8 +177,8 @@ class Functions(unittest.TestCase): self.assertEqual(math.select(Rad(2.0), Rad(5.0), 0.6), Rad(2.0)) def test_vector(self): - self.assertEqual(math.isinf((math.inf, math.nan)), BoolVector2(0b01)) - self.assertEqual(math.isnan((math.inf, math.nan)), BoolVector2(0b10)) + self.assertEqual(math.isinf((math.inf, math.nan)), BitVector2(0b01)) + self.assertEqual(math.isnan((math.inf, math.nan)), BitVector2(0b10)) self.assertEqual(math.min((15.0, 0.5), (3.0, 1.0)), (3.0, 0.5)) self.assertEqual(math.min((15.0, 0.5), 3.0), (3.0, 0.5)) @@ -200,12 +200,12 @@ class Functions(unittest.TestCase): self.assertEqual(math.fmod((5.1, 1.5), (3.0, 1.0)), (2.1, 0.5)) self.assertEqual(math.lerp((2.0, 1.0), (5.0, 2.0), 0.5), (3.5, 1.5)) - self.assertEqual(math.lerp((2.0, 1.0), (5.0, 2.0), BoolVector2(0b01)), (5.0, 1.0)) + self.assertEqual(math.lerp((2.0, 1.0), (5.0, 2.0), BitVector2(0b01)), (5.0, 1.0)) self.assertEqual(math.lerp((2.0, 1.0), (5.0, 2.0), False), (2.0, 1.0)) self.assertEqual(math.lerp((2, 1), (5, 2), 0.5), (3, 1)) - self.assertEqual(math.lerp((2, 1), (5, 2), BoolVector2(0b01)), (5, 1)) + self.assertEqual(math.lerp((2, 1), (5, 2), BitVector2(0b01)), (5, 1)) self.assertEqual(math.lerp((2, 1), (5, 2), True), (5, 2)) - self.assertEqual(math.lerp(BoolVector4(0b1001), BoolVector4(0b0110), BoolVector4(0b0101)), BoolVector4(0b1100)) + self.assertEqual(math.lerp(BitVector4(0b1001), BitVector4(0b0110), BitVector4(0b0101)), BitVector4(0b1100)) self.assertEqual(math.lerp_inverted((2.0, 1.0), (5.0, 2.0), (3.5, 1.5)), (0.5, 0.5)) self.assertEqual(math.select((2.0, 1.0), (5.0, 2.0), 0.6), (2.0, 1.0)) self.assertEqual(math.select((2, 1), (5, 2), 1.0), (5, 2))