summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-05-11 10:15:31 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-05-11 10:15:31 +0100
commit2a768eed79e1dbccd389a31a0d593729c9aef4f8 (patch)
treef63c1e7ef1f9eca4cc32789ace568813b9571cea /game
parentFix conditional render of rail links (diff)
downloadilt-2a768eed79e1dbccd389a31a0d593729c9aef4f8.tar.bz2
ilt-2a768eed79e1dbccd389a31a0d593729c9aef4f8.tar.xz
ilt-2a768eed79e1dbccd389a31a0d593729c9aef4f8.zip
Link helper to get an End pointer based on position
Diffstat (limited to 'game')
-rw-r--r--game/network/link.cpp12
-rw-r--r--game/network/link.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/game/network/link.cpp b/game/network/link.cpp
index b8ffee2..1a4bb89 100644
--- a/game/network/link.cpp
+++ b/game/network/link.cpp
@@ -7,6 +7,18 @@
Link::Link(End endA, End endB, float len) : ends {{std::move(endA), std::move(endB)}}, length {len} { }
+const Link::End *
+Link::endAt(const GlobalPosition3D & queryPos) const
+{
+ if (ends.front().node->pos == queryPos) {
+ return &ends.front();
+ }
+ if (ends.back().node->pos == queryPos) {
+ return &ends.back();
+ }
+ return nullptr;
+}
+
LinkCurve::LinkCurve(GlobalPosition3D centre, RelativeDistance radius, Arc arc) :
centreBase {centre}, radius {radius}, arc {std::move(arc)}
{
diff --git a/game/network/link.h b/game/network/link.h
index 0b58558..7ef1387 100644
--- a/game/network/link.h
+++ b/game/network/link.h
@@ -48,6 +48,8 @@ public:
[[nodiscard]] virtual bool intersectRay(const Ray<GlobalPosition3D> &) const = 0;
[[nodiscard]] virtual std::vector<GlobalPosition3D> getBase(RelativeDistance width) const = 0;
+ [[nodiscard]] const End * endAt(const GlobalPosition3D &) const;
+
std::array<End, 2> ends;
float length;