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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-10-09 16:15:12 +0300
committerVladimir Byko-Ianko <bykoianko@gmail.com>2017-10-13 11:55:26 +0300
commitc3496e52f24a94a0d6bf472ce62e66424ed0f1ee (patch)
tree326376a3aa326e7f25a691e4cdd0fa016cec60e4 /geometry
parent864fd16ddd55b933e3bc9f4c2c0978a94bea9e0c (diff)
[search] CitiesBoundaryTable is exposed to TestMwmBuilder.
Diffstat (limited to 'geometry')
-rw-r--r--geometry/bounding_box.cpp5
-rw-r--r--geometry/bounding_box.hpp3
-rw-r--r--geometry/calipers_box.cpp25
-rw-r--r--geometry/calipers_box.hpp12
-rw-r--r--geometry/diamond_box.hpp3
5 files changed, 31 insertions, 17 deletions
diff --git a/geometry/bounding_box.cpp b/geometry/bounding_box.cpp
index 5a3c5dee69..ef0e7ee0d0 100644
--- a/geometry/bounding_box.cpp
+++ b/geometry/bounding_box.cpp
@@ -24,4 +24,9 @@ bool BoundingBox::HasPoint(double x, double y) const
{
return x >= m_min.x && x <= m_max.x && y >= m_min.y && y <= m_max.y;
}
+
+bool BoundingBox::HasPoint(double x, double y, double eps) const
+{
+ return x >= m_min.x - eps && x <= m_max.x + eps && y >= m_min.y - eps && y <= m_max.y + eps;
+}
} // namespace m2
diff --git a/geometry/bounding_box.hpp b/geometry/bounding_box.hpp
index eaf48a85b6..2b704d0557 100644
--- a/geometry/bounding_box.hpp
+++ b/geometry/bounding_box.hpp
@@ -21,6 +21,9 @@ public:
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; }
diff --git a/geometry/calipers_box.cpp b/geometry/calipers_box.cpp
index ddbb42bc11..639ee96b34 100644
--- a/geometry/calipers_box.cpp
+++ b/geometry/calipers_box.cpp
@@ -22,15 +22,10 @@ static_assert(numeric_limits<double>::has_infinity, "");
double const kInf = numeric_limits<double>::infinity();
-// 1e-12 is used here because of we are going to use the box on
-// Mercator plane, where the precision of all coords is 1e-5, so we
-// are off by two orders of magnitude from the precision of data.
-double const kEps = 1e-12;
-
// Checks whether (p1 - p) x (p2 - p) >= 0.
-bool IsCCW(PointD const & p1, PointD const & p2, PointD const & p)
+bool IsCCW(PointD const & p1, PointD const & p2, PointD const & p, double eps)
{
- return robust::OrientedS(p1, p2, p) > -kEps;
+ return robust::OrientedS(p1, p2, p) > -eps;
}
PointD Ort(PointD const & p) { return PointD(-p.y, p.x); }
@@ -48,15 +43,15 @@ void ForEachRect(ConvexHull const & hull, Fn && fn)
auto const ab = hull.SegmentAt(i).Dir();
j = max(j, i + 1);
- while (DotProduct(ab, hull.SegmentAt(j).Dir()) > kEps)
+ while (DotProduct(ab, hull.SegmentAt(j).Dir()) > CalipersBox::kEps)
++j;
k = max(k, j);
- while (CrossProduct(ab, hull.SegmentAt(k).Dir()) > kEps)
+ while (CrossProduct(ab, hull.SegmentAt(k).Dir()) > CalipersBox::kEps)
++k;
l = max(l, k);
- while (DotProduct(ab, hull.SegmentAt(l).Dir()) < -kEps)
+ while (DotProduct(ab, hull.SegmentAt(l).Dir()) < -CalipersBox::kEps)
++l;
auto const oab = Ort(ab);
@@ -66,7 +61,7 @@ void ForEachRect(ConvexHull const & hull, Fn && fn)
for (size_t i = 0; i < lines.size(); ++i)
{
auto const j = (i + 1) % lines.size();
- auto result = LineIntersector::Intersect(lines[i], lines[j], kEps);
+ auto result = LineIntersector::Intersect(lines[i], lines[j], CalipersBox::kEps);
if (result.m_type == LineIntersector::Result::Type::One)
corners.push_back(result.m_point);
}
@@ -125,7 +120,7 @@ CalipersBox::CalipersBox(vector<PointD> const & points) : m_points({})
m_points = bestPoints;
}
-bool CalipersBox::HasPoint(PointD const & p) const
+bool CalipersBox::HasPoint(PointD const & p, double eps) const
{
auto const n = m_points.size();
@@ -133,16 +128,16 @@ bool CalipersBox::HasPoint(PointD const & p) const
return false;
if (n == 1)
- return AlmostEqualAbs(m_points[0], p, kEps);
+ return AlmostEqualAbs(m_points[0], p, eps);
if (n == 2)
- return IsPointOnSegmentEps(p, m_points[0], m_points[1], kEps);
+ return IsPointOnSegmentEps(p, m_points[0], m_points[1], eps);
for (size_t i = 0; i < n; ++i)
{
auto const & a = m_points[i];
auto const & b = m_points[(i + 1) % n];
- if (!IsCCW(b, p, a))
+ if (!IsCCW(b, p, a, eps))
return false;
}
return true;
diff --git a/geometry/calipers_box.hpp b/geometry/calipers_box.hpp
index d66e354186..61dccff44f 100644
--- a/geometry/calipers_box.hpp
+++ b/geometry/calipers_box.hpp
@@ -17,13 +17,21 @@ namespace m2
class CalipersBox
{
public:
+ // 1e-12 is used here because of we are going to use the box on
+ // Mercator plane, where the precision of all coords is 1e-5, so we
+ // are off by two orders of magnitude from the precision of data.
+ static double constexpr kEps = 1e-12;
+
CalipersBox() = default;
explicit CalipersBox(std::vector<PointD> const & points);
std::vector<PointD> const & Points() const { return m_points; }
- bool HasPoint(PointD const & p) const;
- bool HasPoint(double x, double y) const { return HasPoint(PointD(x, y)); }
+ bool HasPoint(PointD const & p) const { return HasPoint(p, kEps /* eps */); }
+ bool HasPoint(double x, double y) const { return HasPoint(m2::PointD(x, y)); }
+
+ bool HasPoint(PointD const & p, double eps) const;
+ bool HasPoint(double x, double y, double eps) const { return HasPoint(PointD(x, y), eps); }
bool operator==(CalipersBox const & rhs) const { return m_points == rhs.m_points; }
diff --git a/geometry/diamond_box.hpp b/geometry/diamond_box.hpp
index 29aa5b8fcf..6c9b3cdf48 100644
--- a/geometry/diamond_box.hpp
+++ b/geometry/diamond_box.hpp
@@ -23,6 +23,9 @@ public:
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, eps); }
+
std::vector<m2::PointD> Points() const
{
auto points = m_box.Points();