Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diamond_box.hpp « geometry - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 544353208bf7796fe83158729ca699922280d0ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include "geometry/bounding_box.hpp"
#include "geometry/point2d.hpp"

#include "base/visitor.hpp"

#include <vector>

namespace m2
{
// Bounding box for a set of points on the plane, rotated by 45
// degrees.
class DiamondBox
{
public:
  DiamondBox() = default;
  explicit 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); }

  bool HasPoint(PointD const & p, double eps) const { return HasPoint(p.x, p.y, eps); }

  bool HasPoint(double x, double y, double eps) const
  {
    return m_box.HasPoint(x + y, x - y, 2 * eps);
  }

  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, "box"))
  DECLARE_DEBUG_PRINT(DiamondBox)

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;
};
}  // namespace m2