-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFractal_Element.cpp
78 lines (67 loc) · 2.24 KB
/
Fractal_Element.cpp
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
#include "Fractal_Element.h"
#include "config.h"
Fractal_Element::Fractal_Element(std::vector<Line>* _statics):
m_baseline(Line::lt_base, sf::Vector2f(0,0), sf::Vector2f(0,0)),
statics(_statics),
m_statics_end(_statics->size()),
m_maxLength(0)
{
}
Fractal_Element::~Fractal_Element() {
}
double Fractal_Element::BaseLength() {
return m_baseline.Length();
}
double Fractal_Element::GetMaxLength() {
return m_maxLength;
}
void Fractal_Element::AddLine(Line newLine) {
switch (newLine.GetType()) {
case Line::line_type::lt_hidden:
// Hidden lines are useless for iteration, so don't keep track of them.
break;
case Line::line_type::lt_static:
statics->push_back(newLine);
m_statics_end++;
break;
default:
if(newLine.Length() < config::infinity_stop_size) {
newLine.SetType(Line::lt_static);
AddLine(newLine);
} else {
double newLen = newLine.Length();
m_lines.push_back(newLine);
if(newLen > m_maxLength)
m_maxLength = newLen;
}
break;
}
}
const std::vector<Line>& Fractal_Element::GetLines() const {
return m_lines;
}
Fractal_Element Fractal_Element::ReplaceAll(const Fractal_Template& target) const {
Fractal_Element newFE(statics);
for(auto line_it = m_lines.begin(); line_it != m_lines.end(); line_it++) {
Fractal_Template transformed = target.TransformAll(target.MatchBase(*line_it));
std::vector<Line> transLines = transformed.GetLines();
for(auto trans_it = transLines.begin(); trans_it != transLines.end(); trans_it++) {
newFE.AddLine(*trans_it);
}
}
newFE.SetBase(m_baseline.GetStart(), m_baseline.GetFinish());
return newFE;
}
void Fractal_Element::Draw(sf::RenderTarget& target, Line::draw_type style) const {
for(auto line_it = m_lines.begin(); line_it != m_lines.end(); line_it++) {
line_it->Draw(target, style);
}
auto line_it = statics->begin();
for(size_t iii = 0; iii < m_statics_end; iii++) {
line_it->Draw(target, style);
line_it++;
}
}
void Fractal_Element::SetBase(sf::Vector2f start, sf::Vector2f finish) {
m_baseline.SetPosition(start, finish);
}