diff options
author | Maxim Pimenov <m@maps.me> | 2018-07-27 16:14:25 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <bykoianko@gmail.com> | 2018-08-01 13:45:25 +0300 |
commit | e61ae1903cf5acfe6f5290e34ebc6f65e64138e1 (patch) | |
tree | d13b8dcfac261c73b9aa73d380f5cec19e4fc121 /geometry | |
parent | 00f2b4c78b3b4edb4218bcc59a5722e20f49a8e6 (diff) |
Review fixes.
Diffstat (limited to 'geometry')
-rw-r--r-- | geometry/geometry_tests/parametrized_segment_tests.cpp | 8 | ||||
-rw-r--r-- | geometry/geometry_tests/region2d_binary_op_test.cpp | 5 | ||||
-rw-r--r-- | geometry/geometry_tests/simplification_test.cpp | 9 | ||||
-rw-r--r-- | geometry/parametrized_segment.hpp | 3 | ||||
-rw-r--r-- | geometry/polyline2d.hpp | 5 | ||||
-rw-r--r-- | geometry/region2d/binary_operators.cpp | 2 | ||||
-rw-r--r-- | geometry/simplification.hpp | 15 |
7 files changed, 30 insertions, 17 deletions
diff --git a/geometry/geometry_tests/parametrized_segment_tests.cpp b/geometry/geometry_tests/parametrized_segment_tests.cpp index 0a07659c85..569b9acd46 100644 --- a/geometry/geometry_tests/parametrized_segment_tests.cpp +++ b/geometry/geometry_tests/parametrized_segment_tests.cpp @@ -1,8 +1,12 @@ +#include "testing/testing.hpp" + #include "geometry/parametrized_segment.hpp" #include "geometry/point2d.hpp" -#include "testing/testing.hpp" -template <class Point> +#include "base/macros.hpp" +#include "base/math.hpp" + +template <typename Point> void FloatingPointsTest() { m2::ParametrizedSegment<Point> d(Point(-1, 3), Point(2, 1)); diff --git a/geometry/geometry_tests/region2d_binary_op_test.cpp b/geometry/geometry_tests/region2d_binary_op_test.cpp index 9304714036..c0ef2b8579 100644 --- a/geometry/geometry_tests/region2d_binary_op_test.cpp +++ b/geometry/geometry_tests/region2d_binary_op_test.cpp @@ -1,10 +1,9 @@ -#include "geometry/geometry_tests/test_regions.hpp" - #include "testing/testing.hpp" +#include "geometry/geometry_tests/test_regions.hpp" #include "geometry/region2d/binary_operators.hpp" -#include "base/logging.hpp" +#include "base/macros.hpp" #include <vector> diff --git a/geometry/geometry_tests/simplification_test.cpp b/geometry/geometry_tests/simplification_test.cpp index b9e26aea69..be841051a9 100644 --- a/geometry/geometry_tests/simplification_test.cpp +++ b/geometry/geometry_tests/simplification_test.cpp @@ -12,6 +12,7 @@ #include "base/macros.hpp" #include "base/stl_add.hpp" +#include <cstdint> #include <limits> #include <vector> @@ -22,7 +23,8 @@ namespace using P = m2::PointD; using DistanceFn = m2::SquaredDistanceFromSegmentToPoint<P>; using PointOutput = BackInsertFunctor<vector<m2::PointD>>; -typedef void (*SimplifyFn)(m2::PointD const *, m2::PointD const *, double, DistanceFn, PointOutput); +using SimplifyFn = void (*)(m2::PointD const *, m2::PointD const *, double, DistanceFn, + PointOutput); struct LargePolylineTestData { @@ -91,9 +93,7 @@ void CheckDPStrict(P const * arr, size_t n, double eps, size_t expectedCount) TEST_EQUAL(arr[n - 1], vec.back(), ()); if (expectedCount > 0) - { TEST_EQUAL(expectedCount, vec.size(), ()); - } for (size_t i = 2; i < vec.size(); ++i) { @@ -106,7 +106,8 @@ void CheckDPStrict(P const * arr, size_t n, double eps, size_t expectedCount) UNIT_TEST(Simplification_TestDataIsCorrect) { TEST_GREATER_OR_EQUAL(LargePolylineTestData::m_Size, 3, ()); - // LOG(LINFO, ("Polyline test size:", LargePolylineTestData::m_Size)); + // This test provides information about the data set size. + TEST_EQUAL(LargePolylineTestData::m_Size, 5539, ()); } UNIT_TEST(Simplification_DP_Smoke) { TestSimplificationSmoke(&SimplifyDP<DistanceFn>); } diff --git a/geometry/parametrized_segment.hpp b/geometry/parametrized_segment.hpp index b79e9cc913..faa23b58a1 100644 --- a/geometry/parametrized_segment.hpp +++ b/geometry/parametrized_segment.hpp @@ -37,6 +37,7 @@ public: m_d = m_d / m_length; } + // Returns the squared (euclidean) distance from the segment to |p|. double SquaredDistanceToPoint(Point const & p) const { Point const diff = p - m_p0; @@ -53,6 +54,7 @@ public: return std::pow(CrossProduct(diffD, m_d), 2.0); } + // Returns the point of the segment that is closest to |p|. m2::PointD ClosestPointTo(Point const & p) const { Point const diff = p - m_p0; @@ -71,6 +73,7 @@ public: Point const & GetP0() const { return m_p0; } Point const & GetP1() const { return m_p1; } +private: Point m_p0; Point m_p1; m2::PointD m_d; diff --git a/geometry/polyline2d.hpp b/geometry/polyline2d.hpp index 7997eb2e5c..76ac3e2c23 100644 --- a/geometry/polyline2d.hpp +++ b/geometry/polyline2d.hpp @@ -6,6 +6,7 @@ #include "base/internal/message.hpp" +#include <algorithm> #include <cstddef> #include <initializer_list> #include <limits> @@ -57,7 +58,7 @@ public: double GetLength(size_t pointIndex) const { double dist = 0; - for (size_t i = 0; i < min(pointIndex, m_points.size() - 1); ++i) + for (size_t i = 0; i < std::min(pointIndex, m_points.size() - 1); ++i) dist += m_points[i].Length(m_points[i + 1]); return dist; } @@ -70,7 +71,7 @@ public: for (Iter j = i + 1; j != End(); ++i, ++j) { m2::ParametrizedSegment<m2::Point<T>> seg(*i, *j); - res = min(res, seg.SquaredDistanceToPoint(point)); + res = std::min(res, seg.SquaredDistanceToPoint(point)); } return res; diff --git a/geometry/region2d/binary_operators.cpp b/geometry/region2d/binary_operators.cpp index fb7106521c..11581eaa3b 100644 --- a/geometry/region2d/binary_operators.cpp +++ b/geometry/region2d/binary_operators.cpp @@ -1,6 +1,8 @@ #include "geometry/region2d/binary_operators.hpp" #include "geometry/region2d/boost_concept.hpp" +#include <cstddef> + using namespace std; namespace m2 diff --git a/geometry/simplification.hpp b/geometry/simplification.hpp index 95e63b68ae..f61904f4a9 100644 --- a/geometry/simplification.hpp +++ b/geometry/simplification.hpp @@ -7,6 +7,7 @@ #include "base/logging.hpp" #include <algorithm> +#include <cstdint> #include <iterator> #include <utility> #include <vector> @@ -83,12 +84,12 @@ void SimplifyDP(Iter beg, Iter end, double epsilon, DistanceFn distFn, Out out) // Dynamic programming near-optimal simplification. // Uses O(n) additional memory. -// Worst case O(n^3) performance, average O(n*k^2), where k is kMaxFalseLookAhead - parameter, +// Worst case O(n^3) performance, average O(n*k^2), where k is maxFalseLookAhead - parameter, // which limits the number of points to try, that produce error > epsilon. // Essentially, it's a trade-off between optimality and performance. // Values around 20 - 200 are reasonable. template <typename DistanceFn, typename Iter, typename Out> -void SimplifyNearOptimal(int kMaxFalseLookAhead, Iter beg, Iter end, double epsilon, +void SimplifyNearOptimal(int maxFalseLookAhead, Iter beg, Iter end, double epsilon, DistanceFn distFn, Out out) { int32_t const n = static_cast<int32_t>(end - beg); @@ -103,7 +104,7 @@ void SimplifyNearOptimal(int kMaxFalseLookAhead, Iter beg, Iter end, double epsi F[n - 1] = impl::SimplifyOptimalRes(n, 1); for (int32_t i = n - 2; i >= 0; --i) { - for (int32_t falseCount = 0, j = i + 1; j < n && falseCount < kMaxFalseLookAhead; ++j) + for (int32_t falseCount = 0, j = i + 1; j < n && falseCount < maxFalseLookAhead; ++j) { uint32_t const newPointCount = F[j].m_PointCount + 1; if (newPointCount < F[i].m_PointCount) @@ -127,7 +128,7 @@ void SimplifyNearOptimal(int kMaxFalseLookAhead, Iter beg, Iter end, double epsi // Additional points filter to use in simplification. // SimplifyDP can produce points that define degenerate triangle. -template <class DistanceFn, class Point> +template <typename DistanceFn, typename Point> class AccumulateSkipSmallTrg { public: @@ -142,8 +143,10 @@ public: size_t count; while ((count = m_vec.size()) >= 2) { - if (m_distFn(m2::PointD(m_vec[count - 2]), m2::PointD(p), m2::PointD(m_vec[count - 1])) < - m_eps) + auto const a = m2::PointD(m_vec[count - 2]); + auto const b = m2::PointD(p); + auto const c = m2::PointD(m_vec[count - 1]); + if (m_distFn(a, b, c) < m_eps) m_vec.pop_back(); else break; |