blob: 12c5c77e79e819a5a2fcd1a42428162f165e044b (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#pragma once
#include "../std/vector.hpp"
#include "../std/shared_ptr.hpp"
#include "point2d.hpp"
namespace m2
{
class Spline
{
public:
class iterator
{
public:
PointD m_pos;
PointD m_dir;
PointD m_avrDir;
iterator();
iterator(iterator const & other);
iterator & operator=(iterator const & other);
void Attach(Spline const & spl);
void Advance(double step);
bool BeginAgain() const;
double GetLength() const;
double GetFullLength() const;
private:
friend class Spline;
double GetDistance() const;
int GetIndex() const;
void AdvanceForward(double step);
void AdvanceBackward(double step);
private:
bool m_checker;
Spline const * m_spl;
int m_index;
double m_dist;
};
public:
Spline() {}
Spline(vector<PointD> const & path);
Spline const & operator = (Spline const & spl);
void AddPoint(PointD const & pt);
vector<PointD> const & GetPath() const { return m_position; }
template <typename TFunctor>
void ForEachNode(iterator const & begin, iterator const & end, TFunctor & f) const
{
ASSERT(begin.BeginAgain() == false, ());
ASSERT(end.BeginAgain() == false, ());
f(begin.m_pos);
for (int i = begin.GetIndex() + 1; i <= end.GetIndex(); ++i)
f(m_position[i]);
f(end.m_pos);
}
bool IsEmpty() const;
bool IsValid() const;
double GetLength() const;
private:
vector<PointD> m_position;
vector<PointD> m_direction;
vector<double> m_length;
};
class SharedSpline
{
public:
SharedSpline() {}
SharedSpline(vector<PointD> const & path);
SharedSpline(SharedSpline const & other);
SharedSpline const & operator= (SharedSpline const & spl);
bool IsNull() const;
void Reset(Spline * spline);
void Reset(vector<PointD> const & path);
Spline::iterator CreateIterator() const;
Spline * operator->();
Spline const * operator->() const;
private:
shared_ptr<Spline> m_spline;
};
}
|