summaryrefslogtreecommitdiff
path: root/game/network/network.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/network/network.cpp')
-rw-r--r--game/network/network.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp
index a9c9372..70c4e21 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -107,7 +107,7 @@ Network::add(GeoData * geoData, const std::span<const Link::Ptr> links)
}
void
-Network::terrainSplitAt(GenLinkDef & previous, GenLinkDef & next, GlobalPosition3D pos)
+Network::connectAt(GenLinkDef & previous, GenLinkDef & next, GlobalPosition3D pos)
{
std::visit(
[pos](auto & typedDefPrevious, auto & typedDefNext) {
@@ -125,7 +125,7 @@ Network::terrainSplit(const GeoData * geoData, const GenStraightDef & def) const
if (step.previous.is_valid() && geoData->getSurface(step.current) != geoData->getSurface(step.previous)) {
const auto surfaceEdgePosition = geoData->positionAt(GeoData::PointFace(step.exitPosition, step.current));
out.emplace_back(out.back());
- terrainSplitAt(*out.rbegin(), *++out.rbegin(), surfaceEdgePosition);
+ connectAt(*out.rbegin(), *++out.rbegin(), surfaceEdgePosition);
}
});
return out;
@@ -161,26 +161,32 @@ Network::terrainSplit(const GeoData * geoData, const GenCurveDef & def) const
GenLinksDef out {def};
std::ranges::for_each(++points.begin(), --points.end(), [&out](const auto pos) {
out.emplace_back(out.back());
- terrainSplitAt(*out.rbegin(), *++out.rbegin(), pos);
+ connectAt(*out.rbegin(), *++out.rbegin(), pos);
});
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) {