diff --git a/drape_frontend/text_layout.cpp b/drape_frontend/text_layout.cpp index 4c8c88de12..fe108a535d 100644 --- a/drape_frontend/text_layout.cpp +++ b/drape_frontend/text_layout.cpp @@ -213,7 +213,7 @@ void TextLayout::LayoutPathText(m2::Spline::iterator const & iterator, int32_t endIndex = isForwardDirection ? glyphCount : -1; int32_t incSign = isForwardDirection ? 1 : -1; - m2::PointF accum = itr.m_dir; + m2::PointD accum = itr.m_dir; float const koef = 0.7f; rects.resize(GetGlyphCount()); @@ -226,19 +226,24 @@ void TextLayout::LayoutPathText(m2::Spline::iterator const & iterator, advance *= scalePtoG; ASSERT_NOT_EQUAL(advance, 0.0, ()); - m2::PointF pos = itr.m_pos; + m2::PointD pos = itr.m_pos; itr.Step(advance); ASSERT(!itr.BeginAgain(), ()); - m2::PointF dir = (itr.m_avrDir.Normalize() * koef + accum * (1.0f - koef)).Normalize(); + m2::PointD dir = (itr.m_avrDir.Normalize() * koef + accum * (1.0f - koef)).Normalize(); accum = dir; - m2::PointF norm(-dir.y, dir.x); + m2::PointD norm(-dir.y, dir.x); dir *= halfWidth * scalePtoG; norm *= halfHeight * scalePtoG; - m2::PointF const dirComponent = dir * xOffset / halfWidth; - m2::PointF const normalComponent = -norm * incSign * yOffset / halfHeight; - m2::PointF const pivot = dirComponent + normalComponent + pos; + m2::PointD dirComponent; + if (isForwardDirection) + dirComponent = dir * xOffset / halfWidth; + else + dirComponent = dir * (2.0 * halfWidth - xOffset) / halfWidth; + + m2::PointD const normalComponent = -norm * incSign * yOffset / halfHeight; + m2::PointD const pivot = dirComponent + normalComponent + pos; positions.PushBack(glsl_types::vec2(pivot - dir + norm)); positions.PushBack(glsl_types::vec2(pivot - dir - norm)); diff --git a/drape_head/testing_engine.cpp b/drape_head/testing_engine.cpp index 9382225eab..2a15e591bc 100644 --- a/drape_head/testing_engine.cpp +++ b/drape_head/testing_engine.cpp @@ -384,6 +384,19 @@ private: return 0.0f; } + void ParseGeometry(json_t * object, vector & points) + { + size_t const count = json_array_size(object); + ASSERT((count & 1) == 0, ()); + points.reserve(count >> 1); + for (size_t i = 0; i < count; i += 2) + { + double const x = ParseCoord(json_array_get(object, i)); + double const y = ParseCoord(json_array_get(object, i + 1)); + points.push_back(m2::PointD(x, y)); + } + } + void ParseGeometry(json_t * object, vector & points) { size_t const count = json_array_size(object); @@ -416,7 +429,7 @@ private: params.m_join = ParseJoin(json_object_get(object, "join")); params.m_cap = ParseCap(json_object_get(object, "cap")); - vector points; + vector points; ParseGeometry(json_object_get(object, "geometry"), points); return new LineShape(points, params, 1.0); } @@ -601,7 +614,7 @@ void TestingEngine::DrawImpl() TextShape sh2(m2::PointF(250.0f, 250.0f), params); //sh2.Draw(m_batcher.GetRefPointer(), m_textures.GetRefPointer()); - vector path; + vector path; path.push_back(m2::PointF(200, 650)); path.push_back(m2::PointF(200, 450)); @@ -648,14 +661,14 @@ void TestingEngine::DrawImpl() params7.m_cap = dp::LineCap::ButtCap; params7.m_pattern = key.m_pattern; - vector points; + vector points; points.push_back(m2::PointF(100.0f, 100.0f)); points.push_back(m2::PointF(190.0f, 100.0f)); points.push_back(m2::PointF(190.0f, 190.0f)); points.push_back(m2::PointF(280.0f, 190.0f)); points.push_back(m2::PointF(280.0f, 280.0f)); points.push_back(m2::PointF(370.0f, 280.0f)); - LineShape ls1(path, params7, 1.0f / m_modelView.GetScale()); + LineShape ls1(points, params7, 1.0f / m_modelView.GetScale()); ls1.Draw(m_batcher.GetRefPointer(), m_textures.GetRefPointer()); } diff --git a/geometry/geometry_tests/spline_test.cpp b/geometry/geometry_tests/spline_test.cpp index 2d881e7b00..6f70967732 100644 --- a/geometry/geometry_tests/spline_test.cpp +++ b/geometry/geometry_tests/spline_test.cpp @@ -4,204 +4,204 @@ #include "../spline.hpp" using m2::Spline; -using m2::PointF; +using m2::PointD; -void TestPointFDir(PointF const & dst, PointF const & src) +void TestPointDDir(PointD const & dst, PointD const & src) { - float len1 = dst.Length(); - float len2 = src.Length(); + double len1 = dst.Length(); + double len2 = src.Length(); TEST_ALMOST_EQUAL(dst.x/len1, src.x/len2, ()); TEST_ALMOST_EQUAL(dst.y/len1, src.y/len2, ()); } UNIT_TEST(SmoothedDirections) { - vector path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl(path); - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrt(2.0); Spline::iterator itr; - PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f); - PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f); + PointD dir1(sqrt2 / 2.0, sqrt2 / 2.0); + PointD dir2(sqrt2 / 2.0, -sqrt2 / 2.0); itr.Attach(spl); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(sqrt2 * 30.0f); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_avrDir, dir1 * 0.25f + dir2 * 0.75f); - itr.Step(sqrt2 * 10.0f); - TestPointFDir(itr.m_avrDir, dir2); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(sqrt2 * 30.0); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_avrDir, dir1 * 0.25 + dir2 * 0.75); + itr.Step(sqrt2 * 10.0); + TestPointDDir(itr.m_avrDir, dir2); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); - PointF dir12(1.0f, 0.0f); + PointD dir12(1.0, 0.0); Spline spl2(path); itr.Attach(spl2); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(sqrt2 * 80.0f + 40.0f); - TestPointFDir(itr.m_avrDir, dir12); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(sqrt2 * 80.0 + 40.0); + TestPointDDir(itr.m_avrDir, dir12); itr.Attach(spl2); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_avrDir, dir1); - itr.Step(80.0f); - TestPointFDir(itr.m_avrDir, dir12 * 0.5f + dir2 * 0.5f); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_avrDir, dir1); + itr.Step(80.0); + TestPointDDir(itr.m_avrDir, dir12 * 0.5 + dir2 * 0.5); } UNIT_TEST(UsualDirections) { - vector path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl(path); - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrtf(2.0); Spline::iterator itr; - PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f); - PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f); + PointD dir1(sqrt2 / 2.0, sqrt2 / 2.0); + PointD dir2(sqrt2 / 2.0, -sqrt2 / 2.0); itr.Attach(spl); - TestPointFDir(itr.m_dir, dir1); - itr.Step(sqrt2 * 30.0f); - TestPointFDir(itr.m_dir, dir1); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_dir, dir2); + TestPointDDir(itr.m_dir, dir1); + itr.Step(sqrt2 * 30.0); + TestPointDDir(itr.m_dir, dir1); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_dir, dir2); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); - PointF dir12(1.0f, 0.0f); + PointD dir12(1.0, 0.0); Spline spl2(path); itr.Attach(spl2); - TestPointFDir(itr.m_dir, dir1); - itr.Step(sqrt2 * 80.0f + 35.0f); - TestPointFDir(itr.m_dir, dir2); + TestPointDDir(itr.m_dir, dir1); + itr.Step(sqrt2 * 80.0 + 35.0); + TestPointDDir(itr.m_dir, dir2); itr.Attach(spl2); - itr.Step(sqrt2 * 45.0f); - TestPointFDir(itr.m_dir, dir12); - itr.Step(80.0f); - TestPointFDir(itr.m_dir, dir2); + itr.Step(sqrt2 * 45.0); + TestPointDDir(itr.m_dir, dir12); + itr.Step(80.0); + TestPointDDir(itr.m_dir, dir2); } UNIT_TEST(Positions) { - vector path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl0(path); Spline spl4; spl4 = spl0; - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrt(2.0); Spline::iterator itr; itr.Attach(spl0); - TestPointFDir(itr.m_pos, PointF(0, 0)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(40, 40)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(80, 0)); + TestPointDDir(itr.m_pos, PointD(0, 0)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(40, 40)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(80, 0)); itr.Attach(spl4); - TestPointFDir(itr.m_pos, PointF(0, 0)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(40, 40)); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(80, 0)); + TestPointDDir(itr.m_pos, PointD(0, 0)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(40, 40)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(80, 0)); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); Spline spl2(path); Spline spl3 = spl2; itr.Attach(spl3); - TestPointFDir(itr.m_pos, PointF(0, 0)); - itr.Step(sqrt2 * 80.0f + 40.0f); - TestPointFDir(itr.m_pos, PointF(120, 0)); + TestPointDDir(itr.m_pos, PointD(0, 0)); + itr.Step(sqrt2 * 80.0 + 40.0); + TestPointDDir(itr.m_pos, PointD(120, 0)); itr.Attach(spl2); - itr.Step(sqrt2 * 40.0f); - TestPointFDir(itr.m_pos, PointF(40, 40)); - itr.Step(2.0f); - TestPointFDir(itr.m_pos, PointF(42, 40)); - itr.Step(20.0f); - TestPointFDir(itr.m_pos, PointF(62, 40)); - itr.Step(18.0f); - TestPointFDir(itr.m_pos, PointF(80, 40)); + itr.Step(sqrt2 * 40.0); + TestPointDDir(itr.m_pos, PointD(40, 40)); + itr.Step(2.0); + TestPointDDir(itr.m_pos, PointD(42, 40)); + itr.Step(20.0); + TestPointDDir(itr.m_pos, PointD(62, 40)); + itr.Step(18.0); + TestPointDDir(itr.m_pos, PointD(80, 40)); } UNIT_TEST(BeginAgain) { - vector path; - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 0)); + vector path; + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 0)); Spline spl(path); - float const sqrt2 = sqrtf(2.0f); + double const sqrt2 = sqrtf(2.0); Spline::iterator itr; - PointF dir1(sqrt2 / 2.0f, sqrt2 / 2.0f); - PointF dir2(sqrt2 / 2.0f, -sqrt2 / 2.0f); + PointD dir1(sqrt2 / 2.0, sqrt2 / 2.0); + PointD dir2(sqrt2 / 2.0, -sqrt2 / 2.0); itr.Attach(spl); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), true, ()); - itr.Step(190.0f); + itr.Step(190.0); TEST_EQUAL(itr.BeginAgain(), true, ()); path.clear(); - path.push_back(PointF(0, 0)); - path.push_back(PointF(40, 40)); - path.push_back(PointF(80, 40)); - path.push_back(PointF(120, 0)); + path.push_back(PointD(0, 0)); + path.push_back(PointD(40, 40)); + path.push_back(PointD(80, 40)); + path.push_back(PointD(120, 0)); Spline spl2(path); itr.Attach(spl2); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), false, ()); - itr.Step(90.0f); + itr.Step(90.0); TEST_EQUAL(itr.BeginAgain(), true, ()); - itr.Step(190.0f); + itr.Step(190.0); TEST_EQUAL(itr.BeginAgain(), true, ()); } UNIT_TEST(Length) { - vector path; - PointF const p1(27.5536633f, 64.2492523f); - PointF const p2(27.5547638f, 64.2474289f); - PointF const p3(27.5549412f, 64.2471237f); - PointF const p4(27.5559044f, 64.2456436f); - PointF const p5(27.556284f, 64.2451782f); + vector path; + PointD const p1(27.5536633, 64.2492523); + PointD const p2(27.5547638, 64.2474289); + PointD const p3(27.5549412, 64.2471237); + PointD const p4(27.5559044, 64.2456436); + PointD const p5(27.556284, 64.2451782); path.push_back(p1); path.push_back(p2); path.push_back(p3); path.push_back(p4); path.push_back(p5); Spline spl(path); - float len1 = spl.GetLength(); - float l1 = p1.Length(p2); - float l2 = p2.Length(p3); - float l3 = p3.Length(p4); - float l4 = p4.Length(p5); - float len2 = l1 + l2 + l3 + l4; + double len1 = spl.GetLength(); + double l1 = p1.Length(p2); + double l2 = p2.Length(p3); + double l3 = p3.Length(p4); + double l4 = p4.Length(p5); + double len2 = l1 + l2 + l3 + l4; TEST_ALMOST_EQUAL(len1, len2, ()); } diff --git a/geometry/spline.cpp b/geometry/spline.cpp index aafaa51462..7125aa3ffa 100644 --- a/geometry/spline.cpp +++ b/geometry/spline.cpp @@ -7,13 +7,13 @@ namespace m2 { -Spline::Spline(vector const & path) +Spline::Spline(vector const & path) { ASSERT(path.size() > 1, ("Wrong path size!")); m_position.assign(path.begin(), path.end()); int cnt = m_position.size() - 1; - m_direction = vector(cnt); - m_length = vector(cnt); + m_direction = vector(cnt); + m_length = vector(cnt); for(int i = 0; i < cnt; ++i) { @@ -23,7 +23,7 @@ Spline::Spline(vector const & path) } } -void Spline::AddPoint(PointF const & pt) +void Spline::AddPoint(PointD const & pt) { /// TODO remove this check when fix generator. /// Now we have line objects with zero length segments @@ -37,7 +37,7 @@ void Spline::AddPoint(PointF const & pt) m_position.push_back(pt); else { - PointF dir = pt - m_position.back(); + PointD dir = pt - m_position.back(); m_position.push_back(pt); m_length.push_back(dir.Length()); m_direction.push_back(dir.Normalize()); @@ -65,9 +65,9 @@ Spline const & Spline::operator = (Spline const & spl) return *this; } -float Spline::GetLength() const +double Spline::GetLength() const { - return accumulate(m_length.begin(), m_length.end(), 0.0f); + return accumulate(m_length.begin(), m_length.end(), 0.0); } Spline::iterator::iterator() @@ -87,7 +87,7 @@ void Spline::iterator::Attach(Spline const & spl) m_pos = m_spl->m_position[m_index] + m_dir * m_dist; } -void Spline::iterator::Step(float speed) +void Spline::iterator::Step(double speed) { m_dist += speed; while(m_dist > m_spl->m_length[m_index]) @@ -111,7 +111,7 @@ bool Spline::iterator::BeginAgain() const return m_checker; } -float Spline::iterator::GetDistance() const +double Spline::iterator::GetDistance() const { return m_dist; } @@ -121,7 +121,7 @@ int Spline::iterator::GetIndex() const return m_index; } -SharedSpline::SharedSpline(vector const & path) +SharedSpline::SharedSpline(vector const & path) { m_spline.reset(new Spline(path)); } @@ -149,7 +149,7 @@ void SharedSpline::Reset(Spline * spline) m_spline.reset(spline); } -void SharedSpline::Reset(vector const & path) +void SharedSpline::Reset(vector const & path) { m_spline.reset(new Spline(path)); } diff --git a/geometry/spline.hpp b/geometry/spline.hpp index 9abf8e1dc1..d87ad385b8 100644 --- a/geometry/spline.hpp +++ b/geometry/spline.hpp @@ -14,33 +14,33 @@ public: class iterator { public: - PointF m_pos; - PointF m_dir; - PointF m_avrDir; + PointD m_pos; + PointD m_dir; + PointD m_avrDir; iterator(); void Attach(Spline const & spl); - void Step(float speed); + void Step(double speed); bool BeginAgain() const; private: friend class Spline; - float GetDistance() const; + double GetDistance() const; int GetIndex() const; private: bool m_checker; Spline const * m_spl; int m_index; - float m_dist; + double m_dist; }; public: Spline() {} - Spline(vector const & path); + Spline(vector const & path); Spline const & operator = (Spline const & spl); - void AddPoint(PointF const & pt); - vector const & GetPath() const { return m_position; } + void AddPoint(PointD const & pt); + vector const & GetPath() const { return m_position; } template void ForEachNode(iterator const & begin, iterator const & end, TFunctor & f) const @@ -59,25 +59,25 @@ public: bool IsEmpty() const; bool IsValid() const; - float GetLength() const; + double GetLength() const; private: - vector m_position; - vector m_direction; - vector m_length; + vector m_position; + vector m_direction; + vector m_length; }; class SharedSpline { public: SharedSpline() {} - SharedSpline(vector const & path); + SharedSpline(vector const & path); SharedSpline(SharedSpline const & other); SharedSpline const & operator= (SharedSpline const & spl); bool IsNull() const; void Reset(Spline * spline); - void Reset(vector const & path); + void Reset(vector const & path); Spline::iterator CreateIterator() const;