diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-01-30 16:17:17 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:36:52 +0300 |
commit | c23a1907cdcf70d06c29017a7a5a685502623baa (patch) | |
tree | beab6d47e0bcef53699393936d47299fb821e9a0 /geometry | |
parent | 868359ba1f2d4b68eecee102c3a768f76892afca (diff) |
Crash and memory leak was fixed.
Diffstat (limited to 'geometry')
-rw-r--r-- | geometry/geometry_tests/point_test.cpp | 25 | ||||
-rw-r--r-- | geometry/point2d.hpp | 19 |
2 files changed, 21 insertions, 23 deletions
diff --git a/geometry/geometry_tests/point_test.cpp b/geometry/geometry_tests/point_test.cpp index 71eaa24964..6c24dad228 100644 --- a/geometry/geometry_tests/point_test.cpp +++ b/geometry/geometry_tests/point_test.cpp @@ -59,26 +59,23 @@ UNIT_TEST(PointInTriangle_EmptyTriangle) } /// @todo add more tests -UNIT_TEST(ArrowPoints) +UNIT_TEST(GetArrowPoints) { - m2::PointF p1, p2, p3; + array<m2::PointF, 3> arrPntsFlt; + m2::GetArrowPoints(m2::PointF(0, 0), m2::PointF(1, 0), 1.f, 1.f, arrPntsFlt); + TEST(m2::AlmostEqual(arrPntsFlt[0], m2::PointF(1.f, 1.f)), ()); + TEST(m2::AlmostEqual(arrPntsFlt[1], m2::PointF(2.f, 0.f)), ()); + TEST(m2::AlmostEqual(arrPntsFlt[2], m2::PointF(1.f, -1.f)), ()); - m2::ArrowPoints(m2::PointF(0, 0), m2::PointF(1, 0), 1.f, 1.f, p1, p2, p3); - TEST(m2::AlmostEqual(p1, m2::PointF(1.f, 1.f)), ()); - TEST(m2::AlmostEqual(p2, m2::PointF(2.f, 0.f)), ()); - TEST(m2::AlmostEqual(p3, m2::PointF(1.f, -1.f)), ()); - - m2::PointD d1, d2, d3; - m2::ArrowPoints(m2::PointD(-1., 2.), m2::PointD(-1., 100.), 2., 5., d1, d2, d3); - TEST(m2::AlmostEqual(d1, m2::PointD(-3.f, 100.f)), ()); - TEST(m2::AlmostEqual(d2, m2::PointD(-1.f, 105.f)), ()); - TEST(m2::AlmostEqual(d3, m2::PointD(1.f, 100.f)), ()); + array<m2::PointD, 3> arrPntsDbl; + m2::GetArrowPoints(m2::PointD(-1., 2.), m2::PointD(-1., 100.), 2., 5., arrPntsDbl); + TEST(m2::AlmostEqual(arrPntsDbl[0], m2::PointD(-3.f, 100.f)), ()); + TEST(m2::AlmostEqual(arrPntsDbl[1], m2::PointD(-1.f, 105.f)), ()); + TEST(m2::AlmostEqual(arrPntsDbl[2], m2::PointD(1.f, 100.f)), ()); } UNIT_TEST(PointAtSegment) { - m2::PointF p1, p2, p3; - TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(1, 0), 0.5f), m2::PointF(0.5f, 0.f)), ()); TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointF(0, 0), m2::PointF(0, 1), 0.3f), m2::PointF(0.f, 0.3f)), ()); TEST(m2::AlmostEqual(m2::PointAtSegment(m2::PointD(0., 0.), m2::PointD(30., 40.), 5.), m2::PointD(3., 4.)), ()); diff --git a/geometry/point2d.hpp b/geometry/point2d.hpp index f37195b4bf..faad7cef79 100644 --- a/geometry/point2d.hpp +++ b/geometry/point2d.hpp @@ -7,6 +7,7 @@ #include "../std/cmath.hpp" #include "../std/sstream.hpp" #include "../std/typeinfo.hpp" +#include "../std/array.hpp" namespace m2 @@ -321,18 +322,18 @@ namespace m2 /// Calculate three point of a triangle (p1, p2 and p3) which gives a arrow at the end of segment s, f /// with respect to w - arrow's width and l - arrow's length - template <typename T> - void ArrowPoints(Point<T> const & b, Point<T> const & e, T w, T l, - Point<T> & p1, Point<T> & p2, Point<T> & p3) + template <typename T, typename TT, typename PointT = Point<T>> + void GetArrowPoints(PointT const & b, PointT const & e, T w, T l, array<Point<TT>, 3> & arrPnts) { ASSERT(!m2::AlmostEqual(b, e), ()); - Point<T> const beVec = e - b; - Point<T> beNormalizedVec = beVec.Normalize(); - pair<Point<T>, Point<T> > beNormVecs = beNormalizedVec.Normals(w); - p1 = e + beNormVecs.first; - p2 = e + beNormalizedVec * l; - p3 = e + beNormVecs.second; + PointT const beVec = e - b; + PointT beNormalizedVec = beVec.Normalize(); + pair<PointT, PointT > beNormVecs = beNormalizedVec.Normals(w); + + arrPnts[0] = e + beNormVecs.first; + arrPnts[1] = e + beNormalizedVec * l; + arrPnts[2] = e + beNormVecs.second; } /// Returns a point which is belonged to the segment p1, p2 with respet the indent shiftFromP1 from p1. |