diff --git a/src/python/magnum/math.vector.h b/src/python/magnum/math.vector.h index a21b4d8..a04db61 100644 --- a/src/python/magnum/math.vector.h +++ b/src/python/magnum/math.vector.h @@ -533,6 +533,19 @@ template void color3(py::class_, Math::Vector3>& c) return Math::Color3::fromSrgb(srgb); }, "Create linear RGB color from 24-bit sRGB representation", py::arg("srgb")) + .def_static("red", &Math::Color3::red, + "Red color", py::arg("red") = Math::Implementation::fullChannel()) + .def_static("green", &Math::Color3::green, + "Green color", py::arg("green") = Math::Implementation::fullChannel()) + .def_static("blue", &Math::Color3::blue, + "Blue color", py::arg("blue") = Math::Implementation::fullChannel()) + .def_static("cyan", &Math::Color3::cyan, + "Cyan color", py::arg("red") = T(0)) + .def_static("magenta", &Math::Color3::magenta, + "Magenta color", py::arg("green") = T(0)) + .def_static("yellow", &Math::Color3::yellow, + "Yellow color", py::arg("blue") = T(0)) + /* Accessors */ .def("to_srgb_int", &Math::Color3::toSrgbInt, "Convert to 32-bit integral sRGB representation") @@ -583,6 +596,31 @@ template void color4(py::class_, Math::Vector4>& c) return Math::Color4::fromSrgb(srgb, a); }, "Create linear RGBA color from 32-bit sRGB a alpha representation", py::arg("srgb"), py::arg("a") = Math::Implementation::fullChannel()) + .def_static("red", &Math::Color4::red, + "Red color", + py::arg("red") = Math::Implementation::fullChannel(), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("green", &Math::Color4::green, + "Green color", + py::arg("green") = Math::Implementation::fullChannel(), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("blue", &Math::Color4::blue, + "Blue color", + py::arg("blue") = Math::Implementation::fullChannel(), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("cyan", &Math::Color4::cyan, + "Cyan color", + py::arg("red") = T(0), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("magenta", &Math::Color4::magenta, + "Magenta color", + py::arg("green") = T(0), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("yellow", &Math::Color4::yellow, + "Yellow color", + py::arg("blue") = T(0), + py::arg("alpha") = Math::Implementation::fullChannel()) + /* Accessors */ .def("to_srgb_alpha_int", &Math::Color4::toSrgbAlphaInt, "Convert to 32-bit integral sRGB + linear alpha representation") diff --git a/src/python/magnum/test/test_math.py b/src/python/magnum/test/test_math.py index ac08c43..74c398f 100644 --- a/src/python/magnum/test/test_math.py +++ b/src/python/magnum/test/test_math.py @@ -355,6 +355,22 @@ class Color3_(unittest.TestCase): self.assertEqual(c2, Color3(0.5, 0.75, 1.0)) self.assertEqual(c3, Color3(0.5, 0.75, 1.0)) + def test_init_primaries(self): + red = Color3.red(0.5) + cyan = Color3.cyan(0.5) + self.assertEqual(red, Color3(0.5, 0.0, 0.0)) + self.assertEqual(cyan, Color3(0.5, 1.0, 1.0)) + + green = Color3.green(0.5) + magenta = Color3.magenta(0.5) + self.assertEqual(green, Color3(0.0, 0.5, 0.0)) + self.assertEqual(magenta, Color3(1.0, 0.5, 1.0)) + + blue = Color3.blue(0.5) + yellow = Color3.yellow(0.5) + self.assertEqual(blue, Color3(0.0, 0.0, 0.5)) + self.assertEqual(yellow, Color3(1.0, 1.0, 0.5)) + def test_srgb(self): # Cross-checked with C++ tests a = Color3.from_srgb(0xf32a80) @@ -409,6 +425,22 @@ class Color4_(unittest.TestCase): self.assertEqual(e4, Color4(0.5, 0.75, 0.875, 0.9)) self.assertEqual(e5, Color4(0.5, 0.75, 0.875, 0.9)) + def test_init_primaries(self): + red = Color4.red(0.5, 0.75) + cyan = Color4.cyan(0.5, 0.75) + self.assertEqual(red, Color4(0.5, 0.0, 0.0, 0.75)) + self.assertEqual(cyan, Color4(0.5, 1.0, 1.0, 0.75)) + + green = Color4.green(0.5, 0.75) + magenta = Color4.magenta(0.5, 0.75) + self.assertEqual(green, Color4(0.0, 0.5, 0.0, 0.75)) + self.assertEqual(magenta, Color4(1.0, 0.5, 1.0, 0.75)) + + blue = Color4.blue(0.5, 0.75) + yellow = Color4.yellow(0.5, 0.75) + self.assertEqual(blue, Color4(0.0, 0.0, 0.5, 0.75)) + self.assertEqual(yellow, Color4(1.0, 1.0, 0.5, 0.75)) + def test_srgb(self): # Cross-checked with C++ tests a = Color4.from_srgb(0xf32a80)