// Copyright 2016, University of Freiburg, // Chair of Algorithms and Data Structures. // Author: Patrick Brosi #ifndef UTIL_GEO_BOX_H_ #define UTIL_GEO_BOX_H_ #include "./Point.h" namespace util { namespace geo { template class Box { public: // maximum inverse box as default value of box Box() : _ll(std::numeric_limits::max(), std::numeric_limits::max()), _ur(std::numeric_limits::lowest(), std::numeric_limits::lowest()) {} Box(const Point& ll, const Point& ur) : _ll(ll), _ur(ur) {} const Point& getLowerLeft() const { return _ll; } const Point& getUpperRight() const { return _ur; } Point& getLowerLeft() { return _ll; } Point& getUpperRight() { return _ur; } void setLowerLeft(const Point& ll) { _ll = ll; } void setUpperRight(const Point& ur) { _ur = ur; } bool operator==(const Box& b) const { return getLowerLeft() == b.getLowerLeft() && getUpperRight() == b.getUpperRight(); } bool operator!=(const Box& p) const { return !(*this == p); } private: Point _ll, _ur; }; template class RotatedBox { public: RotatedBox() : _box(), _deg(0), _center() {} RotatedBox(const Box& box) : _box(box), _deg(0), _center(Point( (box.getUpperRight().getX() - box.getLowerLeft().getX()) / T(2), (box.getUpperRight().getY() - box.getLowerLeft().getY()) / T(2))) {} RotatedBox(const Point& ll, const Point& ur) : _box(ll, ur), _deg(0), _center(Point((ur.getX() - ll.getX()) / T(2), (ur.getY() - ll.getY()) / T(2))) {} RotatedBox(const Box& box, double deg) : _box(box), _deg(deg), _center(Point( (box.getUpperRight().getX() - box.getLowerLeft().getX()) / T(2), (box.getUpperRight().getY() - box.getLowerLeft().getY()) / T(2))) {} RotatedBox(const Point& ll, const Point& ur, double deg) : _box(ll, ur), _deg(deg), _center(Point((ur.getX() - ll.getX()) / T(2), (ur.getY() - ll.getY()) / T(2))) {} RotatedBox(const Box& box, double deg, const Point& center) : _box(box), _deg(deg), _center(center) {} RotatedBox(const Point& ll, const Point& ur, double deg, const Point& center) : _box(ll, ur), _deg(deg), _center(center) {} const Box& getBox() const { return _box; } Box& getBox() { return _box; } double getDegree() const { return _deg; } const Point& getCenter() const { return _center; } Point& getCenter() { return _center; } void setDegree(double deg) { _deg = deg; } private: Box _box; double _deg; Point _center; }; } // namespace geo } // namespace util #endif // UTIL_GEO_BOX_H_