src/inputvertices.cpp

Tue, 11 Apr 2023 20:27:04 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 11 Apr 2023 20:27:04 +0300
changeset 375
21a5ecbe34e4
parent 322
a39f454a3d7f
permissions
-rw-r--r--

Simplify signature of updateRenderPreferences

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

mercurial