Files
comaps/geometry/bounding_box.hpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

60 lines
1.5 KiB
C++

#pragma once
#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"
#include "base/visitor.hpp"
#include <limits>
#include <vector>
namespace m2
{
class BoundingBox
{
public:
BoundingBox() = default;
BoundingBox(std::vector<PointD> const & points);
void Add(PointD const & p) { return Add(p.x, p.y); }
void Add(double x, double y);
bool HasPoint(PointD const & p) const { return HasPoint(p.x, p.y); }
bool HasPoint(double x, double y) const;
bool HasPoint(PointD const & p, double eps) const { return HasPoint(p.x, p.y, eps); }
bool HasPoint(double x, double y, double eps) const;
PointD Min() const { return m_min; }
PointD Max() const { return m_max; }
m2::RectD ToRect() const { return {Min(), Max()}; }
std::vector<m2::PointD> Points() const
{
std::vector<m2::PointD> points(4);
points[0] = Min();
points[2] = Max();
points[1] = PointD(points[2].x, points[0].y);
points[3] = PointD(points[0].x, points[2].y);
return points;
}
bool operator==(BoundingBox const & rhs) const
{
return m_min == rhs.m_min && m_max == rhs.m_max;
}
DECLARE_VISITOR(visitor(m_min, "min"), visitor(m_max, "max"))
DECLARE_DEBUG_PRINT(BoundingBox)
private:
// Infinity can not be used with -ffast-math
static double constexpr kLargestDouble = std::numeric_limits<double>::max();
static double constexpr kLowestDouble = std::numeric_limits<double>::lowest();
m2::PointD m_min = m2::PointD(kLargestDouble, kLargestDouble);
m2::PointD m_max = m2::PointD(kLowestDouble, kLowestDouble);
};
} // namespace m2