diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-03-21 20:09:34 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-03-21 20:09:34 +0000 |
commit | 31f73b6f44f3deac749af41e84435f5bc9b037f2 (patch) | |
tree | e9de1a70be1256f1ad6929d52631f3e3b68f42a6 | |
parent | vector_yaw only needs 2 dimensions (diff) | |
download | ilt-31f73b6f44f3deac749af41e84435f5bc9b037f2.tar.bz2 ilt-31f73b6f44f3deac749af41e84435f5bc9b037f2.tar.xz ilt-31f73b6f44f3deac749af41e84435f5bc9b037f2.zip |
Make arc_length a member function
-rw-r--r-- | game/network/link.cpp | 2 | ||||
-rw-r--r-- | game/network/rail.cpp | 2 | ||||
-rw-r--r-- | lib/maths.h | 12 |
3 files changed, 8 insertions, 8 deletions
diff --git a/game/network/link.cpp b/game/network/link.cpp index 122eaf4..248fe7d 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -62,7 +62,7 @@ LinkCurve::intersectRay(const Ray<GlobalPosition3D> & ray) const const auto & e1p {ends[1].node->pos}; const auto slength = round_frac(length / 2.F, 5.F); const auto segs = std::round(15.F * slength / std::pow(radius, 0.7F)); - const auto step {glm::vec<2, RelativeDistance> {arc_length(arc), e1p.z - e0p.z} / segs}; + const auto step {glm::vec<2, RelativeDistance> {arc.length(), e1p.z - e0p.z} / segs}; auto segCount = static_cast<std::size_t>(std::lround(segs)) + 1; std::vector<GlobalPosition3D> points; diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 34cbceb..e342224 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -118,7 +118,7 @@ RailLinkCurve::RailLinkCurve( RailLinkCurve::RailLinkCurve(NetworkLinkHolder<RailLinkCurve> & instances, const Node::Ptr & a, const Node::Ptr & b, GlobalPosition3D c, const Arc arc) : Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)}, - glm::length(RelativePosition3D(a->pos - c)) * arc_length(arc)), + glm::length(RelativePosition3D(a->pos - c)) * arc.length()), LinkCurve {c, glm::length(RelativePosition3D(ends[0].node->pos - c)), arc}, instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2000.F), half_pi - arc.first, half_pi - arc.second, radius)} diff --git a/lib/maths.h b/lib/maths.h index ce18b3f..20a397b 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -19,6 +19,12 @@ struct Arc : public std::pair<float, float> { { return i ? second : first; } + + [[nodiscard]] constexpr inline float + length() const + { + return second - first; + } }; constexpr const RelativePosition3D up {0, 0, 1}; @@ -171,12 +177,6 @@ operator%=(glm::vec<L, T, Q> & p, const glm::mat<L + 1, L + 1, T, Q> & mutation) return p = p % mutation; } -constexpr inline float -arc_length(const Arc & arc) -{ - return arc.second - arc.first; -} - float normalize(float ang); template<typename T, glm::qualifier Q> |