summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 13:06:50 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 13:06:50 +0000
commita117836ed6bbbc750830a96647da88d5506e69f8 (patch)
treecfa56e664c825c4f618c37164b2cffac15bcc0e1
parentSimplify flat_angle (diff)
downloadilt-a117836ed6bbbc750830a96647da88d5506e69f8.tar.bz2
ilt-a117836ed6bbbc750830a96647da88d5506e69f8.tar.xz
ilt-a117836ed6bbbc750830a96647da88d5506e69f8.zip
Construct an Arc from three points
-rw-r--r--game/network/rail.cpp2
-rw-r--r--utility/maths.cpp21
-rw-r--r--utility/maths.h4
3 files changed, 14 insertions, 13 deletions
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index 299c647..1ed59bd 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -79,7 +79,7 @@ RailLinkStraight::RailLinkStraight(NodePtr a, NodePtr b, const glm::vec3 & diff)
}
RailLinkCurve::RailLinkCurve(const NodePtr & a, const NodePtr & b, glm::vec2 c) :
- RailLinkCurve(a, b, {c.x, a->pos.y, c.y}, create_arc(!c, a->pos, b->pos))
+ RailLinkCurve(a, b, {c.x, a->pos.y, c.y}, {!c, a->pos, b->pos})
{
}
diff --git a/utility/maths.cpp b/utility/maths.cpp
index 5cae411..e36c91e 100644
--- a/utility/maths.cpp
+++ b/utility/maths.cpp
@@ -39,15 +39,16 @@ normalize(float ang)
return ang;
}
-Arc
-create_arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p)
+Arc::Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p) :
+ Arc([&]() -> Arc {
+ const auto diffa = e0p - centre3;
+ const auto diffb = e1p - centre3;
+ const auto anga = flat_angle(diffa);
+ const auto angb = [&diffb, &anga]() {
+ const auto angb = flat_angle(diffb);
+ return (angb < anga) ? angb + two_pi : angb;
+ }();
+ return {anga, angb};
+ }())
{
- const auto diffa = centre3 - e0p;
- const auto diffb = centre3 - e1p;
- const auto anga = flat_angle(diffa);
- const auto angb = [&diffb, &anga]() {
- const auto angb = flat_angle(diffb);
- return (angb < anga) ? angb + two_pi : angb;
- }();
- return {anga, angb};
}
diff --git a/utility/maths.h b/utility/maths.h
index 31f5960..572268a 100644
--- a/utility/maths.h
+++ b/utility/maths.h
@@ -8,6 +8,8 @@
struct Arc : public std::pair<float, float> {
using std::pair<float, float>::pair;
+ Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p);
+
float
operator[](unsigned int i) const
{
@@ -44,6 +46,4 @@ arc_length(const Arc & arc)
float normalize(float ang);
-Arc create_arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p);
-
#endif