@@ -262,6 +262,13 @@ public:
{
}
+ constexpr Rectangle(const Point &point1, const Point &point2)
+ : Rectangle(std::min(point1.x, point2.x), std::max(point1.y, point2.y),
+ std::max(point1.x, point2.x) - std::min(point1.x, point2.x),
+ std::max(point1.y, point2.y) - std::min(point1.y, point2.y))
+ {
+ }
+
int x;
int y;
unsigned int width;
@@ -629,6 +629,13 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)
* \param[in] size The desired Rectangle size
*/
+/**
+ * \fn Rectangle::Rectangle(const Point &point1, const Point &point2)
+ * \brief Construct a Rectangle with the two given points
+ * \param[in] point1 One corner point of the rectangle
+ * \param[in] point2 The diagonal corner point from \a point1
+ */
+
/**
* \var Rectangle::x
* \brief The horizontal coordinate of the rectangle's top-left corner
@@ -481,6 +481,20 @@ protected:
return TestFail;
}
+ Point topLeft(3, 3);
+ Point bottomRight(30, 30);
+ Point topRight(30, 3);
+ Point bottomLeft(3, 30);
+ Rectangle rect1(topLeft, bottomRight);
+ Rectangle rect2(topRight, bottomLeft);
+ Rectangle rect3(bottomRight, topLeft);
+ Rectangle rect4(bottomLeft, topRight);
+
+ if (rect1 != rect2 || rect1 != rect3 || rect1 != rect4) {
+ cout << "Point-from-point construction failed" << endl;
+ return TestFail;
+ }
+
return TestPass;
}
};