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-09-20 17:24:11 +0300
committerRoman Kuznetsov <r.kuznetsow@gmail.com>2017-09-22 14:07:59 +0300
commitff84731e11a559c38d0381077e997117e0b1d438 (patch)
tree8c9f5125919a1f5b82160e4bfd06de46ec4e32fb /geometry
parent41889bb72a43eccb14e9c3a4b93bcd21153cb14b (diff)
Review fixes.
Diffstat (limited to 'geometry')
-rw-r--r--geometry/CMakeLists.txt10
-rw-r--r--geometry/bbox.cpp26
-rw-r--r--geometry/bounding_box.cpp27
-rw-r--r--geometry/bounding_box.hpp (renamed from geometry/bbox.hpp)16
-rw-r--r--geometry/calipers_box.cpp (renamed from geometry/cbox.cpp)58
-rw-r--r--geometry/calipers_box.hpp28
-rw-r--r--geometry/cbox.hpp22
-rw-r--r--geometry/convex_hull.cpp28
-rw-r--r--geometry/convex_hull.hpp8
-rw-r--r--geometry/dbox.hpp20
-rw-r--r--geometry/diamond_box.hpp22
-rw-r--r--geometry/geometry.pro10
-rw-r--r--geometry/geometry_tests/CMakeLists.txt6
-rw-r--r--geometry/geometry_tests/bbox_tests.cpp35
-rw-r--r--geometry/geometry_tests/bounding_box_tests.cpp36
-rw-r--r--geometry/geometry_tests/calipers_box_tests.cpp (renamed from geometry/geometry_tests/cbox_tests.cpp)46
-rw-r--r--geometry/geometry_tests/convex_hull_tests.cpp6
-rw-r--r--geometry/geometry_tests/dbox_tests.cpp53
-rw-r--r--geometry/geometry_tests/diamond_box_tests.cpp53
-rw-r--r--geometry/geometry_tests/geometry_tests.pro6
-rw-r--r--geometry/geometry_tests/line2d_tests.cpp12
-rw-r--r--geometry/line2d.cpp10
-rw-r--r--geometry/line2d.hpp16
-rw-r--r--geometry/segment2d.cpp6
-rw-r--r--geometry/segment2d.hpp13
25 files changed, 292 insertions, 281 deletions
diff --git a/geometry/CMakeLists.txt b/geometry/CMakeLists.txt
index 4cef9494ec..5985cef06e 100644
--- a/geometry/CMakeLists.txt
+++ b/geometry/CMakeLists.txt
@@ -8,10 +8,10 @@ set(
angles.hpp
any_rect2d.hpp
avg_vector.hpp
- bbox.cpp
- bbox.hpp
- cbox.cpp
- cbox.hpp
+ bounding_box.cpp
+ bounding_box.hpp
+ calipers_box.cpp
+ calipers_box.hpp
cellid.hpp
clipping.cpp
clipping.hpp
@@ -19,7 +19,7 @@ set(
convex_hull.hpp
covering.hpp
covering_utils.hpp
- dbox.hpp
+ diamond_box.hpp
distance.hpp
distance_on_sphere.cpp
distance_on_sphere.hpp
diff --git a/geometry/bbox.cpp b/geometry/bbox.cpp
deleted file mode 100644
index 8aea3d1e02..0000000000
--- a/geometry/bbox.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "geometry/bbox.hpp"
-
-#include <algorithm>
-using namespace std;
-
-namespace m2
-{
-BBox::BBox(std::vector<m2::PointD> const & points)
-{
- for (auto const & p : points)
- Add(p);
-}
-
-void BBox::Add(double x, double y)
-{
- m_minX = std::min(m_minX, x);
- m_minY = std::min(m_minY, y);
- m_maxX = std::max(m_maxX, x);
- m_maxY = std::max(m_maxY, y);
-}
-
-bool BBox::IsInside(double x, double y) const
-{
- return x >= m_minX && x <= m_maxX && y >= m_minY && y <= m_maxY;
-}
-} // namespace m2
diff --git a/geometry/bounding_box.cpp b/geometry/bounding_box.cpp
new file mode 100644
index 0000000000..957f51ff6b
--- /dev/null
+++ b/geometry/bounding_box.cpp
@@ -0,0 +1,27 @@
+#include "geometry/bounding_box.hpp"
+
+#include <algorithm>
+
+using namespace std;
+
+namespace m2
+{
+BoundingBox::BoundingBox(vector<PointD> const & points)
+{
+ for (auto const & p : points)
+ Add(p);
+}
+
+void BoundingBox::Add(double x, double y)
+{
+ m_minX = min(m_minX, x);
+ m_minY = min(m_minY, y);
+ m_maxX = max(m_maxX, x);
+ m_maxY = max(m_maxY, y);
+}
+
+bool BoundingBox::HasPoint(double x, double y) const
+{
+ return x >= m_minX && x <= m_maxX && y >= m_minY && y <= m_maxY;
+}
+} // namespace m2
diff --git a/geometry/bbox.hpp b/geometry/bounding_box.hpp
index ee681a194f..a343e93093 100644
--- a/geometry/bbox.hpp
+++ b/geometry/bounding_box.hpp
@@ -7,20 +7,20 @@
namespace m2
{
-class BBox
+class BoundingBox
{
public:
- BBox() = default;
- BBox(std::vector<m2::PointD> const & points);
+ BoundingBox() = default;
+ BoundingBox(std::vector<PointD> const & points);
- void Add(m2::PointD const & p) { return Add(p.x, p.y); }
+ void Add(PointD const & p) { return Add(p.x, p.y); }
void Add(double x, double y);
- bool IsInside(m2::PointD const & p) const { return IsInside(p.x, p.y); }
- bool IsInside(double x, double y) const;
+ bool HasPoint(PointD const & p) const { return HasPoint(p.x, p.y); }
+ bool HasPoint(double x, double y) const;
- m2::PointD Min() const { return m2::PointD(m_minX, m_minY); }
- m2::PointD Max() const { return m2::PointD(m_maxX, m_maxY); }
+ PointD Min() const { return PointD(m_minX, m_minY); }
+ PointD Max() const { return PointD(m_maxX, m_maxY); }
private:
static_assert(std::numeric_limits<double>::has_infinity, "");
diff --git a/geometry/cbox.cpp b/geometry/calipers_box.cpp
index 700fafe126..046c81a89f 100644
--- a/geometry/cbox.cpp
+++ b/geometry/calipers_box.cpp
@@ -1,13 +1,12 @@
-#include "geometry/cbox.hpp"
+#include "geometry/calipers_box.hpp"
-#include "geometry/bbox.hpp"
+#include "geometry/bounding_box.hpp"
#include "geometry/convex_hull.hpp"
#include "geometry/line2d.hpp"
#include "geometry/polygon.hpp"
#include "geometry/segment2d.hpp"
#include "base/assert.hpp"
-#include "base/logging.hpp"
#include <algorithm>
#include <array>
@@ -22,6 +21,10 @@ namespace
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.
@@ -32,6 +35,8 @@ bool IsCCW(PointD const & p1, PointD const & p2, PointD const & p)
PointD Ort(PointD const & p) { return PointD(-p.y, p.x); }
+// For each facet of the |hull| calls |fn| with the smallest rectangle
+// containing the hull and with one side collinear to the facet.
template <typename Fn>
void ForEachRect(ConvexHull const & hull, Fn && fn)
{
@@ -57,37 +62,39 @@ void ForEachRect(ConvexHull const & hull, Fn && fn)
auto const oab = Ort(ab);
array<Line2D, 4> const lines = {{Line2D(hull.PointAt(i), ab), Line2D(hull.PointAt(j), oab),
Line2D(hull.PointAt(k), ab), Line2D(hull.PointAt(l), oab)}};
- vector<m2::PointD> corners;
- for (size_t u = 0; u < lines.size(); ++u)
+ vector<PointD> corners;
+ for (size_t i = 0; i < lines.size(); ++i)
{
- for (size_t v = u + 1; v < lines.size(); ++v)
- {
- auto result = LineIntersector::Intersect(lines[u], lines[v], kEps);
- if (result.m_type == LineIntersector::Result::Type::Single)
- corners.push_back(result.m_point);
- }
+ auto const j = (i + 1) % lines.size();
+ auto result = LineIntersector::Intersect(lines[i], lines[j], kEps);
+ if (result.m_type == LineIntersector::Result::Type::One)
+ corners.push_back(result.m_point);
}
- ConvexHull rect(corners);
- if (rect.Size() == 4)
- fn(rect.Points());
+ if (corners.size() != 4)
+ continue;
+
+ auto const it = min_element(corners.begin(), corners.end());
+ rotate(corners.begin(), it, corners.end());
+
+ fn(corners);
}
}
} // namespace
-CBox::CBox(vector<m2::PointD> const & points) : m_points({})
+CalipersBox::CalipersBox(vector<PointD> const & points) : m_points({})
{
- ConvexHull hull(points);
+ ConvexHull hull(points, kEps);
- if (hull.Size() <= 4)
+ if (hull.Size() < 4)
{
m_points = hull.Points();
return;
}
double bestArea = kInf;
- vector<m2::PointD> bestPoints;
- ForEachRect(hull, [&](vector<m2::PointD> const & points) {
+ vector<PointD> bestPoints;
+ ForEachRect(hull, [&](vector<PointD> const & points) {
ASSERT_EQUAL(points.size(), 4, ());
double const area = GetPolygonArea(points.begin(), points.end());
if (area < bestArea)
@@ -99,7 +106,7 @@ CBox::CBox(vector<m2::PointD> const & points) : m_points({})
if (bestPoints.empty())
{
- BBox bbox(points);
+ BoundingBox bbox(points);
auto const min = bbox.Min();
auto const max = bbox.Max();
@@ -108,9 +115,9 @@ CBox::CBox(vector<m2::PointD> const & points) : m_points({})
m_points.resize(4);
m_points[0] = min;
- m_points[1] = m_points[0] + m2::PointD(width, 0);
- m_points[2] = m_points[1] + m2::PointD(0, height);
- m_points[3] = m_points[0] + m2::PointD(0, height);
+ m_points[1] = m_points[0] + PointD(width, 0);
+ m_points[2] = m_points[1] + PointD(0, height);
+ m_points[3] = m_points[0] + PointD(0, height);
return;
}
@@ -118,7 +125,7 @@ CBox::CBox(vector<m2::PointD> const & points) : m_points({})
m_points = bestPoints;
}
-bool CBox::IsInside(m2::PointD const & p) const
+bool CalipersBox::HasPoint(PointD const & p) const
{
auto const n = m_points.size();
@@ -131,7 +138,8 @@ bool CBox::IsInside(m2::PointD const & p) const
if (n == 2)
return IsPointOnSegmentEps(p, m_points[0], m_points[1], kEps);
- for (size_t i = 0; i < n; ++i) {
+ 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))
diff --git a/geometry/calipers_box.hpp b/geometry/calipers_box.hpp
new file mode 100644
index 0000000000..19119ad147
--- /dev/null
+++ b/geometry/calipers_box.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "geometry/point2d.hpp"
+
+#include <vector>
+
+namespace m2
+{
+// When the size of the convex hull over a set of |points| is less
+// than 4, stores convex hull explicitly, otherwise stores smallest
+// rectangle containing the hull. Note that at least one side of the
+// rectangle should contain a facet of the hull, and in general sides
+// of the rectangle may not be parallel to the axes. In any case,
+// CalipersBox stores points in counter-clockwise order.
+class CalipersBox
+{
+public:
+ 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)); }
+
+private:
+ std::vector<PointD> m_points;
+};
+} // namespace m2
diff --git a/geometry/cbox.hpp b/geometry/cbox.hpp
deleted file mode 100644
index cd1f5fa4b6..0000000000
--- a/geometry/cbox.hpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-#include "geometry/point2d.hpp"
-
-#include <vector>
-
-namespace m2
-{
-class CBox
-{
-public:
- CBox(std::vector<m2::PointD> const & points);
-
- std::vector<m2::PointD> Points() const { return m_points; }
-
- bool IsInside(m2::PointD const & p) const;
- bool IsInside(double x, double y) const { return IsInside(m2::PointD(x, y)); }
-
-private:
- std::vector<m2::PointD> m_points;
-};
-} // namespace m2
diff --git a/geometry/convex_hull.cpp b/geometry/convex_hull.cpp
index 514ebe043b..1e7d867c06 100644
--- a/geometry/convex_hull.cpp
+++ b/geometry/convex_hull.cpp
@@ -12,18 +12,13 @@ namespace m2
{
namespace
{
-// 1e-12 is used here because of we're going to use the convex hull 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;
}
-bool IsContinuedBy(vector<PointD> const & hull, PointD const & p)
+bool IsContinuedBy(vector<PointD> const & hull, PointD const & p, double eps)
{
auto const n = hull.size();
if (n < 2)
@@ -33,10 +28,10 @@ bool IsContinuedBy(vector<PointD> const & hull, PointD const & p)
auto const & p2 = hull[n - 1];
// Checks whether (p2 - p1) x (p - p2) > 0.
- return IsCCW(p, p1, p2);
+ return IsCCW(p, p1, p2, eps);
}
-vector<PointD> BuildConvexHull(vector<PointD> points)
+vector<PointD> BuildConvexHull(vector<PointD> points, double eps)
{
my::SortUnique(points);
@@ -49,10 +44,10 @@ vector<PointD> BuildConvexHull(vector<PointD> points)
auto const pivot = points[0];
- sort(points.begin() + 1, points.end(), [&pivot](PointD const & lhs, PointD const & rhs) {
- if (IsCCW(lhs, rhs, pivot))
+ sort(points.begin() + 1, points.end(), [&pivot, &eps](PointD const & lhs, PointD const & rhs) {
+ if (IsCCW(lhs, rhs, pivot, eps))
return true;
- if (IsCCW(rhs, lhs, pivot))
+ if (IsCCW(rhs, lhs, pivot, eps))
return false;
return lhs.SquareLength(pivot) < rhs.SquareLength(pivot);
});
@@ -61,7 +56,7 @@ vector<PointD> BuildConvexHull(vector<PointD> points)
for (auto const & p : points)
{
- while (!IsContinuedBy(hull, p))
+ while (!IsContinuedBy(hull, p, eps))
hull.pop_back();
hull.push_back(p);
}
@@ -70,5 +65,8 @@ vector<PointD> BuildConvexHull(vector<PointD> points)
}
} // namespace
-ConvexHull::ConvexHull(vector<m2::PointD> const & points) : m_hull(BuildConvexHull(points)) {}
+ConvexHull::ConvexHull(vector<PointD> const & points, double eps)
+ : m_hull(BuildConvexHull(points, eps))
+{
+}
} // namespace m2
diff --git a/geometry/convex_hull.hpp b/geometry/convex_hull.hpp
index 438df467f3..2048ca3fa0 100644
--- a/geometry/convex_hull.hpp
+++ b/geometry/convex_hull.hpp
@@ -17,12 +17,12 @@ public:
// points lying on the same straight line.
//
// Complexity: O(n * log(n)), where n is the number of points.
- explicit ConvexHull(std::vector<m2::PointD> const & points);
+ ConvexHull(std::vector<PointD> const & points, double eps);
size_t Size() const { return m_hull.size(); }
bool Empty() const { return m_hull.empty(); }
- m2::PointD const & PointAt(size_t i) const
+ PointD const & PointAt(size_t i) const
{
ASSERT(!Empty(), ());
return m_hull[i % Size()];
@@ -34,9 +34,9 @@ public:
return Segment2D(PointAt(i), PointAt(i + 1));
}
- std::vector<m2::PointD> const & Points() const { return m_hull; }
+ std::vector<PointD> const & Points() const { return m_hull; }
private:
- std::vector<m2::PointD> m_hull;
+ std::vector<PointD> m_hull;
};
} // namespace m2
diff --git a/geometry/dbox.hpp b/geometry/dbox.hpp
deleted file mode 100644
index 958f16d2a7..0000000000
--- a/geometry/dbox.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include "geometry/bbox.hpp"
-#include "geometry/point2d.hpp"
-
-namespace m2
-{
-class DBox
-{
-public:
- void Add(m2::PointD const & p) { return Add(p.x, p.y); }
- void Add(double x, double y) { return m_box.Add(x + y, x - y); }
-
- bool IsInside(m2::PointD const & p) const { return IsInside(p.x, p.y); }
- bool IsInside(double x, double y) const { return m_box.IsInside(x + y, x - y); }
-
-private:
- BBox m_box;
-};
-} // namespace m2
diff --git a/geometry/diamond_box.hpp b/geometry/diamond_box.hpp
new file mode 100644
index 0000000000..5bbd4d2f6f
--- /dev/null
+++ b/geometry/diamond_box.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "geometry/bounding_box.hpp"
+#include "geometry/point2d.hpp"
+
+namespace m2
+{
+// Bounding box for a set of points on the plane, rotated by 45
+// degrees.
+class DiamondBox
+{
+public:
+ 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); }
+
+private:
+ BoundingBox m_box;
+};
+} // namespace m2
diff --git a/geometry/geometry.pro b/geometry/geometry.pro
index efb99dc95b..bf5bd72b54 100644
--- a/geometry/geometry.pro
+++ b/geometry/geometry.pro
@@ -11,8 +11,8 @@ include($$ROOT_DIR/common.pri)
SOURCES += \
algorithm.cpp \
angles.cpp \
- bbox.cpp \
- cbox.cpp \
+ bounding_box.cpp \
+ calipers_box.cpp \
clipping.cpp \
convex_hull.cpp \
distance_on_sphere.cpp \
@@ -33,14 +33,14 @@ HEADERS += \
angles.hpp \
any_rect2d.hpp \
avg_vector.hpp \
- bbox.hpp \
- cbox.hpp \
+ bounding_box.hpp \
+ calipers_box.hpp \
cellid.hpp \
clipping.hpp \
convex_hull.hpp \
covering.hpp \
covering_utils.hpp \
- dbox.hpp \
+ diamond_box.hpp \
distance.hpp \
distance_on_sphere.hpp \
latlon.hpp \
diff --git a/geometry/geometry_tests/CMakeLists.txt b/geometry/geometry_tests/CMakeLists.txt
index 715476433a..cadc7921bd 100644
--- a/geometry/geometry_tests/CMakeLists.txt
+++ b/geometry/geometry_tests/CMakeLists.txt
@@ -7,14 +7,14 @@ set(
algorithm_test.cpp
angle_test.cpp
anyrect_test.cpp
- bbox_tests.cpp
- cbox_tests.cpp
+ bounding_box_tests.cpp
+ calipers_box_tests.cpp
cellid_test.cpp
clipping_test.cpp
common_test.cpp
convex_hull_tests.cpp
covering_test.cpp
- dbox_tests.cpp
+ diamond_box_tests.cpp
distance_on_sphere_test.cpp
distance_test.cpp
equality.hpp
diff --git a/geometry/geometry_tests/bbox_tests.cpp b/geometry/geometry_tests/bbox_tests.cpp
deleted file mode 100644
index 3e4be8a159..0000000000
--- a/geometry/geometry_tests/bbox_tests.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "testing/testing.hpp"
-
-#include "geometry/bbox.hpp"
-#include "geometry/point2d.hpp"
-
-using namespace m2;
-
-namespace
-{
-UNIT_TEST(BBox_Smoke)
-{
- {
- BBox bbox;
- TEST(!bbox.IsInside(0, 0), ());
- TEST(!bbox.IsInside(-1, 1), ());
- }
-
- {
- BBox bbox;
-
- bbox.Add(0, 0);
- TEST(bbox.IsInside(0, 0), ());
- TEST(!bbox.IsInside(1, 0), ());
- TEST(!bbox.IsInside(0, 1), ());
- TEST(!bbox.IsInside(1, 1), ());
- TEST(!bbox.IsInside(0.5, 0.5), ());
-
- bbox.Add(1, 1);
- TEST(bbox.IsInside(1, 0), ());
- TEST(bbox.IsInside(0, 1), ());
- TEST(bbox.IsInside(1, 1), ());
- TEST(bbox.IsInside(0.5, 0.5), ());
- }
-}
-} // namespace
diff --git a/geometry/geometry_tests/bounding_box_tests.cpp b/geometry/geometry_tests/bounding_box_tests.cpp
new file mode 100644
index 0000000000..feb18f001c
--- /dev/null
+++ b/geometry/geometry_tests/bounding_box_tests.cpp
@@ -0,0 +1,36 @@
+#include "testing/testing.hpp"
+
+#include "geometry/bounding_box.hpp"
+#include "geometry/point2d.hpp"
+
+using namespace m2;
+
+namespace
+{
+UNIT_TEST(BoundingBox_Smoke)
+{
+ {
+ BoundingBox bbox;
+
+ TEST(!bbox.HasPoint(0, 0), ());
+ TEST(!bbox.HasPoint(-1, 1), ());
+ }
+
+ {
+ BoundingBox bbox;
+
+ bbox.Add(0, 0);
+ TEST(bbox.HasPoint(0, 0), ());
+ TEST(!bbox.HasPoint(1, 0), ());
+ TEST(!bbox.HasPoint(0, 1), ());
+ TEST(!bbox.HasPoint(1, 1), ());
+ TEST(!bbox.HasPoint(0.5, 0.5), ());
+
+ bbox.Add(1, 1);
+ TEST(bbox.HasPoint(1, 0), ());
+ TEST(bbox.HasPoint(0, 1), ());
+ TEST(bbox.HasPoint(1, 1), ());
+ TEST(bbox.HasPoint(0.5, 0.5), ());
+ }
+}
+} // namespace
diff --git a/geometry/geometry_tests/cbox_tests.cpp b/geometry/geometry_tests/calipers_box_tests.cpp
index aa76304f0a..9d78e2d57b 100644
--- a/geometry/geometry_tests/cbox_tests.cpp
+++ b/geometry/geometry_tests/calipers_box_tests.cpp
@@ -1,6 +1,6 @@
#include "testing/testing.hpp"
-#include "geometry/cbox.hpp"
+#include "geometry/calipers_box.hpp"
#include "geometry/point2d.hpp"
#include <vector>
@@ -10,49 +10,49 @@ using namespace std;
namespace
{
-UNIT_TEST(CBox_Smoke)
+UNIT_TEST(CalipersBox_Smoke)
{
{
- CBox const cbox(vector<PointD>{});
+ CalipersBox const cbox(vector<PointD>{});
TEST(cbox.Points().empty(), ());
- TEST(!cbox.IsInside(0, 0), ());
- TEST(!cbox.IsInside(0, 1), ());
- TEST(!cbox.IsInside(1, 0), ());
+ TEST(!cbox.HasPoint(0, 0), ());
+ TEST(!cbox.HasPoint(0, 1), ());
+ TEST(!cbox.HasPoint(1, 0), ());
}
{
vector<PointD> const points = {{PointD(2, 3)}};
- CBox const cbox(points);
+ CalipersBox const cbox(points);
TEST_EQUAL(cbox.Points(), points, ());
- TEST(cbox.IsInside(2, 3), ());
- TEST(!cbox.IsInside(4, 6), ());
- TEST(!cbox.IsInside(0, 0), ());
+ TEST(cbox.HasPoint(2, 3), ());
+ TEST(!cbox.HasPoint(4, 6), ());
+ TEST(!cbox.HasPoint(0, 0), ());
}
{
vector<PointD> const points = {{PointD(2, 3), PointD(2, 3), PointD(2, 3)}};
- CBox const cbox(points);
+ CalipersBox const cbox(points);
TEST_EQUAL(cbox.Points(), vector<PointD>{{PointD(2, 3)}}, ());
}
{
vector<PointD> const points = {{PointD(1, 1), PointD(1, 2)}};
- CBox const cbox(points);
+ CalipersBox const cbox(points);
TEST_EQUAL(cbox.Points(), points, ());
- TEST(cbox.IsInside(1, 1.5), ());
- TEST(!cbox.IsInside(1, 3), ());
- TEST(!cbox.IsInside(0, 0), ());
+ TEST(cbox.HasPoint(1, 1.5), ());
+ TEST(!cbox.HasPoint(1, 3), ());
+ TEST(!cbox.HasPoint(0, 0), ());
}
{
vector<PointD> const points = {
{PointD(0, 0), PointD(-2, 3), PointD(1, 5), PointD(3, 2), PointD(1, 2), PointD(0, 3)}};
- CBox const cbox(points);
+ CalipersBox const cbox(points);
TEST_EQUAL(cbox.Points(),
(vector<PointD>{{PointD(-2, 3), PointD(0, 0), PointD(3, 2), PointD(1, 5)}}), ());
for (auto const & p : points)
- TEST(cbox.IsInside(p), (p));
- TEST(!cbox.IsInside(1, 0), ());
+ TEST(cbox.HasPoint(p), (p));
+ TEST(!cbox.HasPoint(1, 0), ());
}
{
@@ -60,16 +60,16 @@ UNIT_TEST(CBox_Smoke)
PointD(-2, 2), PointD(-2, 3), PointD(3, 2), PointD(3, 3)}};
vector<PointD> const expected = {
{PointD(-2.5, 2.5), PointD(0.5, -0.5), PointD(3.5, 2.5), PointD(0.5, 5.5)}};
- CBox const cbox(points);
+ CalipersBox const cbox(points);
TEST_EQUAL(cbox.Points(), expected, ());
for (auto const & p : points)
- TEST(cbox.IsInside(p), (p));
+ TEST(cbox.HasPoint(p), (p));
- TEST(cbox.IsInside(0, 2), ());
+ TEST(cbox.HasPoint(0, 2), ());
- TEST(!cbox.IsInside(2, 0), ());
- TEST(!cbox.IsInside(4, 2), ());
+ TEST(!cbox.HasPoint(2, 0), ());
+ TEST(!cbox.HasPoint(4, 2), ());
}
}
} // namespace
diff --git a/geometry/geometry_tests/convex_hull_tests.cpp b/geometry/geometry_tests/convex_hull_tests.cpp
index 5aafc4f1e3..8441a14c15 100644
--- a/geometry/geometry_tests/convex_hull_tests.cpp
+++ b/geometry/geometry_tests/convex_hull_tests.cpp
@@ -10,9 +10,11 @@ using namespace std;
namespace
{
-vector<m2::PointD> BuildConvexHull(vector<m2::PointD> const & points)
+double const kEps = 1e-12;
+
+vector<PointD> BuildConvexHull(vector<PointD> const & points)
{
- return ConvexHull(points).Points();
+ return ConvexHull(points, kEps).Points();
}
UNIT_TEST(ConvexHull_Smoke)
diff --git a/geometry/geometry_tests/dbox_tests.cpp b/geometry/geometry_tests/dbox_tests.cpp
deleted file mode 100644
index 12fdfef88f..0000000000
--- a/geometry/geometry_tests/dbox_tests.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "testing/testing.hpp"
-
-#include "geometry/dbox.hpp"
-#include "geometry/point2d.hpp"
-
-using namespace m2;
-
-namespace
-{
-UNIT_TEST(DBox_Smoke)
-{
- {
- DBox dbox;
- TEST(!dbox.IsInside(0, 0), ());
- }
-
- {
- DBox dbox;
- dbox.Add(0, 0);
- TEST(dbox.IsInside(0, 0), ());
- TEST(!dbox.IsInside(0, 1), ());
- TEST(!dbox.IsInside(1, 0), ());
- TEST(!dbox.IsInside(1, 1), ());
- TEST(!dbox.IsInside(0.5, 0.5), ());
-
- dbox.Add(1, 1);
- TEST(dbox.IsInside(0, 0), ());
- TEST(dbox.IsInside(1, 1), ());
- TEST(dbox.IsInside(0.5, 0.5), ());
- TEST(!dbox.IsInside(1, 0), ());
- TEST(!dbox.IsInside(0, 1), ());
- }
-
- {
- DBox dbox;
-
- dbox.Add(0, 1);
- dbox.Add(0, -1);
- dbox.Add(-1, 0);
- dbox.Add(1, 0);
- TEST(dbox.IsInside(0, 0), ());
- TEST(dbox.IsInside(0.5, 0.5), ());
- TEST(dbox.IsInside(0.5, -0.5), ());
- TEST(dbox.IsInside(-0.5, 0.5), ());
- TEST(dbox.IsInside(-0.5, -0.5), ());
-
- TEST(!dbox.IsInside(0.51, 0.51), ());
- TEST(!dbox.IsInside(0.51, -0.51), ());
- TEST(!dbox.IsInside(-0.51, 0.51), ());
- TEST(!dbox.IsInside(-0.51, -0.51), ());
- }
-}
-} // namespace
diff --git a/geometry/geometry_tests/diamond_box_tests.cpp b/geometry/geometry_tests/diamond_box_tests.cpp
new file mode 100644
index 0000000000..a3ed68f0e4
--- /dev/null
+++ b/geometry/geometry_tests/diamond_box_tests.cpp
@@ -0,0 +1,53 @@
+#include "testing/testing.hpp"
+
+#include "geometry/diamond_box.hpp"
+#include "geometry/point2d.hpp"
+
+using namespace m2;
+
+namespace
+{
+UNIT_TEST(DiamondBox_Smoke)
+{
+ {
+ DiamondBox dbox;
+ TEST(!dbox.HasPoint(0, 0), ());
+ }
+
+ {
+ DiamondBox dbox;
+ dbox.Add(0, 0);
+ TEST(dbox.HasPoint(0, 0), ());
+ TEST(!dbox.HasPoint(0, 1), ());
+ TEST(!dbox.HasPoint(1, 0), ());
+ TEST(!dbox.HasPoint(1, 1), ());
+ TEST(!dbox.HasPoint(0.5, 0.5), ());
+
+ dbox.Add(1, 1);
+ TEST(dbox.HasPoint(0, 0), ());
+ TEST(dbox.HasPoint(1, 1), ());
+ TEST(dbox.HasPoint(0.5, 0.5), ());
+ TEST(!dbox.HasPoint(1, 0), ());
+ TEST(!dbox.HasPoint(0, 1), ());
+ }
+
+ {
+ DiamondBox dbox;
+
+ dbox.Add(0, 1);
+ dbox.Add(0, -1);
+ dbox.Add(-1, 0);
+ dbox.Add(1, 0);
+ TEST(dbox.HasPoint(0, 0), ());
+ TEST(dbox.HasPoint(0.5, 0.5), ());
+ TEST(dbox.HasPoint(0.5, -0.5), ());
+ TEST(dbox.HasPoint(-0.5, 0.5), ());
+ TEST(dbox.HasPoint(-0.5, -0.5), ());
+
+ TEST(!dbox.HasPoint(0.51, 0.51), ());
+ TEST(!dbox.HasPoint(0.51, -0.51), ());
+ TEST(!dbox.HasPoint(-0.51, 0.51), ());
+ TEST(!dbox.HasPoint(-0.51, -0.51), ());
+ }
+}
+} // namespace
diff --git a/geometry/geometry_tests/geometry_tests.pro b/geometry/geometry_tests/geometry_tests.pro
index b75f23fd5f..f0747bd140 100644
--- a/geometry/geometry_tests/geometry_tests.pro
+++ b/geometry/geometry_tests/geometry_tests.pro
@@ -22,14 +22,14 @@ SOURCES += \
algorithm_test.cpp \
angle_test.cpp \
anyrect_test.cpp \
- bbox_tests.cpp \
- cbox_tests.cpp \
+ bounding_box_tests.cpp \
+ calipers_box_tests.cpp \
cellid_test.cpp \
clipping_test.cpp \
common_test.cpp \
convex_hull_tests.cpp \
covering_test.cpp \
- dbox_tests.cpp \
+ diamond_box_tests.cpp \
distance_on_sphere_test.cpp \
distance_test.cpp \
intersect_test.cpp \
diff --git a/geometry/geometry_tests/line2d_tests.cpp b/geometry/geometry_tests/line2d_tests.cpp
index b6e196e483..c5c8147f9e 100644
--- a/geometry/geometry_tests/line2d_tests.cpp
+++ b/geometry/geometry_tests/line2d_tests.cpp
@@ -21,19 +21,13 @@ UNIT_TEST(LineIntersector_Smoke)
{
{
Line2D const line(Segment2D(PointD(0, 0), PointD(1, 0)));
- TEST_EQUAL(Intersect(line, line).m_type, Type::Infinite, ());
+ TEST_EQUAL(Intersect(line, line).m_type, Type::Infinity, ());
}
{
Line2D const lhs(Segment2D(PointD(0, 0), PointD(1, 1)));
Line2D const rhs(Segment2D(PointD(-10, -10), PointD(-100, -100)));
- TEST_EQUAL(Intersect(lhs, rhs).m_type, Type::Infinite, ());
- }
-
- {
- Line2D const lhs(Segment2D(PointD(0, 0), PointD(1, 1)));
- Line2D const rhs(Segment2D(PointD(-10, -10), PointD(-100, -100)));
- TEST_EQUAL(Intersect(lhs, rhs).m_type, Type::Infinite, ());
+ TEST_EQUAL(Intersect(lhs, rhs).m_type, Type::Infinity, ());
}
{
@@ -46,7 +40,7 @@ UNIT_TEST(LineIntersector_Smoke)
Line2D const lhs(Segment2D(PointD(10, 0), PointD(9, 10)));
Line2D const rhs(Segment2D(PointD(-10, 0), PointD(-9, 10)));
auto const result = Intersect(lhs, rhs);
- TEST_EQUAL(result.m_type, Type::Single, ());
+ TEST_EQUAL(result.m_type, Type::One, ());
TEST(AlmostEqualAbs(result.m_point, PointD(0, 100), kEps), (result.m_point));
}
}
diff --git a/geometry/line2d.cpp b/geometry/line2d.cpp
index 1401e7a06a..061474463c 100644
--- a/geometry/line2d.cpp
+++ b/geometry/line2d.cpp
@@ -9,7 +9,7 @@ namespace m2
{
namespace
{
-bool Collinear(m2::PointD const & a, m2::PointD const & b, double eps)
+bool Collinear(PointD const & a, PointD const & b, double eps)
{
return fabs(CrossProduct(a, b)) < eps;
}
@@ -38,7 +38,7 @@ LineIntersector::Result LineIntersector::Intersect(Line2D const & lhs, Line2D co
if (Collinear(ab, cd, eps))
{
if (Collinear(c - a, cd, eps))
- return Result(Result::Type::Infinite);
+ return Result(Result::Type::Infinity);
return Result(Result::Type::Zero);
}
@@ -58,8 +58,8 @@ string DebugPrint(LineIntersector::Result::Type type)
switch (type)
{
case Type::Zero: return "Zero";
- case Type::Single: return "Single";
- case Type::Infinite: return "Infinite";
+ case Type::One: return "One";
+ case Type::Infinity: return "Infinity";
}
}
@@ -67,7 +67,7 @@ string DebugPrint(LineIntersector::Result const & result)
{
ostringstream os;
os << "Result [";
- if (result.m_type == LineIntersector::Result::Type::Single)
+ if (result.m_type == LineIntersector::Result::Type::One)
os << DebugPrint(result.m_point);
else
os << DebugPrint(result.m_type);
diff --git a/geometry/line2d.hpp b/geometry/line2d.hpp
index d35e187d28..cfce8d0858 100644
--- a/geometry/line2d.hpp
+++ b/geometry/line2d.hpp
@@ -15,13 +15,13 @@ struct Line2D
explicit Line2D(Segment2D const & segment) : m_point(segment.m_u), m_direction(segment.Dir()) {}
- Line2D(m2::PointD const & point, m2::PointD const & direction)
+ Line2D(PointD const & point, PointD const & direction)
: m_point(point), m_direction(direction)
{
}
- m2::PointD m_point;
- m2::PointD m_direction;
+ PointD m_point;
+ PointD m_direction;
};
std::string DebugPrint(Line2D const & line);
@@ -33,14 +33,14 @@ struct LineIntersector
enum class Type
{
Zero,
- Single,
- Infinite
+ One,
+ Infinity
};
- explicit Result(Type type) : m_type(type) { ASSERT_NOT_EQUAL(m_type, Type::Single, ()); }
- explicit Result(m2::PointD const & point) : m_point(point), m_type(Type::Single) {}
+ explicit Result(Type type) : m_type(type) { ASSERT_NOT_EQUAL(m_type, Type::One, ()); }
+ explicit Result(PointD const & point) : m_point(point), m_type(Type::One) {}
- m2::PointD m_point;
+ PointD m_point;
Type m_type;
};
diff --git a/geometry/segment2d.cpp b/geometry/segment2d.cpp
index 97d73819b9..f51d5940c7 100644
--- a/geometry/segment2d.cpp
+++ b/geometry/segment2d.cpp
@@ -3,6 +3,7 @@
#include "geometry/robust_orientation.hpp"
#include <algorithm>
+
using namespace std;
namespace m2
@@ -12,8 +13,7 @@ string DebugPrint(Segment2D const & segment)
return "(" + DebugPrint(segment.m_u) + ", " + DebugPrint(segment.m_v) + ")";
}
-bool IsPointOnSegmentEps(m2::PointD const & pt, m2::PointD const & p1, m2::PointD const & p2,
- double eps)
+bool IsPointOnSegmentEps(PointD const & pt, PointD const & p1, PointD const & p2, double eps)
{
double const t = robust::OrientedS(p1, p2, pt);
@@ -33,7 +33,7 @@ bool IsPointOnSegmentEps(m2::PointD const & pt, m2::PointD const & p1, m2::Point
return pt.x >= minX - eps && pt.x <= maxX + eps && pt.y >= minY - eps && pt.y <= maxY + eps;
}
-bool IsPointOnSegment(m2::PointD const & pt, m2::PointD const & p1, m2::PointD const & p2)
+bool IsPointOnSegment(PointD const & pt, PointD const & p1, PointD const & p2)
{
// The epsilon here is chosen quite arbitrarily, to pass paranoid
// tests and to match our real-data geometry precision. If you have
diff --git a/geometry/segment2d.hpp b/geometry/segment2d.hpp
index 2c4e9a10c9..1e77857ee1 100644
--- a/geometry/segment2d.hpp
+++ b/geometry/segment2d.hpp
@@ -9,17 +9,16 @@ namespace m2
struct Segment2D
{
Segment2D() = default;
- Segment2D(m2::PointD const & u, m2::PointD const & v) : m_u(u), m_v(v) {}
+ Segment2D(PointD const & u, PointD const & v) : m_u(u), m_v(v) {}
- m2::PointD const Dir() const { return m_v - m_u; }
+ PointD const Dir() const { return m_v - m_u; }
- m2::PointD m_u;
- m2::PointD m_v;
+ PointD m_u;
+ PointD m_v;
};
std::string DebugPrint(Segment2D const & s);
-bool IsPointOnSegmentEps(m2::PointD const & pt, m2::PointD const & p1, m2::PointD const & p2,
- double eps);
-bool IsPointOnSegment(m2::PointD const & pt, m2::PointD const & p1, m2::PointD const & p2);
+bool IsPointOnSegmentEps(PointD const & pt, PointD const & p1, PointD const & p2, double eps);
+bool IsPointOnSegment(PointD const & pt, PointD const & p1, PointD const & p2);
} // namespace m2