summaryrefslogtreecommitdiff
path: root/lib/ray.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-07 13:23:27 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-07 13:23:27 +0000
commit108bf5b2424da06aa2e1735ffd10a2b713834db8 (patch)
treeaf0918a6a266aa7e6ee1d8129df6d5ef9fc4f8ab /lib/ray.cpp
parentRemove more use of legacy types and unnecessary pointers from selectable inte... (diff)
parentRemove Position3D from RailVehicle (diff)
downloadilt-108bf5b2424da06aa2e1735ffd10a2b713834db8.tar.bz2
ilt-108bf5b2424da06aa2e1735ffd10a2b713834db8.tar.xz
ilt-108bf5b2424da06aa2e1735ffd10a2b713834db8.zip
Merge branch 'template-types'
Diffstat (limited to 'lib/ray.cpp')
-rw-r--r--lib/ray.cpp35
1 files changed, 0 insertions, 35 deletions
diff --git a/lib/ray.cpp b/lib/ray.cpp
deleted file mode 100644
index 9fb3648..0000000
--- a/lib/ray.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "ray.h"
-#include <algorithm>
-
-Ray
-Ray::fromPoints(Position3D start, Position3D p)
-{
- return {start, glm::normalize(p - start)};
-}
-
-float
-Ray::distanceToLine(const Position3D & p1, const Position3D & e1) const
-{
- // https://en.wikipedia.org/wiki/Skew_lines
- const auto diff = p1 - e1;
- const auto d1 = glm::normalize(diff);
- const auto &p2 = start, &d2 = direction;
- const auto n = glm::cross(d1, d2);
- const auto n2 = glm::cross(d2, n);
- const auto c1 = p1 + (glm::dot((p2 - p1), n2) / glm::dot(d1, n2)) * d1;
- const auto difflength = glm::length(diff);
- if (glm::length(c1 - p1) > difflength || glm::length(c1 - e1) > difflength) {
- return std::numeric_limits<float>::infinity();
- }
- return glm::abs(glm::dot(n, p1 - p2));
-}
-
-bool
-Ray::passesCloseToEdges(const std::span<const Position3D> positions, float distance) const
-{
- return std::adjacent_find(positions.begin(), positions.end(),
- [this, distance](const Position3D & a, const Position3D & b) {
- return distanceToLine(a, b) <= distance;
- })
- != positions.end();
-}