diff --git a/application/editormodecrossing.cpp b/application/editormodecrossing.cpp index 74a0760fd..4d0fc8ca4 100644 --- a/application/editormodecrossing.cpp +++ b/application/editormodecrossing.cpp @@ -373,7 +373,15 @@ void editor_mode::crossings_update() continue; level_crossing::design_result result; std::string reason; - if (editor_road::settle_crossing(*road, record, result, reason)) + auto const laid{editor_road::settle_crossing(*road, record, result, reason)}; + // a road refused is told, with its fix, whatever comes of the roads after it: the last one's outcome told, a road laid after it + // took the refusal and its window away, and the road refused stayed as it was with nothing told + if (refusal) + { + WriteLog(format("Editor: crossing of %s %s, the refusal of another road told", road->name().c_str(), laid ? "laid" : "refused")); + continue; + } + if (laid) { text = crossing_summary(result); refusal = false; diff --git a/editor/editorRoad.cpp b/editor/editorRoad.cpp index 5b2e9f093..a329e9bdb 100644 --- a/editor/editorRoad.cpp +++ b/editor/editorRoad.cpp @@ -2146,6 +2146,33 @@ double outer_halfwidth(road_node::state const &State) return 0.5 * std::max(State.span(0.0), State.span(1.0)) + sides + kerbs; } +// none of the paths of the track starts within its own length of the box of the road's axis, as rails_crossing() takes them: the road +// can't cross it, the paths of the scenery aren't gone through for it +bool far_from_road(TTrack const &Track, segment_data const &Axis) +{ + glm::dvec2 low{std::numeric_limits::max()}; + glm::dvec2 high{-std::numeric_limits::max()}; + // the curve within the box of its control points + for (auto const &point : curve_points(Axis)) + { + low = glm::min(low, glm::dvec2{point.x, point.z}); + high = glm::max(high, glm::dvec2{point.x, point.z}); + } + for (int path = 0; path < track_rails::path_count(Track); ++path) + { + auto const &segment{track_rails::path_segment(Track, path)}; + auto const length{segment.GetLength()}; + if (length <= 0.0) + continue; + glm::dvec3 start; + glm::dvec3 across; + segment.plan_frame(0.0, start, across); + if (start.x >= low.x - length && start.x <= high.x + length && start.z >= low.y - length && start.z <= high.y + length) + return false; + } + return true; +} + // the paths of the rail tracks the road crosses near the height of its axis, each as it lies where it's crossed std::vector rails_crossing(std::vector const &Pieces) { @@ -2179,15 +2206,19 @@ std::vector rails_crossing(std::vector rail; glm::dvec3 across; + auto const far_from = [&](glm::dvec3 const &Point) { return Point.x < low.x - length || Point.x > high.x + length || Point.z < low.y - length || Point.z > high.y + length; }; + // tried at its start first: the points along a path far from the roads were worked out for nothing, for every path of the + // scenery after every track edit + glm::dvec3 start; + segment.plan_frame(0.0, start, across); + if (far_from(start)) + continue; for (int j = 0; j <= railpieces; ++j) { glm::dvec3 point; segment.plan_frame(length * j / railpieces, point, across); rail.push_back(point); } - auto const far_from = [&](glm::dvec3 const &Point) { return Point.x < low.x - length || Point.x > high.x + length || Point.z < low.y - length || Point.z > high.y + length; }; - if (far_from(rail.front())) - continue; for (int j = 1; j <= railpieces; ++j) for (auto const &line : lines) for (std::size_t i = 0; i + 1 < line.size(); ++i) @@ -2272,15 +2303,13 @@ std::vector editor_road::roads_across(TTrack const &Track) return result; for (auto *road : simulation::Roads.sequence()) { - if (road == nullptr || road->m_editorremoved) + if (road == nullptr || road->m_editorremoved || far_from_road(Track, road->definition().axis)) continue; std::vector pieces{{road->definition().axis, outer_halfwidth(road->definition())}}; - for (auto const &track : rails_crossing(pieces)) - if (track.name == Track.name()) - { - result.push_back(road); - break; - } + // the track itself: by its name, every road across an unnamed track (none, read as no name) was taken, or across another track + // of the same name, and laid again with the edit of a track it doesn't cross + if (std::ranges::any_of(rails_crossing(pieces), [&Track](level_crossing::rail_track const &Crossed) { return Crossed.source == &Track; })) + result.push_back(road); } return result; }