From 58dd7df7242ab18f2ea62b2898c4a2b16a4edb8b Mon Sep 17 00:00:00 2001 From: Yury Melnichek Date: Sun, 30 Jan 2011 06:14:38 +0100 Subject: [PATCH] Better predictors for polylines. --- indexer/geometry_coding.cpp | 33 ++++++++++++++++++- .../indexer_tests/geometry_coding_test.cpp | 4 +-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/indexer/geometry_coding.cpp b/indexer/geometry_coding.cpp index cf0d36487e..f295b7d952 100644 --- a/indexer/geometry_coding.cpp +++ b/indexer/geometry_coding.cpp @@ -1,4 +1,5 @@ #include "geometry_coding.hpp" +#include "../../geometry/distance.hpp" #include "../coding/byte_stream.hpp" #include "../base/assert.hpp" #include "../base/stl_add.hpp" @@ -45,7 +46,9 @@ m2::PointU PredictPointInPolyline(m2::PointU const & maxPoint, m2::PointU const & p1, m2::PointU const & p2) { - return ClampPoint(maxPoint, m2::PointI64(p1) + m2::PointI64(p1) - m2::PointI64(p2)); + // return ClampPoint(maxPoint, m2::PointI64(p1) + m2::PointI64(p1) - m2::PointI64(p2)); + // return ClampPoint(maxPoint, m2::PointI64(p1) + (m2::PointI64(p1) - m2::PointI64(p2)) / 2); + return ClampPoint(maxPoint, m2::PointD(p1) + (m2::PointD(p1) - m2::PointD(p2)) / 2); } m2::PointU PredictPointInPolyline(m2::PointU const & maxPoint, @@ -55,12 +58,40 @@ m2::PointU PredictPointInPolyline(m2::PointU const & maxPoint, { CHECK_NOT_EQUAL(p2, p3, ()); + complex const c1(p1.x, p1.y); + complex const c2(p2.x, p2.y); + complex const c3(p3.x, p3.y); + complex const d = (c1 - c2) / (c2 - c3); + complex const c0 = c1 + (c1 - c2) * polar(0.5, 0.5 * arg(d)); + + /* + complex const c1(p1.x, p1.y); + complex const c2(p2.x, p2.y); + complex const c3(p3.x, p3.y); + complex const d = (c1 - c2) / (c2 - c3); + complex const c01 = c1 + (c1 - c2) * polar(0.5, arg(d)); + complex const c02 = c1 + (c1 - c2) * complex(0.5, 0.0); + complex const c0 = (c01 + c02) * complex(0.5, 0.0); + */ + + /* + complex const c1(p1.x, p1.y); + complex const c2(p2.x, p2.y); + complex const c3(p3.x, p3.y); + complex d = (c1 - c2) / (c2 - c3); + d /= abs(d); + complex const c0 = c1 + (c1 - c2) * d * complex(0.5, 0.0); + */ + + /* // In complex numbers: // Ci = Ci-1 + (Ci-1 - Ci-2) * (Ci-1 - Ci-2) / (Ci-2 - Ci-3) complex const c1(p1.x, p1.y); complex const c2(p2.x, p2.y); complex const c3(p3.x, p3.y); complex const c0 = c1 + (c1 - c2) * (c1 - c2) / (c2 - c3); + */ + return ClampPoint(maxPoint, m2::PointD(c0.real(), c0.imag())); } diff --git a/indexer/indexer_tests/geometry_coding_test.cpp b/indexer/indexer_tests/geometry_coding_test.cpp index 1131e2f96e..fd814d5b50 100644 --- a/indexer/indexer_tests/geometry_coding_test.cpp +++ b/indexer/indexer_tests/geometry_coding_test.cpp @@ -118,8 +118,8 @@ UNIT_TEST(EncodePolyline) vector points; points.reserve(polygonSize); for (size_t i = 0; i < polygonSize; ++i) - points.push_back(m2::PointU(static_cast(kLargePolygon[i].x * 1000), - static_cast((kLargePolygon[i].y + 200) * 1000))); + points.push_back(m2::PointU(static_cast(kLargePolygon[i].x * 10000), + static_cast((kLargePolygon[i].y + 200) * 10000))); TestEncodePolyline("Unsimp", maxPoint, points); TestEncodePolyline("1simp", maxPoint, SimplifyPoints(points, 1));