Welcome to mirror list, hosted at ThFree Co, Russian Federation.

polyline2d.hpp « geometry - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a5da9877edff13d4bc3c2a8db0af279ee8611d53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once

#include "point2d.hpp"
#include "rect2d.hpp"

#include "../base/internal/message.hpp"

#include "../std/vector.hpp"


namespace m2
{

template <typename T>
class PolylineT
{
  vector<Point<T> > m_points;

public:
  PolylineT() {}
  explicit PolylineT(vector<Point<T> > const & points) : m_points(points)
  {
    ASSERT_GREATER(m_points.size(), 1, ());
  }

  double GetLength() const
  {
    // @todo add cached value and lazy init
    double dist = 0;
    for (size_t i = 1; i < m_points.size(); ++i)
      dist += m_points[i-1].Length(m_points[i]);
    return dist;
  }

  Rect<T> GetLimitRect() const
  {
    // @todo add cached value and lazy init
    m2::Rect<T> rect;
    for (size_t i = 0; i < m_points.size(); ++i)
      rect.Add(m_points[i]);
    return rect;
  }

  void Clear() { m_points.clear(); }
  void Add(Point<T> const & pt) { m_points.push_back(pt); }
  void Swap(PolylineT & rhs)
  {
    m_points.swap(rhs.m_points);
  }

  size_t GetSize() const { return m_points.size(); }

  typedef typename vector<Point<T> >::const_iterator IterT;
  IterT Begin() const { return m_points.begin(); }
  IterT End() const { return m_points.end(); }

  friend string DebugPrint(PolylineT<T> const & p)
  {
    return ::DebugPrint(p.m_points);
  }
};

typedef PolylineT<double> PolylineD;

}