mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-31 19:19:03 +01:00
fix(editor): no path of a few millimetres laid by the route design, and no camera at no finite place: an arc of a compound curve squeezed to almost nothing in the plan (a share of 0.00002) made pieces of a few millimetres, which the simulation takes for paths of no length (Bad track: zero length spline, it measures a path in steps of 5 cm), laid as tracks with kinks at their joints. alignment::pieces gives such a stretch to the piece next to it, the one between the same joints if there's one, so no piece is shorter than 10 cm, and a piece of no finite length isn't split for ever. A zoom with the wheel aimed at a point which isn't a number doesn't move the camera, and a camera gone to no finite place goes back to where it last was: right after such tracks were laid the graphics driver hung (TDR) and the whole machine froze. A unit test cuts 4000 compound curves of random arcs, transitions and shares into pieces, as the plan lays them over the paths there and all over again, and finds none under 5 cm
This commit is contained in:
@@ -2822,6 +2822,37 @@ std::vector<segment_data> pieces(result const &Result, design const &Design, std
|
||||
auto const interval = [&](span const &Span) {
|
||||
return static_cast<std::size_t>(std::upper_bound(Breaks.begin(), Breaks.end(), (chainage_from(Span) + chainage_to(Span)) * 0.5) - Breaks.begin());
|
||||
};
|
||||
// no path of a few millimetres, as an arc of a compound curve squeezed to almost nothing or a joint by the end of an element
|
||||
// leaves: the simulation takes a path under 5 cm for one of no length. Such a stretch goes to the path next to it, the one
|
||||
// between the same joints if there's one
|
||||
double constexpr shortest_piece{0.1};
|
||||
for (std::size_t i = 0; i < spans.size() && spans.size() > 1;)
|
||||
{
|
||||
if (extent(spans[i]) >= shortest_piece)
|
||||
{
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
auto const own{interval(spans[i])};
|
||||
auto const backward{i > 0 && (i + 1 == spans.size() || interval(spans[i - 1]) == own || interval(spans[i + 1]) != own)};
|
||||
if (backward)
|
||||
{
|
||||
auto &previous{spans[i - 1]};
|
||||
previous.start = chainage_from(previous);
|
||||
previous.end = chainage_to(spans[i]);
|
||||
previous.generic = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &next{spans[i + 1]};
|
||||
next.end = chainage_to(next);
|
||||
next.start = chainage_from(spans[i]);
|
||||
next.generic = true;
|
||||
}
|
||||
spans.erase(spans.begin() + static_cast<std::ptrdiff_t>(i));
|
||||
if (i > 0)
|
||||
--i;
|
||||
}
|
||||
for (std::size_t k = 0; k < Counts.size(); ++k)
|
||||
{
|
||||
while (true)
|
||||
@@ -2846,7 +2877,8 @@ std::vector<segment_data> pieces(result const &Result, design const &Design, std
|
||||
{
|
||||
auto const from{chainage_from(spans[i])};
|
||||
auto const length{chainage_to(spans[i]) - from};
|
||||
if (length <= geometry::longest_path)
|
||||
// a length not finite would be split for ever
|
||||
if (length <= geometry::longest_path || false == std::isfinite(length))
|
||||
{
|
||||
++i;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user