From 80529930ea3bc874c8da22c66343745ff6fdd45b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 24 Feb 2024 00:10:27 +0000 Subject: Simplify vector addition/subtraction with differnt types Automatically applies correct rounding with float to int operations, adjusts test expectations accordingly. --- game/geoData.cpp | 3 +-- game/geoData.h | 3 +-- game/network/link.cpp | 5 ++--- game/network/network.cpp | 8 ++++---- game/network/rail.cpp | 8 ++++---- game/vehicles/railVehicle.cpp | 2 +- 6 files changed, 13 insertions(+), 16 deletions(-) (limited to 'game') diff --git a/game/geoData.cpp b/game/geoData.cpp index b30a35b..359e8c0 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -204,8 +204,7 @@ GeoData::intersectRay(const Ray & ray, FaceHandle face) const { std::optional out; walkUntil(PointFace {ray.start, face}, - ray.start.xy() - + GlobalPosition2D(ray.direction.xy() * RelativePosition2D(upperExtent.xy() - lowerExtent.xy())), + ray.start.xy() + (ray.direction.xy() * RelativePosition2D(upperExtent.xy() - lowerExtent.xy())), [&out, &ray, this](FaceHandle face) { BaryPosition bari {}; RelativeDistance dist {}; diff --git a/game/geoData.h b/game/geoData.h index e234bfe..15143e8 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -65,8 +65,7 @@ public: operator*(BaryPosition bari) const { const auto & t {*this}; - return t[0] + GlobalPosition(RelativePosition(t[1] - t[0]) * bari.x) - + GlobalPosition(RelativePosition(t[2] - t[1]) * bari.y); + return t[0] + (RelativePosition(t[1] - t[0]) * bari.x) + (RelativePosition(t[2] - t[1]) * bari.y); } }; diff --git a/game/network/link.cpp b/game/network/link.cpp index 932fc67..122eaf4 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -28,8 +28,7 @@ LinkStraight::positionAt(RelativeDistance dist, unsigned char start) const const auto es {std::make_pair(ends[start].node.get(), ends[1 - start].node.get())}; const RelativePosition3D diff {es.second->pos - es.first->pos}; const auto dir {glm::normalize(diff)}; - return Location {es.first->pos + GlobalPosition3D(vehiclePositionOffset() + dir * dist), - {vector_pitch(dir), vector_yaw(dir), 0}}; + return Location {es.first->pos + (vehiclePositionOffset() + dir * dist), {vector_pitch(dir), vector_yaw(dir), 0}}; } bool @@ -70,7 +69,7 @@ LinkCurve::intersectRay(const Ray & ray) const points.reserve(segCount); for (std::remove_const_t swing = {arc.first, centreBase.z - e0p.z}; segCount; swing += step, --segCount) { - points.emplace_back(centreBase + GlobalPosition3D((sincosf(swing.x) * radius) || swing.y)); + points.emplace_back(centreBase + ((sincosf(swing.x) * radius) || swing.y)); } return ray.passesCloseToEdges(points, 1.F); } diff --git a/game/network/network.cpp b/game/network/network.cpp index b6c52b8..65b2a62 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -121,16 +121,16 @@ Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & en }; if (const auto radii = find_arcs_radius(flatStart, startDir, flatEnd, endDir); radii.first < radii.second) { const auto radius {radii.first}; - const auto c1 = flatStart + GlobalPosition2D(sincosf(startDir + half_pi) * radius); - const auto c2 = flatEnd + GlobalPosition2D(sincosf(endDir + half_pi) * radius); + const auto c1 = flatStart + (sincosf(startDir + half_pi) * radius); + const auto c2 = flatEnd + (sincosf(endDir + half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); return {{start, midh, c1}, {end, midh, c2}}; } else { const auto radius {radii.second}; - const auto c1 = flatStart + GlobalPosition2D(sincosf(startDir - half_pi) * radius); - const auto c2 = flatEnd + GlobalPosition2D(sincosf(endDir - half_pi) * radius); + const auto c1 = flatStart + (sincosf(startDir - half_pi) * radius); + const auto c2 = flatEnd + (sincosf(endDir - half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); return {{midh, start, c1}, {midh, end, c2}}; diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 176a704..34cbceb 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -45,8 +45,8 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) const float dir2 = pi + findNodeDirection(node2ins.first); if (const auto radii = find_arcs_radius(flatStart, dir, flatEnd, dir2); radii.first < radii.second) { const auto radius {radii.first}; - const auto c1 = flatStart + GlobalPosition2D(sincosf(dir + half_pi) * radius); - const auto c2 = flatEnd + GlobalPosition2D(sincosf(dir2 + half_pi) * radius); + const auto c1 = flatStart + (sincosf(dir + half_pi) * radius); + const auto c2 = flatEnd + (sincosf(dir2 + half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); addLink(start, midh, c1); @@ -54,8 +54,8 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) } else { const auto radius {radii.second}; - const auto c1 = flatStart + GlobalPosition2D(sincosf(dir - half_pi) * radius); - const auto c2 = flatEnd + GlobalPosition2D(sincosf(dir2 - half_pi) * radius); + const auto c1 = flatStart + (sincosf(dir - half_pi) * radius); + const auto c2 = flatEnd + (sincosf(dir2 - half_pi) * radius); const auto mid = (c1 + c2) / 2; const auto midh = mid || midheight(mid); addLink(midh, start, c1); diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index 4a1fdab..59d1e83 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -51,7 +51,7 @@ RailVehicle::intersectRay(const Ray & ray, BaryPosition & bary constexpr const auto Z = 3900.F; const glm::mat3 moveBy = location.getRotationTransform(); const auto cornerVertices = cuboidCorners(-X, X, -Y, Y, 0.F, Z) * [&moveBy, this](const auto & corner) { - return location.position() + GlobalPosition3D(moveBy * corner); + return location.position() + (moveBy * corner); }; static constexpr const std::array, 10> triangles {{ // Front -- cgit v1.2.3