blob: d1a50dc2adada479f9fead8b10e25983b270257d (
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
101
102
103
104
105
106
107
108
109
110
111
|
#pragma once
#include "geometry/point2d.hpp"
#include <memory>
#include <vector>
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;
size_t GetIndex() const;
bool IsAttached() const;
private:
friend class Spline;
double GetDistance() const;
void AdvanceForward(double step);
void AdvanceBackward(double step);
private:
bool m_checker;
Spline const * m_spl;
size_t m_index;
double m_dist;
};
public:
Spline() {}
Spline(size_t reservedSize);
Spline(std::vector<PointD> const & path);
Spline const & operator = (Spline const & spl);
void AddPoint(PointD const & pt);
void ReplacePoint(PointD const & pt);
bool IsPrelonging(PointD const & pt);
size_t GetSize() const;
std::vector<PointD> const & GetPath() const { return m_position; }
std::vector<double> const & GetLengths() const { return m_length; }
std::vector<PointD> const & GetDirections() const { return m_direction; }
void Clear();
iterator GetPoint(double step) const;
template <typename TFunctor>
void ForEachNode(iterator const & begin, iterator const & end, TFunctor const & f) const
{
ASSERT(begin.BeginAgain() == false, ());
ASSERT(end.BeginAgain() == false, ());
f(begin.m_pos);
for (size_t 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:
std::vector<PointD> m_position;
std::vector<PointD> m_direction;
std::vector<double> m_length;
};
class SharedSpline
{
public:
SharedSpline() {}
SharedSpline(std::vector<PointD> const & path);
SharedSpline(SharedSpline const & other);
SharedSpline const & operator= (SharedSpline const & spl);
bool IsNull() const;
void Reset(Spline * spline);
void Reset(std::vector<PointD> const & path);
Spline::iterator CreateIterator() const;
Spline * operator->();
Spline const * operator->() const;
Spline const * Get() const;
private:
std::shared_ptr<Spline> m_spline;
};
} // namespace m2
|