载入中...
搜索中...
未找到
RoadNetwork.cpp
浏览该文件的文档.
2
6
7#include "common/Diagnostic.h"
8
9#include <algorithm>
10#include <cmath>
11#include <limits>
12#include <string>
13#include <tuple>
14#include <utility>
15
16namespace eve::procgen::road {
17namespace {
18bool laneOrderLess(const RoadLaneConnection& a, const RoadLaneConnection& b) noexcept {
19 return std::tie(a.inEdge, a.inDirection, a.inLane, a.outEdge, a.outDirection, a.outLane) <
20 std::tie(b.inEdge, b.inDirection, b.inLane, b.outEdge, b.outDirection, b.outLane);
21}
22
23bool finite3(float x, float y, float z) { return std::isfinite(x) && std::isfinite(y) && std::isfinite(z); }
24
25bool validPoint(const RoadControlPoint& point) {
26 return finite3(point.x, point.y, point.z) && std::isfinite(point.widthScale) && point.widthScale >= 0.05f &&
27 point.widthScale <= 16.f && std::isfinite(point.rollDegrees) && std::fabs(point.rollDegrees) <= 360.f &&
28 std::isfinite(point.rollCenterOffset) && point.rollCenterOffset >= -.5f && point.rollCenterOffset <= .5f &&
29 std::isfinite(point.splineStrength) && point.splineStrength >= .01f && point.splineStrength <= 1.f &&
30 point.pathControl <= RoadPathControl::Circular;
31}
32
33Result<void> validateCircularPoints(const std::vector<RoadControlPoint>& points) {
34 if (std::none_of(points.begin(), points.end(),
35 [](const auto& p) { return p.pathControl == RoadPathControl::Circular; }))
36 return Result<void>::success();
38 for (const auto& p : points) {
40 q.x = p.x;
41 q.y = p.y;
42 q.z = p.z;
43 q.spanControl = static_cast<eve::procgen::SplineSpanControl>(p.pathControl);
44 q.circularFromEnd = p.circularFromEnd;
45 auto added = path.addPointResult(q);
46 if (!added.ok()) return added;
47 }
48 auto evaluated = path.evaluateResult(0.f);
49 if (!evaluated.ok()) return Result<void>::failure(evaluated.status());
50 return Result<void>::success();
51}
52
53void anchorPoint(RoadControlPoint& point, float x, float y, float z) {
54 point.x = x;
55 point.y = y;
56 point.z = z;
57}
58
59bool hasUsableGeometry(const std::vector<RoadControlPoint>& points) {
60 constexpr float minimumSegmentLengthSquared = 1e-8f;
61 for (std::size_t i = 1; i < points.size(); ++i) {
62 const float dx = points[i].x - points[i - 1].x;
63 const float dy = points[i].y - points[i - 1].y;
64 const float dz = points[i].z - points[i - 1].z;
65 if (dx * dx + dy * dy + dz * dz > minimumSegmentLengthSquared) return true;
66 }
67 return false;
68}
69
70
71int laneCount(const RoadEdge& edge, RoadLaneDirection direction) {
73}
74
75std::uint32_t laneEntryNode(const RoadEdge& edge, RoadLaneDirection direction) {
77}
78
79std::uint32_t laneExitNode(const RoadEdge& edge, RoadLaneDirection direction) {
81}
82
83bool sameLaneLink(const RoadLaneConnection& a, const RoadLaneConnection& b) {
84 return a.inEdge == b.inEdge && a.inLane == b.inLane && a.outEdge == b.outEdge && a.outLane == b.outLane &&
85 a.inDirection == b.inDirection && a.outDirection == b.outDirection;
86}
87
88
89} // namespace
90
91Result<void> RoadNetwork::validateStyle(const RoadStyle& style) const {
92 auto profile = makeRoadProfile(style, 1, 0);
93 if (!profile.ok()) return Result<void>::failure(profile.status());
94 if (!std::isfinite(style.speedLimitMps) || style.speedLimitMps <= 0.f || style.speedLimitMps > 200.f ||
95 style.trafficPriority < 0 || style.trafficPriority > 255)
97 DiagnosticCode::InvalidArgument, "road traffic settings are outside supported bounds", "style.traffic"));
98 const auto& placement = style.sidePlacement;
100 placement.reference > RoadSideReference::Center || !std::isfinite(placement.lateralOffset) ||
101 std::fabs(placement.lateralOffset) > 10000.f || !std::isfinite(placement.verticalOffset) ||
102 std::fabs(placement.verticalOffset) > 10000.f || !std::isfinite(placement.yawDegrees) ||
103 std::fabs(placement.yawDegrees) > 360.f)
105 DiagnosticCode::InvalidArgument, "rigid facility reference or offsets are outside supported bounds",
106 "style.sidePlacement"));
107 if (style.sideObjectDistribution > RoadSideDistribution::Average || !std::isfinite(style.sideObjectStartOffset) ||
108 style.sideObjectStartOffset < 0.f || !std::isfinite(style.sideObjectEndOffset) ||
109 style.sideObjectEndOffset < 0.f)
111 "road side-object offsets must be finite and non-negative",
112 "style.sideObjects"));
113 return Result<void>::success();
114}
115
116int mapLaneByLateralRank(int inLane, int inLaneCount, int outLaneCount) {
117 if (inLaneCount <= 1) return (outLaneCount - 1) / 2;
118 const float rank = static_cast<float>(inLane) / static_cast<float>(inLaneCount - 1);
119 return static_cast<int>(std::lround(rank * static_cast<float>(outLaneCount - 1)));
120}
121
125
126int RoadNetwork::findNodeIndex(std::uint32_t id) const {
127 const auto it = nodeIndex_.find(id);
128 return it == nodeIndex_.end() ? -1 : it->second;
129}
130
131int RoadNetwork::findEdgeIndex(std::uint32_t id) const {
132 const auto it = edgeIndex_.find(id);
133 return it == edgeIndex_.end() ? -1 : it->second;
134}
135
136Result<std::uint32_t> RoadNetwork::addNode(float x, float y, float z, float junctionRadius) {
137 if (!finite3(x, y, z) || !std::isfinite(junctionRadius) || junctionRadius <= 0.f)
139 DiagnosticCode::InvalidArgument, "node requires finite position and positive junctionRadius", "node"));
140 const std::uint32_t id = nextNodeId_++;
141 nodeIndex_[id] = static_cast<int>(nodes_.size());
142 nodes_.push_back(RoadNode{id, x, y, z, junctionRadius});
143 ++revision_;
145}
146
148 if (node.id == 0 || node.id == std::numeric_limits<std::uint32_t>::max() || findNodeIndex(node.id) >= 0)
150 Diagnostic::error(DiagnosticCode::AlreadyExists, "node id must be non-zero and unused", "node.id"));
151 if (!finite3(node.x, node.y, node.z) || !std::isfinite(node.junctionRadius) || node.junctionRadius <= 0.f)
153 DiagnosticCode::InvalidArgument, "node requires finite position and positive junctionRadius", "node"));
154 if (!validJunctionControl(node.junctionControl))
156 "node junction control is outside supported bounds",
157 "node.junctionControl"));
158 auto asset = detail::validateConnectionAsset(node.connection);
159 if (!asset.ok()) return asset;
160 const auto position = std::lower_bound(nodes_.begin(), nodes_.end(), node.id,
161 [](const RoadNode& item, std::uint32_t id) { return item.id < id; });
162 const auto inserted = static_cast<std::size_t>(position - nodes_.begin());
163 nodes_.insert(position, node);
164 for (std::size_t i = inserted; i < nodes_.size(); ++i) nodeIndex_[nodes_[i].id] = static_cast<int>(i);
165 nextNodeId_ = std::max(nextNodeId_, node.id + 1);
166 ++revision_;
167 return Result<void>::success();
168}
169
171 std::vector<RoadControlPoint> controlPoints, int lanesForward,
172 int lanesBackward, RoadStyle style) {
173 if (findNodeIndex(from) < 0 || findNodeIndex(to) < 0)
175 Diagnostic::error(DiagnosticCode::NotFound, "edge endpoints must reference live nodes", "edge"));
176 if (!nodes_[static_cast<std::size_t>(findNodeIndex(from))].connection.ports.empty() ||
177 !nodes_[static_cast<std::size_t>(findNodeIndex(to))].connection.ports.empty())
180 "clear a custom connection before adding a new incident edge", "edge"));
181 if (from == to)
183 Diagnostic::error(DiagnosticCode::PreconditionViolation, "edge endpoints must be distinct", "edge"));
184 if (controlPoints.size() < 2)
186 Diagnostic::error(DiagnosticCode::InvalidArgument, "edge needs at least two control points", "edge"));
187 for (const auto& p : controlPoints) {
188 if (!validPoint(p))
190 DiagnosticCode::InvalidArgument, "control point positions and profiles must be valid", "edge"));
191 }
192 auto styleOk = validateStyle(style);
193 if (!styleOk.ok()) return Result<std::uint32_t>::failure(styleOk.status());
194 auto profile = makeRoadProfile(style, lanesForward, lanesBackward);
195 if (!profile.ok()) return Result<std::uint32_t>::failure(profile.status());
196
197 // A node is the authoritative connection position. Canonicalizing the two
198 // endpoint samples prevents authored handles from leaving invisible gaps or
199 // sending turn curves toward a stale position.
200 const auto& fromNode = nodes_[static_cast<std::size_t>(findNodeIndex(from))];
201 const auto& toNode = nodes_[static_cast<std::size_t>(findNodeIndex(to))];
202 anchorPoint(controlPoints.front(), fromNode.x, fromNode.y, fromNode.z);
203 anchorPoint(controlPoints.back(), toNode.x, toNode.y, toNode.z);
204 auto circular = validateCircularPoints(controlPoints);
205 if (!circular.ok()) return Result<std::uint32_t>::failure(circular.status());
206 if (!hasUsableGeometry(controlPoints))
208 DiagnosticCode::PreconditionViolation, "edge centerline must contain a non-degenerate segment", "edge"));
209
210 const std::uint32_t id = nextEdgeId_++;
211 edgeIndex_[id] = static_cast<int>(edges_.size());
213 edge.id = id;
214 edge.from = from;
215 edge.to = to;
216 edge.controlPoints = std::move(controlPoints);
217 edge.lanesForward = lanesForward;
218 edge.lanesBackward = lanesBackward;
219 edge.style = std::move(style);
220 edges_.push_back(std::move(edge));
221 ++revision_;
223}
224
226 if (edge.id == 0 || edge.id == std::numeric_limits<std::uint32_t>::max() || findEdgeIndex(edge.id) >= 0)
228 Diagnostic::error(DiagnosticCode::AlreadyExists, "edge id must be non-zero and unused", "edge.id"));
229 if (findNodeIndex(edge.from) < 0 || findNodeIndex(edge.to) < 0)
231 Diagnostic::error(DiagnosticCode::NotFound, "edge endpoints must reference live nodes", "edge"));
232 if (edge.from == edge.to)
234 Diagnostic::error(DiagnosticCode::PreconditionViolation, "edge endpoints must be distinct", "edge"));
235 if (edge.controlPoints.size() < 2)
237 Diagnostic::error(DiagnosticCode::InvalidArgument, "edge needs at least two control points", "edge"));
238 for (const auto& point : edge.controlPoints) {
239 if (!validPoint(point))
241 DiagnosticCode::InvalidArgument, "control point positions and profiles must be valid", "edge"));
242 }
243 auto styleOk = validateStyle(edge.style);
244 if (!styleOk.ok()) return styleOk;
245 auto profile = makeRoadProfile(edge.style, edge.lanesForward, edge.lanesBackward);
246 if (!profile.ok()) return Result<void>::failure(profile.status());
247 const auto& from = nodes_[static_cast<std::size_t>(findNodeIndex(edge.from))];
248 const auto& to = nodes_[static_cast<std::size_t>(findNodeIndex(edge.to))];
249 anchorPoint(edge.controlPoints.front(), from.x, from.y, from.z);
250 anchorPoint(edge.controlPoints.back(), to.x, to.y, to.z);
251 auto circular = validateCircularPoints(edge.controlPoints);
252 if (!circular.ok()) return circular;
253 if (!hasUsableGeometry(edge.controlPoints))
255 DiagnosticCode::PreconditionViolation, "edge centerline must contain a non-degenerate segment", "edge"));
256 nextEdgeId_ = std::max(nextEdgeId_, edge.id + 1);
257 const auto position = std::lower_bound(edges_.begin(), edges_.end(), edge.id,
258 [](const RoadEdge& item, std::uint32_t id) { return item.id < id; });
259 const auto inserted = static_cast<std::size_t>(position - edges_.begin());
260 edges_.insert(position, std::move(edge));
261 for (std::size_t i = inserted; i < edges_.size(); ++i) edgeIndex_[edges_[i].id] = static_cast<int>(i);
262 ++revision_;
263 return Result<void>::success();
264}
265
266Result<void> RoadNetwork::validateLaneConnection(const RoadLaneConnection& link) const {
267 const int inIdx = findEdgeIndex(link.inEdge);
268 const int outIdx = findEdgeIndex(link.outEdge);
269 if (inIdx < 0 || outIdx < 0)
271 Diagnostic::error(DiagnosticCode::NotFound, "lane link references missing edges", "laneLink"));
272 const auto& inEdge = edges_[static_cast<std::size_t>(inIdx)];
273 const auto& outEdge = edges_[static_cast<std::size_t>(outIdx)];
274 const auto sharedNode = laneEntryNode(inEdge, link.inDirection);
275 if (sharedNode != laneExitNode(outEdge, link.outDirection))
277 "lane link directions must meet at the same node", "laneLink"));
278 if (link.inEdge == link.outEdge)
280 "lane link cannot make an immediate U-turn on one edge",
281 "laneLink"));
282 if (link.inLane < 0 || link.inLane >= laneCount(inEdge, link.inDirection))
284 Diagnostic::error(DiagnosticCode::InvalidArgument, "inLane out of range", "laneLink"));
285 if (link.outLane < 0 || link.outLane >= laneCount(outEdge, link.outDirection))
287 Diagnostic::error(DiagnosticCode::InvalidArgument, "outLane out of range", "laneLink"));
288 return Result<void>::success();
289}
290
292 auto valid = validateLaneConnection(link);
293 if (!valid.ok()) return valid;
294 if (std::any_of(laneLinks_.begin(), laneLinks_.end(),
295 [&](const auto& existing) { return sameLaneLink(existing, link); }))
297 Diagnostic::error(DiagnosticCode::AlreadyExists, "lane link already exists", "laneLink"));
298 if (std::any_of(blockedLaneLinks_.begin(), blockedLaneLinks_.end(),
299 [&](const auto& blocked) { return sameLaneLink(blocked, link); }))
301 Diagnostic::error(DiagnosticCode::PreconditionViolation, "lane link is persistently blocked", "laneLink"));
302 laneLinks_.insert(std::lower_bound(laneLinks_.begin(), laneLinks_.end(), link, laneOrderLess), link);
303 ++revision_;
304 return Result<void>::success();
305}
306
308 auto valid = validateLaneConnection(link);
309 if (!valid.ok()) return Result<bool>::failure(valid.status());
310 if (std::any_of(blockedLaneLinks_.begin(), blockedLaneLinks_.end(),
311 [&](const auto& blocked) { return sameLaneLink(blocked, link); }))
313 Diagnostic::error(DiagnosticCode::AlreadyExists, "lane link is already blocked", "laneLink"));
314 auto candidate = *this;
315 const auto active = std::find_if(candidate.laneLinks_.begin(), candidate.laneLinks_.end(),
316 [&](const auto& current) { return sameLaneLink(current, link); });
317 const bool removed = active != candidate.laneLinks_.end();
318 if (removed) candidate.laneLinks_.erase(active);
319 candidate.blockedLaneLinks_.insert(
320 std::lower_bound(candidate.blockedLaneLinks_.begin(), candidate.blockedLaneLinks_.end(), link, laneOrderLess),
321 link);
322 auto checked = candidate.validate();
323 if (!checked.ok()) return Result<bool>::failure(checked.status());
324 candidate.revision_ = revision_ + 1;
325 *this = std::move(candidate);
327}
328
330 const auto found = std::find_if(blockedLaneLinks_.begin(), blockedLaneLinks_.end(),
331 [&](const auto& blocked) { return sameLaneLink(blocked, link); });
332 if (found == blockedLaneLinks_.end())
334 Diagnostic::error(DiagnosticCode::NotFound, "lane link block does not exist", "laneLink"));
335 blockedLaneLinks_.erase(found);
336 ++revision_;
337 return Result<void>::success();
338}
339
341 const auto found = std::find_if(laneLinks_.begin(), laneLinks_.end(),
342 [&](const RoadLaneConnection& candidate) { return sameLaneLink(candidate, link); });
343 if (found == laneLinks_.end())
345 Diagnostic::error(DiagnosticCode::NotFound, "lane link does not exist", "laneLink"));
346 laneLinks_.erase(found);
347 ++revision_;
348 return Result<void>::success();
349}
350
352 if (findNodeIndex(nodeId) < 0)
353 return Result<int>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown node", "nodeId"));
354 auto candidate = *this;
355 int added = 0;
357 for (const auto& inEdge : candidate.edges_) {
358 for (const auto inDirection : directions) {
359 const int inLanes = laneCount(inEdge, inDirection);
360 if (inLanes == 0 || laneEntryNode(inEdge, inDirection) != nodeId) continue;
361 for (const auto& outEdge : candidate.edges_) {
362 if (outEdge.id == inEdge.id) continue;
363 for (const auto outDirection : directions) {
364 const int outLanes = laneCount(outEdge, outDirection);
365 if (outLanes == 0 || laneExitNode(outEdge, outDirection) != nodeId) continue;
366 for (int il = 0; il < inLanes; ++il) {
367 // Preserve normalized lateral rank when lane counts change. This
368 // distributes merges/expansions across the full destination width
369 // instead of collapsing every overflow lane onto one side.
370 const int ol = mapLaneByLateralRank(il, inLanes, outLanes);
371 RoadLaneConnection link{inEdge.id, il, outEdge.id, ol, inDirection, outDirection};
372 const bool blocked = std::any_of(candidate.blockedLaneLinks_.begin(),
373 candidate.blockedLaneLinks_.end(),
374 [&](const auto& current) {
375 return sameLaneLink(current, link);
376 });
377 if (blocked) continue;
378 // Any authored link for the same incoming lane and outgoing
379 // physical route is an override, even when it selects another
380 // destination lane. Do not re-add an automatic parallel turn.
381 const bool overridden =
382 std::any_of(candidate.laneLinks_.begin(), candidate.laneLinks_.end(), [&](const auto& current) {
383 return current.inEdge == link.inEdge && current.inLane == link.inLane &&
384 current.outEdge == link.outEdge && current.inDirection == link.inDirection &&
385 current.outDirection == link.outDirection;
386 });
387 if (overridden) continue;
388 auto r = candidate.addLaneLink(link);
389 if (!r.ok()) return Result<int>::failure(r.status());
390 ++added;
391 }
392 }
393 }
394 }
395 }
396 if (added == 0) return Result<int>::success(0);
397 auto valid = candidate.validate();
398 if (!valid.ok()) return Result<int>::failure(valid.status());
399 candidate.revision_ = revision_ + 1;
400 *this = std::move(candidate);
401 return Result<int>::success(added);
402}
403
405 for (const auto& node : nodes_) {
406 if (!finite3(node.x, node.y, node.z) || !std::isfinite(node.junctionRadius) || node.junctionRadius <= 0.f ||
407 !validJunctionControl(node.junctionControl))
409 "network contains an invalid junction node", "node"));
410 }
411 for (const auto& node : nodes_) {
412 auto connection = detail::validateConnectionSeams(*this, node);
413 if (!connection.ok()) return connection;
414 auto routes = detail::validateFacilityRoutes(*this, node);
415 if (!routes.ok()) return routes;
416 }
417 for (const auto& edge : edges_) {
418 for (const auto& point : edge.controlPoints) {
419 if (!validPoint(point))
421 "edge contains invalid control-point profiles", "edge"));
422 }
423 auto circular = validateCircularPoints(edge.controlPoints);
424 if (!circular.ok()) return circular;
425 auto styleOk = validateStyle(edge.style);
426 if (!styleOk.ok()) return styleOk;
427 auto profile = makeRoadProfile(edge.style, edge.lanesForward, edge.lanesBackward);
428 if (!profile.ok()) return Result<void>::failure(profile.status());
429 if (findNodeIndex(edge.from) < 0 || findNodeIndex(edge.to) < 0)
431 Diagnostic::error(DiagnosticCode::InvariantViolation, "edge references a missing node", "edge"));
432 if (edge.from == edge.to)
434 Diagnostic::error(DiagnosticCode::InvariantViolation, "edge forms a self-loop", "edge"));
435 if (edge.controlPoints.size() < 2)
437 Diagnostic::error(DiagnosticCode::InvariantViolation, "edge has fewer than two samples", "edge"));
438 if (!hasUsableGeometry(edge.controlPoints))
440 DiagnosticCode::InvariantViolation, "edge centerline has no usable segment", "edge"));
441 const auto& a = nodes_[static_cast<std::size_t>(findNodeIndex(edge.from))];
442 const auto& b = nodes_[static_cast<std::size_t>(findNodeIndex(edge.to))];
443 const auto& p0 = edge.controlPoints.front();
444 const auto& p1 = edge.controlPoints.back();
445 if (p0.x != a.x || p0.y != a.y || p0.z != a.z || p1.x != b.x || p1.y != b.y || p1.z != b.z)
447 "edge samples are not anchored to endpoint nodes", "edge"));
448 }
449 for (std::size_t i = 0; i < laneLinks_.size(); ++i) {
450 const auto& link = laneLinks_[i];
451 const int inIdx = findEdgeIndex(link.inEdge);
452 const int outIdx = findEdgeIndex(link.outEdge);
453 if (inIdx < 0 || outIdx < 0)
455 "lane link references a missing edge", "laneLink"));
456 const auto& inEdge = edges_[static_cast<std::size_t>(inIdx)];
457 const auto& outEdge = edges_[static_cast<std::size_t>(outIdx)];
458 if (laneEntryNode(inEdge, link.inDirection) != laneExitNode(outEdge, link.outDirection) || link.inLane < 0 ||
459 link.inLane >= laneCount(inEdge, link.inDirection) || link.outLane < 0 ||
460 link.outLane >= laneCount(outEdge, link.outDirection))
462 "lane link violates endpoint or lane bounds", "laneLink"));
463 for (std::size_t j = i + 1; j < laneLinks_.size(); ++j) {
464 if (sameLaneLink(link, laneLinks_[j]))
466 "network contains a duplicate lane link", "laneLink"));
467 }
468 }
469 return Result<void>::success();
470}
471
473 const int idx = findEdgeIndex(edgeId);
474 if (idx < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "edgeId"));
475 auto styleOk = validateStyle(style);
476 if (!styleOk.ok()) return styleOk;
477 auto profile = makeRoadProfile(style, edges_[static_cast<std::size_t>(idx)].lanesForward,
478 edges_[static_cast<std::size_t>(idx)].lanesBackward);
479 if (!profile.ok()) return Result<void>::failure(profile.status());
480 const auto& original = edges_[static_cast<std::size_t>(idx)];
481 if (!nodes_[static_cast<std::size_t>(findNodeIndex(original.from))].connection.ports.empty() ||
482 !nodes_[static_cast<std::size_t>(findNodeIndex(original.to))].connection.ports.empty() ||
483 !nodes_[static_cast<std::size_t>(findNodeIndex(original.from))].connection.facilityRoutes.empty() ||
484 !nodes_[static_cast<std::size_t>(findNodeIndex(original.to))].connection.facilityRoutes.empty()) {
485 auto candidate = *this;
486 candidate.edges_[static_cast<std::size_t>(idx)].style = std::move(style);
487 auto valid = candidate.validate();
488 if (!valid.ok()) return valid;
489 candidate.revision_ = revision_ + 1;
490 *this = std::move(candidate);
491 return Result<void>::success();
492 }
493 edges_[static_cast<std::size_t>(idx)].style = std::move(style);
494 ++revision_;
495 return Result<void>::success();
496}
497
498Result<void> RoadNetwork::setNodePosition(std::uint32_t nodeId, float x, float y, float z) {
499 const int index = findNodeIndex(nodeId);
500 if (index < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown node", "nodeId"));
501 if (!finite3(x, y, z))
503 Diagnostic::error(DiagnosticCode::InvalidArgument, "node position must be finite", "position"));
504
505 const auto& node = nodes_[static_cast<std::size_t>(index)];
506 if (node.x == x && node.y == y && node.z == z) return Result<void>::success();
507 auto candidate = *this;
508 auto& candidateNode = candidate.nodes_[static_cast<std::size_t>(index)];
509 candidateNode.x = x;
510 candidateNode.y = y;
511 candidateNode.z = z;
512 for (auto& edge : candidate.edges_) {
513 if (edge.from == nodeId) anchorPoint(edge.controlPoints.front(), x, y, z);
514 if (edge.to == nodeId) anchorPoint(edge.controlPoints.back(), x, y, z);
515 }
516 for (std::size_t i = 0; i < blockedLaneLinks_.size(); ++i) {
517 const auto& blocked = blockedLaneLinks_[i];
518 auto valid = validateLaneConnection(blocked);
519 if (!valid.ok())
521 DiagnosticCode::InvariantViolation, "blocked lane link violates topology", "blockedLaneLink"));
522 if (std::any_of(laneLinks_.begin(), laneLinks_.end(),
523 [&](const auto& active) { return sameLaneLink(active, blocked); }))
525 DiagnosticCode::InvariantViolation, "lane link is both active and blocked", "blockedLaneLink"));
526 for (std::size_t j = i + 1; j < blockedLaneLinks_.size(); ++j) {
527 if (sameLaneLink(blocked, blockedLaneLinks_[j]))
529 DiagnosticCode::InvariantViolation, "network contains a duplicate lane-link block",
530 "blockedLaneLink"));
531 }
532 }
533 auto valid = candidate.validate();
534 if (!valid.ok()) return valid;
535 candidate.revision_ = revision_ + 1;
536 *this = std::move(candidate);
537 return Result<void>::success();
538}
539
540Result<void> RoadNetwork::setNodeJunctionRadius(std::uint32_t nodeId, float junctionRadius) {
541 const int index = findNodeIndex(nodeId);
542 if (index < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown node", "nodeId"));
543 if (!std::isfinite(junctionRadius) || junctionRadius <= 0.f)
545 DiagnosticCode::InvalidArgument, "junction radius must be finite and positive", "junctionRadius"));
546 auto& node = nodes_[static_cast<std::size_t>(index)];
547 if (node.junctionRadius == junctionRadius) return Result<void>::success();
548 node.junctionRadius = junctionRadius;
549 ++revision_;
550 return Result<void>::success();
551}
552
554 const int index = findNodeIndex(nodeId);
555 if (index < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown node", "nodeId"));
556 if (!validJunctionControl(control))
558 DiagnosticCode::InvalidArgument, "junction control is outside supported bounds", "junctionControl"));
559 auto& node = nodes_[static_cast<std::size_t>(index)];
560 if (node.junctionControl == control) return Result<void>::success();
561 node.junctionControl = control;
562 ++revision_;
563 return Result<void>::success();
564}
565
566Result<int> RoadNetwork::mergeNodes(std::uint32_t keepNodeId, std::uint32_t removeNodeId, float maxDistance) {
567 if (keepNodeId == removeNodeId)
569 Diagnostic::error(DiagnosticCode::InvalidArgument, "merge nodes must be distinct", "removeNodeId"));
570 const int keepIndex = findNodeIndex(keepNodeId), removeIndex = findNodeIndex(removeNodeId);
571 if (keepIndex < 0 || removeIndex < 0)
573 Diagnostic::error(DiagnosticCode::NotFound, "merge references an unknown node", "nodeId"));
574 if (!std::isfinite(maxDistance) || maxDistance < 0.f)
576 Diagnostic::error(DiagnosticCode::InvalidArgument, "merge distance must be finite and non-negative",
577 "maxDistance"));
578 const auto& keep = nodes_[static_cast<std::size_t>(keepIndex)];
579 const auto& removed = nodes_[static_cast<std::size_t>(removeIndex)];
580 const float dx = keep.x - removed.x, dy = keep.y - removed.y, dz = keep.z - removed.z;
581 if (dx * dx + dy * dy + dz * dz > maxDistance * maxDistance)
583 DiagnosticCode::PreconditionViolation, "nodes are outside the merge distance", "maxDistance"));
584 if (std::any_of(edges_.begin(), edges_.end(), [&](const auto& edge) {
585 return (edge.from == keepNodeId && edge.to == removeNodeId) ||
586 (edge.from == removeNodeId && edge.to == keepNodeId);
587 }))
589 "merging nodes would create a self-loop edge", "removeNodeId"));
590
591 if (!nodes_[static_cast<std::size_t>(keepIndex)].connection.ports.empty() ||
592 !nodes_[static_cast<std::size_t>(removeIndex)].connection.ports.empty() ||
593 !nodes_[static_cast<std::size_t>(keepIndex)].connection.facilityRoutes.empty() ||
594 !nodes_[static_cast<std::size_t>(removeIndex)].connection.facilityRoutes.empty())
596 "clear custom connection assets before merging their nodes",
597 "nodeId"));
598 auto candidate = *this;
599 int rewired = 0;
600 for (auto& edge : candidate.edges_) {
601 if (edge.from == removeNodeId) {
602 edge.from = keepNodeId;
603 anchorPoint(edge.controlPoints.front(), keep.x, keep.y, keep.z);
604 ++rewired;
605 }
606 if (edge.to == removeNodeId) {
607 edge.to = keepNodeId;
608 anchorPoint(edge.controlPoints.back(), keep.x, keep.y, keep.z);
609 ++rewired;
610 }
611 }
612 candidate.nodes_.erase(candidate.nodes_.begin() + removeIndex);
613 candidate.nodeIndex_.clear();
614 for (std::size_t i = 0; i < candidate.nodes_.size(); ++i)
615 candidate.nodeIndex_[candidate.nodes_[i].id] = static_cast<int>(i);
616 auto valid = candidate.validate();
617 if (!valid.ok()) return Result<int>::failure(valid.status());
618 candidate.revision_ = revision_ + 1;
619 *this = std::move(candidate);
620 return Result<int>::success(rewired);
621}
622
623Result<void> RoadNetwork::setEdgeControlPoints(std::uint32_t edgeId, std::vector<RoadControlPoint> controlPoints) {
624 const int index = findEdgeIndex(edgeId);
625 if (index < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "edgeId"));
626 if (controlPoints.size() < 2)
628 Diagnostic::error(DiagnosticCode::InvalidArgument, "edge needs at least two control points", "points"));
629 for (const auto& point : controlPoints) {
630 if (!validPoint(point))
632 DiagnosticCode::InvalidArgument, "control point positions and profiles must be valid", "points"));
633 }
634
635 auto& edge = edges_[static_cast<std::size_t>(index)];
636 const auto& from = nodes_[static_cast<std::size_t>(findNodeIndex(edge.from))];
637 const auto& to = nodes_[static_cast<std::size_t>(findNodeIndex(edge.to))];
638 anchorPoint(controlPoints.front(), from.x, from.y, from.z);
639 anchorPoint(controlPoints.back(), to.x, to.y, to.z);
640 auto circular = validateCircularPoints(controlPoints);
641 if (!circular.ok()) return circular;
642 if (!hasUsableGeometry(controlPoints))
644 DiagnosticCode::PreconditionViolation, "edge centerline must contain a non-degenerate segment", "points"));
645 if (!from.connection.ports.empty() || !to.connection.ports.empty()) {
646 auto candidate = *this;
647 candidate.edges_[static_cast<std::size_t>(index)].controlPoints = std::move(controlPoints);
648 auto valid = candidate.validate();
649 if (!valid.ok()) return valid;
650 candidate.revision_ = revision_ + 1;
651 *this = std::move(candidate);
652 return Result<void>::success();
653 }
654 edge.controlPoints = std::move(controlPoints);
655 ++revision_;
656 return Result<void>::success();
657}
658
659Result<int> RoadNetwork::setEdgeLaneCounts(std::uint32_t edgeId, int lanesForward, int lanesBackward) {
660 const int idx = findEdgeIndex(edgeId);
661 if (idx < 0) return Result<int>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "edgeId"));
662 auto profile = makeRoadProfile(edges_[static_cast<std::size_t>(idx)].style, lanesForward, lanesBackward);
663 if (!profile.ok()) return Result<int>::failure(profile.status());
664
665 auto candidate = *this;
666 auto& edge = candidate.edges_[static_cast<std::size_t>(idx)];
667 edge.lanesForward = lanesForward;
668 edge.lanesBackward = lanesBackward;
669 const auto invalid = [&](const RoadLaneConnection& link) {
670 if (link.inEdge == edgeId && link.inLane >= laneCount(edge, link.inDirection)) return true;
671 return link.outEdge == edgeId && link.outLane >= laneCount(edge, link.outDirection);
672 };
673 const auto before = candidate.laneLinks_.size();
674 candidate.laneLinks_.erase(std::remove_if(candidate.laneLinks_.begin(), candidate.laneLinks_.end(), invalid),
675 candidate.laneLinks_.end());
676 candidate.blockedLaneLinks_.erase(
677 std::remove_if(candidate.blockedLaneLinks_.begin(), candidate.blockedLaneLinks_.end(), invalid),
678 candidate.blockedLaneLinks_.end());
679 auto valid = candidate.validate();
680 if (!valid.ok()) return Result<int>::failure(valid.status());
681 candidate.revision_ = revision_ + 1;
682 const int removed = static_cast<int>(before - candidate.laneLinks_.size());
683 *this = std::move(candidate);
685}
686
688 const int index = findEdgeIndex(edgeId);
689 if (index < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "edgeId"));
690 auto candidate = *this;
691 auto& edge = candidate.edges_[static_cast<std::size_t>(index)];
692 std::swap(edge.from, edge.to);
693 std::reverse(edge.controlPoints.begin(), edge.controlPoints.end());
694 // Strength belongs to outgoing spans, not the geometric marker after reversal.
695 const float terminalStrength = edge.controlPoints.front().splineStrength;
696 const auto terminalControl = edge.controlPoints.front().pathControl;
697 const bool terminalStart = edge.controlPoints.front().alignStraightStart,
698 terminalEnd = edge.controlPoints.front().alignStraightEnd;
699 const bool terminalCircle = edge.controlPoints.front().circularFromEnd;
700 for (std::size_t i = 0; i + 1 < edge.controlPoints.size(); ++i) {
701 edge.controlPoints[i].splineStrength = edge.controlPoints[i + 1].splineStrength;
702 edge.controlPoints[i].pathControl = edge.controlPoints[i + 1].pathControl;
703 edge.controlPoints[i].circularFromEnd = edge.controlPoints[i].pathControl == RoadPathControl::Circular
704 ? !edge.controlPoints[i + 1].circularFromEnd
705 : edge.controlPoints[i + 1].circularFromEnd;
706 edge.controlPoints[i].alignStraightStart = edge.controlPoints[i + 1].alignStraightEnd;
707 edge.controlPoints[i].alignStraightEnd = edge.controlPoints[i + 1].alignStraightStart;
708 }
709 edge.controlPoints.back().splineStrength = terminalStrength;
710 edge.controlPoints.back().pathControl = terminalControl;
711 edge.controlPoints.back().circularFromEnd =
712 terminalControl == RoadPathControl::Circular ? !terminalCircle : terminalCircle;
713 edge.controlPoints.back().alignStraightStart = terminalEnd;
714 edge.controlPoints.back().alignStraightEnd = terminalStart;
715 for (auto& point : edge.controlPoints) {
716 if (point.rollDegrees != 0.f) point.rollDegrees = -point.rollDegrees;
717 if (point.rollCenterOffset != 0.f) point.rollCenterOffset = -point.rollCenterOffset;
718 }
720 std::swap(edge.lanesForward, edge.lanesBackward);
721 std::swap(edge.style.sideObjectStartOffset, edge.style.sideObjectEndOffset);
722 std::swap(edge.style.sideObjectsLeft, edge.style.sideObjectsRight);
723 const auto flip = [](RoadLaneDirection direction) {
725 };
726 for (auto& link : candidate.laneLinks_) {
727 if (link.inEdge == edgeId) link.inDirection = flip(link.inDirection);
728 if (link.outEdge == edgeId) link.outDirection = flip(link.outDirection);
729 }
730 for (auto& link : candidate.blockedLaneLinks_) {
731 if (link.inEdge == edgeId) link.inDirection = flip(link.inDirection);
732 if (link.outEdge == edgeId) link.outDirection = flip(link.outDirection);
733 }
734 candidate.normalizeLaneLinkOrder();
735 auto valid = candidate.validate();
736 if (!valid.ok()) return valid;
737 candidate.revision_ = revision_ + 1;
738 *this = std::move(candidate);
739 return Result<void>::success();
740}
741void RoadNetwork::normalizeLaneLinkOrder() {
742 std::sort(laneLinks_.begin(), laneLinks_.end(), laneOrderLess);
743 std::sort(blockedLaneLinks_.begin(), blockedLaneLinks_.end(), laneOrderLess);
744}
745
746Result<int> RoadNetwork::reconnectEdgeEndpoint(std::uint32_t edgeId, bool fromEndpoint, std::uint32_t nodeId) {
747 const int edgeIndex = findEdgeIndex(edgeId);
748 const int nodeIndex = findNodeIndex(nodeId);
749 if (edgeIndex < 0)
750 return Result<int>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "edgeId"));
751 if (nodeIndex < 0)
752 return Result<int>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown node", "nodeId"));
753 const auto& current = edges_[static_cast<std::size_t>(edgeIndex)];
754 const std::uint32_t oldNodeId = fromEndpoint ? current.from : current.to;
755 if (oldNodeId == nodeId) return Result<int>::success(0);
756 if ((fromEndpoint ? current.to : current.from) == nodeId)
758 DiagnosticCode::PreconditionViolation, "edge endpoint reconnect would create a self-loop", "nodeId"));
759
760 auto candidate = *this;
761 auto& edge = candidate.edges_[static_cast<std::size_t>(edgeIndex)];
762 const auto& node = candidate.nodes_[static_cast<std::size_t>(nodeIndex)];
763 if (fromEndpoint) {
764 edge.from = nodeId;
765 anchorPoint(edge.controlPoints.front(), node.x, node.y, node.z);
766 } else {
767 edge.to = nodeId;
768 anchorPoint(edge.controlPoints.back(), node.x, node.y, node.z);
769 }
770 const auto stale = [&](const RoadLaneConnection& link) {
771 if (link.inEdge != edgeId && link.outEdge != edgeId) return false;
772 return !candidate.validateLaneConnection(link).ok();
773 };
774 const auto activeBefore = candidate.laneLinks_.size();
775 const auto blockedBefore = candidate.blockedLaneLinks_.size();
776 candidate.laneLinks_.erase(std::remove_if(candidate.laneLinks_.begin(), candidate.laneLinks_.end(), stale),
777 candidate.laneLinks_.end());
778 candidate.blockedLaneLinks_.erase(
779 std::remove_if(candidate.blockedLaneLinks_.begin(), candidate.blockedLaneLinks_.end(), stale),
780 candidate.blockedLaneLinks_.end());
781 auto valid = candidate.validate();
782 if (!valid.ok()) return Result<int>::failure(valid.status());
783 candidate.revision_ = revision_ + 1;
784 const int removed = static_cast<int>((activeBefore - candidate.laneLinks_.size()) +
785 (blockedBefore - candidate.blockedLaneLinks_.size()));
786 *this = std::move(candidate);
788}
789
790Result<std::uint32_t> RoadNetwork::detachEdgeEndpoint(std::uint32_t edgeId, bool fromEndpoint) {
791 return detachEdgeEndpoint(edgeId, fromEndpoint, 0);
792}
793
794Result<std::uint32_t> RoadNetwork::detachEdgeEndpoint(std::uint32_t edgeId, bool fromEndpoint,
795 std::uint32_t nodeId) {
796 const int edgeIndex = findEdgeIndex(edgeId);
797 if (edgeIndex < 0)
799 Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "edgeId"));
800 const auto& edge = edges_[static_cast<std::size_t>(edgeIndex)];
801 const std::uint32_t oldNodeId = fromEndpoint ? edge.from : edge.to;
802 const auto incidentCount = std::count_if(edges_.begin(), edges_.end(), [&](const RoadEdge& candidate) {
803 return candidate.from == oldNodeId || candidate.to == oldNodeId;
804 });
805 if (incidentCount < 2)
808 "edge endpoint must share a junction with another edge before detaching", "edgeId"));
809 const int oldNodeIndex = findNodeIndex(oldNodeId);
810 if (oldNodeIndex < 0)
812 Diagnostic::error(DiagnosticCode::InvariantViolation, "edge endpoint node is missing", "edgeId"));
813 const auto oldNode = nodes_[static_cast<std::size_t>(oldNodeIndex)];
814
815 auto candidate = *this;
816 std::uint32_t createdNodeId = nodeId;
817 if (createdNodeId == 0) {
818 auto created = candidate.addNode(oldNode.x, oldNode.y, oldNode.z, oldNode.junctionRadius);
819 if (!created.ok()) return Result<std::uint32_t>::failure(created.status());
820 createdNodeId = created.value();
821 } else {
822 auto restored = candidate.restoreNode(
823 {createdNodeId, oldNode.x, oldNode.y, oldNode.z, oldNode.junctionRadius});
824 if (!restored.ok()) return Result<std::uint32_t>::failure(restored.status());
825 }
826 auto reconnected = candidate.reconnectEdgeEndpoint(edgeId, fromEndpoint, createdNodeId);
827 if (!reconnected.ok()) return Result<std::uint32_t>::failure(reconnected.status());
828 candidate.revision_ = revision_ + 1;
829 const auto result = createdNodeId;
830 *this = std::move(candidate);
832}
833
835 for (const auto& node : nodes_)
836 for (const auto& route : node.connection.facilityRoutes)
837 if (route.firstEdge == edgeId || route.secondEdge == edgeId)
839 "clear facility routes before removing a bound edge",
840 "edgeId"));
841 for (const auto& node : nodes_)
842 for (const auto& port : node.connection.ports)
843 if (port.edgeId == edgeId)
846 "clear the custom connection before destroying its bound edge", "edgeId"));
847 const int index = findEdgeIndex(edgeId);
848 if (index < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "edgeId"));
849 laneLinks_.erase(
850 std::remove_if(laneLinks_.begin(), laneLinks_.end(),
851 [edgeId](const auto& link) { return link.inEdge == edgeId || link.outEdge == edgeId; }),
852 laneLinks_.end());
853 blockedLaneLinks_.erase(
854 std::remove_if(blockedLaneLinks_.begin(), blockedLaneLinks_.end(),
855 [edgeId](const auto& link) { return link.inEdge == edgeId || link.outEdge == edgeId; }),
856 blockedLaneLinks_.end());
857 edges_.erase(edges_.begin() + index);
858 edgeIndex_.clear();
859 for (std::size_t i = 0; i < edges_.size(); ++i) edgeIndex_[edges_[i].id] = static_cast<int>(i);
860 ++revision_;
861 return Result<void>::success();
862}
863
865 const int index = findNodeIndex(nodeId);
866 if (index < 0) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown node", "nodeId"));
867 if (std::any_of(edges_.begin(), edges_.end(),
868 [nodeId](const auto& edge) { return edge.from == nodeId || edge.to == nodeId; }))
870 Diagnostic::error(DiagnosticCode::PreconditionViolation, "node must be isolated before removal", "nodeId"));
871 nodes_.erase(nodes_.begin() + index);
872 nodeIndex_.clear();
873 for (std::size_t i = 0; i < nodes_.size(); ++i) nodeIndex_[nodes_[i].id] = static_cast<int>(i);
874 ++revision_;
875 return Result<void>::success();
876}
877
879 nodes_.clear();
880 edges_.clear();
881 laneLinks_.clear();
882 blockedLaneLinks_.clear();
883 nodeIndex_.clear();
884 edgeIndex_.clear();
885 nextNodeId_ = 1;
886 nextEdgeId_ = 1;
887 ++revision_;
888}
889
891 const int idx = findNodeIndex(id);
892 if (idx < 0) return Result<RoadNode>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown node", "id"));
893 return Result<RoadNode>::success(nodes_[static_cast<std::size_t>(idx)]);
894}
895
897 const int idx = findEdgeIndex(id);
898 if (idx < 0) return Result<RoadEdge>::failure(Diagnostic::error(DiagnosticCode::NotFound, "unknown edge", "id"));
899 return Result<RoadEdge>::success(edges_[static_cast<std::size_t>(idx)]);
900}
901
902} // namespace eve::procgen::road
double z
double y
double x
bool & active
glm::vec4 p[6]
Stable, structured diagnostics shared by engine modules.
std::string nodeId
std::array< double, 10 > q
double r
PhysicsJointLink link
std::array< float, 3 > position
std::string to
std::string from
std::string id
Poco::JSON::Object::Ptr result
bool valid
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
Placement placement
glm::dvec3 dx
glm::dvec3 dz
size_t directions
int idx
std::string path
Definition PlayHost.cpp:111
std::shared_ptr< const std::vector< glm::vec2 > > points
const RoadNode * node
RoadLaneDirection direction
bool found
int created
int removed
double current
float dy
Definition Shadow.cpp:151
uint32_t index
glm::vec3 point
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
const T & value() const &
Borrow the value from a const lvalue after checking success.
Definition Result.h:339
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Owning multi-segment 3D spline with deterministic bounded sampling.
Definition SplinePath.h:118
Result< int > reconnectEdgeEndpoint(std::uint32_t edgeId, bool fromEndpoint, std::uint32_t nodeId)
Reconnect one edge endpoint to an existing node and prune connections left at the old junction.
Result< void > removeNode(std::uint32_t nodeId)
Remove an isolated node.
Result< void > unblockLaneLink(const RoadLaneConnection &link)
Remove one exact persistent lane-link prohibition.
Result< void > setEdgeStyle(std::uint32_t edgeId, RoadStyle style)
Replace owning style/section/interval authoring atomically.
Result< void > addLaneLink(RoadLaneConnection link)
Register one legal turn inside a shared junction node.
Result< std::uint32_t > detachEdgeEndpoint(std::uint32_t edgeId, bool fromEndpoint)
Detach one edge endpoint onto a new coincident stable node.
Result< void > removeLaneLink(const RoadLaneConnection &link)
Remove one exact lane-to-lane connection.
Result< void > restoreNode(RoadNode node)
Restore a node with an explicit stable id for undo/import paths.
Result< RoadEdge > edgeResult(std::uint32_t id) const
Return an owning edge snapshot. @cost Copies control points, custom sections and bounded interval/fac...
Result< void > reverseEdge(std::uint32_t edgeId)
Atomically reverse one edge while preserving its physical lanes, links, and side-object intervals.
Result< void > validate() const
Validate graph, endpoint and lane-link invariants without mutation.
Result< void > setNodeJunctionRadius(std::uint32_t nodeId, float junctionRadius)
Replace one node's positive junction trim radius.
Result< void > setNodeJunctionControl(std::uint32_t nodeId, RoadJunctionControl control)
Replace one node's authoritative traffic-control policy.
Result< std::uint32_t > addEdge(std::uint32_t from, std::uint32_t to, std::vector< RoadControlPoint > controlPoints, int lanesForward=2, int lanesBackward=0, RoadStyle style={})
Insert a non-degenerate directed edge between two distinct live nodes.
Result< void > setNodePosition(std::uint32_t nodeId, float x, float y, float z)
Move a node and atomically re-anchor every incident edge endpoint.
Result< bool > blockLaneLink(RoadLaneConnection link)
Persistently forbid one exact legal lane connection and remove it if currently active.
Result< int > connectAllTurns(std::uint32_t nodeId)
Auto-connect all forward and backward lane ports at one node.
Result< std::uint32_t > addNode(float x, float y, float z, float junctionRadius=6.f)
Insert a junction node after validating finite coordinates.
Result< void > setEdgeControlPoints(std::uint32_t edgeId, std::vector< RoadControlPoint > controlPoints)
Replace one edge spline while preserving its node-owned endpoint positions.
void clear()
Clear every node, edge and link.
Result< RoadNode > nodeResult(std::uint32_t id) const
Return an owning node snapshot. @cost Copies the node-owned custom mesh and port sections; authoring ...
Result< void > removeEdge(std::uint32_t edgeId)
Remove an edge and every lane link that references it.
Result< void > restoreEdge(RoadEdge edge)
Restore an edge with an explicit stable id for undo/import paths.
Result< int > setEdgeLaneCounts(std::uint32_t edgeId, int lanesForward, int lanesBackward)
Atomically replace directional lane counts and remove links that become out of range.
Result< int > mergeNodes(std::uint32_t keepNodeId, std::uint32_t removeNodeId, float maxDistance)
Atomically merge one nearby endpoint node into another stable node.
Result< int > invalid(std::string message)
Invalid.
Result< void > validateConnectionAsset(const RoadConnection &connection)
Validate the owned asset, local frames, indexed topology and exact mesh boundary seams.
Result< void > validateFacilityRoutes(const RoadNetwork &network, const RoadNode &node)
Validate explicit one-to-one routes, compatible sections and live incident endpoint ownership.
void reverseRoadAuthoring(RoadStyle &style)
Reflect section and interval authoring while preserving physical placement.
Result< void > validateConnectionSeams(const RoadNetwork &network, const RoadNode &node)
Validate actual baked spline sockets against every full custom asset seam.
Result< RoadProfile > makeRoadProfile(const RoadStyle &style, int lanesForward, int lanesBackward)
Build a mathematical road cross-section for the given lane counts.
RoadJunctionControl
Authoritative traffic-control policy applied to every approach of one junction node.
Definition RoadTypes.h:232
@ Signal
Every incoming approach is controlled by a traffic signal.
@ Uncontrolled
Edge trafficPriority resolves right-of-way without a mandatory stop.
int mapLaneByLateralRank(int inLane, int inLaneCount, int outLaneCount)
bool validJunctionControl(RoadJunctionControl control)
RoadLaneDirection
Travel direction of a lane relative to the authored edge centerline.
Definition RoadTypes.h:304
@ Forward
Travels from RoadEdge::from to RoadEdge::to.
@ Backward
Travels from RoadEdge::to to RoadEdge::from.
SplineSpanControl
Native outgoing overrides; Inherit uses the path kind.
Definition SplinePath.h:22
One spline anchor with incoming and outgoing handle offsets.
Definition SplinePath.h:25
Directed centerline edge with optional reverse lanes.
Definition RoadTypes.h:286
One legal lane-to-lane connection inside a junction.
Definition RoadTypes.h:315
Junction node owned by a road network.
Definition RoadTypes.h:275
Owning cross-section, width policy and structural authoring for one road edge.
Definition RoadTypes.h:182