diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-05-12 12:50:57 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-05-12 12:50:57 +0100 |
commit | 55c2a0f45d55e404494614c0f45a6bbc8985b0a8 (patch) | |
tree | d292b3ea9053fe9278db955ba38bd61b2719e252 /game | |
parent | Rename terrainSplitAt to connectAt (diff) | |
download | ilt-55c2a0f45d55e404494614c0f45a6bbc8985b0a8.tar.bz2 ilt-55c2a0f45d55e404494614c0f45a6bbc8985b0a8.tar.xz ilt-55c2a0f45d55e404494614c0f45a6bbc8985b0a8.zip |
Standard interface for creating link definitions
2 positions and, 0, 1 or 2 angles; always returns a GenLinksDef
collection.
Diffstat (limited to 'game')
-rw-r--r-- | game/network/network.cpp | 30 | ||||
-rw-r--r-- | game/network/network.h | 7 |
2 files changed, 21 insertions, 16 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp index 5afac7e..70c4e21 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -166,21 +166,27 @@ Network::terrainSplit(const GeoData * geoData, const GenCurveDef & def) const return out; } -GenCurveDef -Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir) +GenLinksDef +Network::genDef(const GlobalPosition3D & start, const GlobalPosition3D & end) +{ + return {GenStraightDef {start, end}}; +} + +GenLinksDef +Network::genDef(const GlobalPosition3D & start, const GlobalPosition3D & end, Angle startDir) { const auto dir = pi + startDir; const auto flatStart = start.xy(), flatEnd = end.xy(); const auto centre = find_arc_centre(flatStart, dir, flatEnd); if (centre.second) { // right hand arc - return {end, start, centre.first}; + return {GenCurveDef {end, start, centre.first}}; } - return {start, end, centre.first}; + return {GenCurveDef {start, end, centre.first}}; } -std::pair<GenCurveDef, GenCurveDef> -Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir, float endDir) +GenLinksDef +Network::genDef(const GlobalPosition3D & start, const GlobalPosition3D & end, Angle startDir, Angle endDir) { // Based on formula/code from https://www.ryanjuckett.com/biarc-interpolation/ const auto startVec = -sincos(startDir); @@ -194,7 +200,7 @@ Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & en if (equalTangents && perpT1) { const auto joint = start + (diff * 0.5F); - return {genCurveDef(start, joint, startDir), genCurveDef(end, joint, endDir)}; + return genDef(start, joint, startDir) + genDef(end, joint, endDir); } const auto vDotT = glm::dot(diff.xy(), endsVecTotal); @@ -210,7 +216,7 @@ Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & en const auto joint = (start + end + ((difference(startVec, endVec) * extLen1) || 0.F)) / 2; - return {genCurveDef(start, joint, startDir), genCurveDef(end, joint, endDir)}; + return genDef(start, joint, startDir) + genDef(end, joint, endDir); } Link::Collection @@ -228,15 +234,13 @@ Network::create(const GeoData * geoData, const CreationDefinition & def) if (def.fromEnd.direction) { if (def.toEnd.direction) { // Two specific directions at both ends, S curves - const auto curves = genCurveDef( - def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction, *def.toEnd.direction); - return {curves.first, curves.second}; + return genDef(def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction, *def.toEnd.direction); } // One specific direction, single curve from there - return {genCurveDef(def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction)}; + return genDef(def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction); } // One specific direction, single curve from the other - return {genCurveDef(def.toEnd.position, def.fromEnd.position, *def.toEnd.direction)}; + return genDef(def.toEnd.position, def.fromEnd.position, *def.toEnd.direction); }; const auto splitDefs = [&linkDefs, this, geoData]() { return std::ranges::fold_left(linkDefs(), GenLinksDef {}, [this, geoData](auto && existing, const auto & def) { diff --git a/game/network/network.h b/game/network/network.h index efacac2..d3370b3 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -66,9 +66,10 @@ public: protected: static void joinLinks(const Link::Ptr & link, const Link::Ptr & oldLink); - static GenCurveDef genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir); - static std::pair<GenCurveDef, GenCurveDef> genCurveDef( - const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir, float endDir); + static GenLinksDef genDef(const GlobalPosition3D & start, const GlobalPosition3D & end); + static GenLinksDef genDef(const GlobalPosition3D & start, const GlobalPosition3D & end, Angle startDir); + static GenLinksDef genDef( + const GlobalPosition3D & start, const GlobalPosition3D & end, Angle startDir, Angle endDir); [[nodiscard]] GenLinksDef terrainSplit(const GeoData *, const GenStraightDef &) const; [[nodiscard]] GenLinksDef terrainSplit(const GeoData *, const GenCurveDef &) const; |