diff --git a/examples/shapes/src/primitives/Rectangle.cpp b/examples/shapes/src/primitives/Rectangle.cpp index 8256830..afe8d59 100644 --- a/examples/shapes/src/primitives/Rectangle.cpp +++ b/examples/shapes/src/primitives/Rectangle.cpp @@ -1,9 +1,10 @@ +#include #include + #include "Point.hpp" #include "Rectangle.hpp" -Rectangle::Rectangle(double width, double height) : - Shape<2>() +Rectangle::Rectangle(double width, double height) : Shape<2>() { this->mVertices.push_back(std::make_shared >(0.0, 0.0)); this->mVertices.push_back(std::make_shared >(width, 0.0)); @@ -11,7 +12,16 @@ Rectangle::Rectangle(double width, double height) : this->mVertices.push_back(std::make_shared >(0.0, height)); } -Rectangle::~Rectangle() +Rectangle::Rectangle(const std::vector > > points) : Shape<2>() { + assert(points.size() == 4); + + for (unsigned i = 0; i < points.size(); ++i) + { + this->mVertices.push_back(points[i]); + } +} +Rectangle::~Rectangle() +{ } diff --git a/examples/shapes/src/primitives/Rectangle.hpp b/examples/shapes/src/primitives/Rectangle.hpp index a990a90..8f7ac91 100644 --- a/examples/shapes/src/primitives/Rectangle.hpp +++ b/examples/shapes/src/primitives/Rectangle.hpp @@ -1,6 +1,7 @@ #ifndef _RECTANGLE_HPP #define _RECTANGLE_HPP +#include "Point.hpp" #include "Shape.hpp" /** @@ -10,17 +11,20 @@ class Rectangle : public Shape<2> { public: - /** * Default Constructor */ Rectangle(double width = 2.0, double height = 1.0); + /** + * Construct from points + */ + Rectangle(const std::vector > > points = {}); + /** * Destructor */ ~Rectangle(); - }; -#endif // _RECTANGLE_HPP +#endif // _RECTANGLE_HPP diff --git a/examples/shapes/src/python/test/test_classes.py b/examples/shapes/src/python/test/test_classes.py index 3f9a134..4241f1f 100644 --- a/examples/shapes/src/python/test/test_classes.py +++ b/examples/shapes/src/python/test/test_classes.py @@ -12,10 +12,17 @@ def testGeometry(self): p0 = pyshapes.geometry.Point2() self.assertTrue(p0.GetLocation() == [0.0, 0.0]) - p1 = pyshapes.geometry.Point2(0.0, 0.0) - p2 = pyshapes.geometry.Point2(1.0, 0.0) - p3 = pyshapes.geometry.Point2(0.0, 1.0) + p1 = pyshapes.geometry.Point2(5.0, 0.0) + self.assertTrue(p1.GetLocation() == [5.0, 0.0]) + + p2 = pyshapes.geometry.Point2(5.0, 5.0) + self.assertTrue(p2.GetLocation() == [5.0, 5.0]) + + p3 = pyshapes.geometry.Point2(0.0, 5.0) + self.assertTrue(p3.GetLocation() == [0.0, 5.0]) + points = [p1, p2, p3] + triangle = pyshapes.primitives.Shape2() triangle.SetVertices(points) self.assertTrue(len(triangle.rGetVertices()) == 3) @@ -23,6 +30,9 @@ def testGeometry(self): rectangle = pyshapes.primitives.Rectangle(5.0, 10.0) self.assertTrue(len(rectangle.rGetVertices()) == 4) + rectangle = pyshapes.primitives.Rectangle([p0, p1, p2, p3]) + self.assertTrue(rectangle.rGetVertices() == [p0, p1, p2, p3]) + cuboid = pyshapes.primitives.Cuboid(5.0, 10.0, 20.0) self.assertTrue(len(cuboid.rGetVertices()) == 8) diff --git a/examples/shapes/wrapper/primitives/Rectangle.cppwg.cpp b/examples/shapes/wrapper/primitives/Rectangle.cppwg.cpp index 6bb2f11..051c21d 100644 --- a/examples/shapes/wrapper/primitives/Rectangle.cppwg.cpp +++ b/examples/shapes/wrapper/primitives/Rectangle.cppwg.cpp @@ -11,5 +11,6 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); void register_Rectangle_class(py::module &m){ py::class_ , Shape<2> >(m, "Rectangle") .def(py::init(), py::arg("width") = 2., py::arg("height") = 1.) + .def(py::init<::std::vector>> const >(), py::arg("points") = ::std::vector>> {}) ; }