summaryrefslogtreecommitdiff
path: root/utility
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-23 17:50:26 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-23 17:50:26 +0000
commit293a885381a3717f01b546a8d8b1e34856440dc9 (patch)
tree3901acd435aadb3d2de8b84ac119b10146460ec2 /utility
parentAdd meandering support (diff)
downloadilt-293a885381a3717f01b546a8d8b1e34856440dc9.tar.bz2
ilt-293a885381a3717f01b546a8d8b1e34856440dc9.tar.xz
ilt-293a885381a3717f01b546a8d8b1e34856440dc9.zip
As suspected, find_arc_centre could be simplfied
Diffstat (limited to 'utility')
-rw-r--r--utility/maths.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/utility/maths.cpp b/utility/maths.cpp
index 74a3085..bda6ea6 100644
--- a/utility/maths.cpp
+++ b/utility/maths.cpp
@@ -3,7 +3,6 @@
#include <glm/glm.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/transform.hpp>
-#include <initializer_list>
#include <stdexcept>
glm::mat4
@@ -66,22 +65,16 @@ find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye)
if (as == bs) {
return {as, false};
}
- for (const auto lr : {1.F, -1.F}) { // left or right turn (maybe possible with removal of positve check below)
- const auto perps = entrys + (half_pi * lr);
- const auto perpe = entrye - (half_pi * lr);
- const glm::vec2 ad {std::sin(perps), std::cos(perps)};
- const glm::vec2 bd {std::sin(perpe), std::cos(perpe)};
+ const auto perps = entrys + half_pi;
+ const auto perpe = entrye - half_pi;
+ const glm::vec2 ad {std::sin(perps), std::cos(perps)};
+ const glm::vec2 bd {std::sin(perpe), std::cos(perpe)};
- const auto dx = bs.x - as.x;
- const auto dy = bs.y - as.y;
- const auto det = bd.x * ad.y - bd.y * ad.x;
- if (det != 0) { // near parallel line will yield noisy results
- const auto u = (dy * bd.x - dx * bd.y) / det;
- const auto v = (dy * ad.x - dx * ad.y) / det;
- if (u >= 0 && v >= 0) {
- return {as + ad * u, lr < 0};
- }
- }
+ const auto det = bd.x * ad.y - bd.y * ad.x;
+ if (det != 0) { // near parallel line will yield noisy results
+ const auto d = bs - as;
+ const auto u = (d.y * bd.x - d.x * bd.y) / det;
+ return {as + ad * u, u < 0};
}
throw std::runtime_error("no intersection");
}