|
1 #include "src/inputvertices.h" |
|
2 |
|
3 bool InputVertices::currentPointOnExistingPoint() const |
|
4 { |
|
5 const glm::vec3& pos = this->polygon.back(); |
|
6 return std::any_of( |
|
7 this->polygon.begin(), |
|
8 this->polygon.end() - 1, |
|
9 [&pos](const glm::vec3& p){return isclose(pos, p);}); |
|
10 } |
|
11 |
|
12 std::size_t InputVertices::calcNumPoints() const |
|
13 { |
|
14 std::size_t result = this->polygon.size(); |
|
15 if (this->currentPointOnExistingPoint()) { |
|
16 result -= 1; |
|
17 } |
|
18 return result; |
|
19 } |
|
20 |
|
21 void InputVertices::updateCurrentPoint(const glm::vec3& p) |
|
22 { |
|
23 this->polygon.back() = p; |
|
24 this->numpoints = this->calcNumPoints(); |
|
25 } |
|
26 |
|
27 void InputVertices::removeLastPoint() |
|
28 { |
|
29 if (this->polygon.size() > 1) { |
|
30 this->polygon.erase(this->polygon.end() - 2); |
|
31 this->numpoints = this->calcNumPoints(); |
|
32 } |
|
33 } |
|
34 |
|
35 void InputVertices::finishCurrentPoint() |
|
36 { |
|
37 this->polygon.push_back(this->polygon.back()); |
|
38 } |
|
39 |
|
40 void InputVertices::clear() |
|
41 { |
|
42 *this = {}; |
|
43 } |