diff options
Diffstat (limited to 'geometry/diamond_box.hpp')
-rw-r--r-- | geometry/diamond_box.hpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/geometry/diamond_box.hpp b/geometry/diamond_box.hpp index 5bbd4d2f6f..436eca4009 100644 --- a/geometry/diamond_box.hpp +++ b/geometry/diamond_box.hpp @@ -3,6 +3,11 @@ #include "geometry/bounding_box.hpp" #include "geometry/point2d.hpp" +#include "base/visitor.hpp" + +#include <string> +#include <vector> + namespace m2 { // Bounding box for a set of points on the plane, rotated by 45 @@ -10,13 +15,35 @@ namespace m2 class DiamondBox { public: + DiamondBox() = default; + DiamondBox(std::vector<PointD> const & points); + void Add(PointD const & p) { return Add(p.x, p.y); } void Add(double x, double y) { return m_box.Add(x + y, x - y); } bool HasPoint(PointD const & p) const { return HasPoint(p.x, p.y); } bool HasPoint(double x, double y) const { return m_box.HasPoint(x + y, x - y); } + std::vector<m2::PointD> Points() const + { + auto points = m_box.Points(); + for (auto & p : points) + p = ToOrig(p); + return points; + } + + bool operator==(DiamondBox const & rhs) const { return m_box == rhs.m_box; } + + DECLARE_VISITOR(visitor(m_box)) + private: + static m2::PointD ToOrig(m2::PointD const & p) + { + return m2::PointD(0.5 * (p.x + p.y), 0.5 * (p.x - p.y)); + } + BoundingBox m_box; }; + +std::string DebugPrint(DiamondBox const & dbox); } // namespace m2 |