mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 06:35:21 +01:00
test(editor): the station track picked by bands of height in a unit case; a station failing half way and one at the history cap in self-tests
The review of #508 asked for these two. - The choice of the track a station starts or ends on is trace_station::pick_station_track(), a free function of editor/editorTraceStation: the tracks in reach in plan compared by bands of 3 m of height, then by the distance in plan, the first of two alike. editor_mode::station_track_at() collects the tracks as before and takes its pick, in the same order and with the same comparisons, so it picks what it picked. The unit case covers a flyover above and a bridge over a cutting against the track at the height clicked, a high embankment within one band, a track only far above or below, the reach and the width of the bands. - st_5_station_failed: the station of st_1 made to fail after its first turnout, then after both turnouts with the line between them not laid. Each time the turnouts laid are taken back, the main track is as it was, the clicks are kept but the last one, the reason is told and Ctrl+Y has nothing to lay; the last click again lays the station in full. - st_6_station_history_cap: the same station laid with the history capped at 2 steps, laid in full and not taken for failed. - For them the self-test has stationfail <end|line> (the next station made to fail there, once; lay_station() asks selftest_station_fails(), which only the self-test sets), historycap <steps> and expect laypoints <count>.
This commit is contained in:
@@ -2255,6 +2255,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
// lays the turnouts of the station, then the line between them as the lay tool lays one from a free end, one step of the history; End:
|
||||
// the free end the line reached
|
||||
void lay_station(traced_station const &Station, editor_track::snap_target const &End);
|
||||
// the self-test made this station fail at Where (stationfail): once, told in the log
|
||||
bool selftest_station_fails(std::string_view Where);
|
||||
bool m_station_laying{false}; // the line of a station laid from the ends of its turnouts: no station looked for again
|
||||
std::optional<alignment::design> m_station_design; // the line designed of the station laid from the ends of its turnouts
|
||||
// the tracer of the points given, kept from one call to the next as long as they go on from the ones before
|
||||
@@ -3567,6 +3569,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
glm::vec2 badge_at{0.0f}; // its bottom left corner, in the pixels of the window
|
||||
std::map<std::string, double> marks; // the heights of the ends of tracks kept by mark, for expect lift
|
||||
std::optional<std::pair<bool, bool>> terrain_kept; // the terrain made while laying, and the answer without it, before nmtquestion
|
||||
// the next station traced on the photo made to fail, for the cases of its failure path: end (the turnout it ends with isn't laid,
|
||||
// after the one it starts with) or line (the track between the turnouts isn't, after both)
|
||||
std::string station_fails;
|
||||
};
|
||||
selftest m_selftest;
|
||||
using selftest_result = editor_selftest_result;
|
||||
|
||||
@@ -145,6 +145,9 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
|
||||
// Tab; curve: a curve traced between bends, the shape of before, reached by the self-test alone; default:
|
||||
// as the user who hasn't chosen, traced where the photo is on
|
||||
// laysigma <m> the noise of the clicks from now on; 0: two pixels of the view at each
|
||||
// stationfail <end|line> the next station traced on the photo made to fail: the turnout it ends with not laid (after the
|
||||
// one it starts with), or the track between the turnouts (after both)
|
||||
// historycap <steps> the cap of the size of the history from now on, as its window sets it: the oldest steps dropped
|
||||
// laysettings <0|1> the settings of the lay tool opened under the line of their summary, or folded into it, as a
|
||||
// click on that line does while the points are clicked
|
||||
// endcurves logs every free end of the rails: where, the way out and the curvature its track goes on with
|
||||
|
||||
@@ -877,6 +877,14 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
|
||||
if (false == malformed(what, words))
|
||||
expectation(m_lay.tabs == tabs && m_lay.enters == enters, what, format("%d Tab, %d Enter", m_lay.tabs, m_lay.enters), format("%d Tab, %d Enter", tabs, enters));
|
||||
}
|
||||
else if (kind == "laypoints")
|
||||
{
|
||||
// the points of the lay tool clicked and not laid yet
|
||||
std::size_t wanted{0};
|
||||
words >> wanted;
|
||||
if (false == malformed(what, words))
|
||||
expectation(m_lay.points.size() == wanted, what, std::to_string(m_lay.points.size()), std::to_string(wanted));
|
||||
}
|
||||
else if (kind == "laycontinue")
|
||||
{
|
||||
int wanted{0};
|
||||
|
||||
@@ -508,6 +508,23 @@ editor_mode::selftest_result editor_mode::selftest_join(std::string const &comma
|
||||
WriteLog(format("SELFTEST laysigma: %.3f m", m_lay.sigma_given));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
// the next station traced made to fail: end (the turnout it ends with not laid, after the one it starts with) or line (the track
|
||||
// between the turnouts not laid, after both), for the cases of what it leaves behind
|
||||
if (command == "stationfail")
|
||||
{
|
||||
words >> m_selftest.station_fails;
|
||||
WriteLog("SELFTEST stationfail: next at " + m_selftest.station_fails);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
// the cap of the size of the history from now on (the setting of the history window), the oldest steps dropped past it
|
||||
if (command == "historycap")
|
||||
{
|
||||
int cap{m_max_history_size};
|
||||
words >> cap;
|
||||
m_max_history_size = std::max(1, cap);
|
||||
WriteLog(format("SELFTEST historycap: %d", m_max_history_size));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "laysettings")
|
||||
{
|
||||
// as a click on the line of their summary while the points are clicked: the settings shown under it, or folded into it again
|
||||
|
||||
@@ -124,13 +124,9 @@ editor_mode::station_catalogue const &editor_mode::station_shapes(std::string co
|
||||
editor_mode::track_under editor_mode::station_track_at(glm::dvec3 const &Point) const
|
||||
{
|
||||
track_under result;
|
||||
TTrack *found{nullptr};
|
||||
auto best{kStationReach};
|
||||
// a track at the height clicked wins over one above or below it (a bridge, a flyover): the tracks in reach in plan are compared
|
||||
// in bands of 3 m of height, and by the distance in plan within one. The height clicked is a guess where the terrain isn't there
|
||||
// yet, and the ground plus the bed is off on an embankment, so a track in reach only far above or below it is still taken
|
||||
double constexpr kHeightBand{3.0};
|
||||
auto bestband{std::numeric_limits<int>::max()};
|
||||
// the tracks near the click, chosen by trace_station::pick_station_track: by bands of height, then by the distance in plan
|
||||
std::vector<TTrack *> tracks;
|
||||
std::vector<trace_station::track_near> nearby;
|
||||
for (auto *section : simulation::Region->sections(Point, 40.f))
|
||||
for (auto const &cell : section->m_cells)
|
||||
for (auto *track : cell.m_paths)
|
||||
@@ -138,17 +134,13 @@ editor_mode::track_under editor_mode::station_track_at(glm::dvec3 const &Point)
|
||||
if (track->eType != tt_Normal || track->m_editorremoved || track->m_paths.empty() || (track->iCategoryFlag & 15) != kRailCategory)
|
||||
continue;
|
||||
auto const nearest{editor_track::point_at(*track, editor_track::nearest_parameter(*track, Point))};
|
||||
auto const distance{plan_distance(nearest, Point)};
|
||||
auto const band{static_cast<int>(std::min(std::abs(nearest.y - Point.y) / kHeightBand, 1000.0))};
|
||||
if (distance < kStationReach && (band < bestband || (band == bestband && distance < best)))
|
||||
{
|
||||
bestband = band;
|
||||
best = distance;
|
||||
found = track;
|
||||
}
|
||||
tracks.push_back(track);
|
||||
nearby.emplace_back(plan_distance(nearest, Point), nearest.y - Point.y);
|
||||
}
|
||||
if (found == nullptr)
|
||||
auto const picked{trace_station::pick_station_track(nearby, kStationReach)};
|
||||
if (picked < 0)
|
||||
return result;
|
||||
auto *found{tracks[static_cast<std::size_t>(picked)]};
|
||||
// by a free end the line goes on from the end, or ends at it
|
||||
if (editor_track::find_free_end(nullptr, kRailCategory, Point, kStationEndAway, {}).track != nullptr)
|
||||
return result;
|
||||
@@ -594,6 +586,15 @@ editor_mode::traced_station const &editor_mode::traced_station_of(std::vector<gl
|
||||
return done();
|
||||
}
|
||||
|
||||
bool editor_mode::selftest_station_fails(std::string_view const Where)
|
||||
{
|
||||
if (m_selftest.station_fails != Where)
|
||||
return false;
|
||||
m_selftest.station_fails.clear();
|
||||
WriteLog("SELFTEST stationfail: " + std::string{Where} + " not laid");
|
||||
return true;
|
||||
}
|
||||
|
||||
void editor_mode::lay_station(traced_station const &Station, editor_track::snap_target const &End)
|
||||
{
|
||||
auto &tool{m_lay};
|
||||
@@ -735,7 +736,11 @@ void editor_mode::lay_station(traced_station const &Station, editor_track::snap_
|
||||
}
|
||||
if (Station.end.has_value())
|
||||
{
|
||||
auto *laid{lay_turnout(*Station.end)};
|
||||
TTrack *laid{nullptr};
|
||||
if (selftest_station_fails("end"))
|
||||
m_switch.status.clear();
|
||||
else
|
||||
laid = lay_turnout(*Station.end);
|
||||
into = branch_end(laid);
|
||||
if (into.track == nullptr)
|
||||
return back(m_switch.status.empty() ? std::string{STR_C("The turnout couldn't be laid")} : m_switch.status);
|
||||
@@ -778,7 +783,10 @@ void editor_mode::lay_station(traced_station const &Station, editor_track::snap_
|
||||
auto const line_top{history_top()};
|
||||
m_station_laying = true;
|
||||
m_station_design = Station.design;
|
||||
lay_finish(into);
|
||||
if (selftest_station_fails("line"))
|
||||
tool.status.clear();
|
||||
else
|
||||
lay_finish(into);
|
||||
m_station_laying = false;
|
||||
m_station_design.reset();
|
||||
if (history_top() <= line_top)
|
||||
|
||||
@@ -445,4 +445,23 @@ head_place place_in_head(double const From, double const Length, double const Lo
|
||||
return result;
|
||||
}
|
||||
|
||||
int pick_station_track(std::vector<track_near> const &Tracks, double const Reach, double const Band)
|
||||
{
|
||||
int found{-1};
|
||||
auto best{Reach};
|
||||
auto bestband{std::numeric_limits<int>::max()};
|
||||
for (std::size_t index = 0; index < Tracks.size(); ++index)
|
||||
{
|
||||
auto const &track{Tracks[index]};
|
||||
auto const band{static_cast<int>(std::min(std::abs(track.height) / Band, 1000.0))};
|
||||
if (track.plan < Reach && (band < bestband || (band == bestband && track.plan < best)))
|
||||
{
|
||||
bestband = band;
|
||||
best = track.plan;
|
||||
found = static_cast<int>(index);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
} // namespace trace_station
|
||||
|
||||
@@ -136,4 +136,18 @@ struct head_place
|
||||
};
|
||||
head_place place_in_head(double From, double Length, double Low, double High, bool Before, bool After, double Least);
|
||||
|
||||
// a track near the point a station starts or ends with a click on: how far in plan the nearest point of its axis is from the click, how
|
||||
// far that point is above it (below it, less than 0)
|
||||
struct track_near
|
||||
{
|
||||
double plan{0.0}; // m
|
||||
double height{0.0}; // m
|
||||
};
|
||||
|
||||
// The track a station starts or ends on, of those near the point clicked: its index, -1 where none is within Reach in plan. A track at
|
||||
// the height clicked wins over one above or below it (a bridge, a flyover): the tracks are compared in bands of Band metres of height,
|
||||
// and by the distance in plan within one; of two alike the first. The height clicked is a guess where the terrain isn't there yet, and
|
||||
// the ground plus the bed is off on an embankment, so a track in reach only far above or below the click is still taken
|
||||
int pick_station_track(std::vector<track_near> const &Tracks, double Reach, double Band = 3.0);
|
||||
|
||||
} // namespace trace_station
|
||||
|
||||
@@ -139,6 +139,7 @@ tool's `parallel <spacing> <side>` lay turnouts, crossovers and lines of the mod
|
||||
| `expect laid radius <curve> <R>[/<R>...] <tolerance %>`, `expect laid speed <curve> <km/h>`, `expect laid nearly <curve> <0\|1>` | a curve of it: the radii of its arcs, the speed it's laid for, nearly straight (R 5 km and more) |
|
||||
| `expect laid slowtracks <km/h> <at least>`, `expect laid joined <0\|1>` | its tracks given the speed of a curve slowed down; its first track joined at its start to the one it goes on from |
|
||||
| `expect laykeys <tabs> <enters>`, `expect laycontinue <0\|1>` | the shapes switched with Tab and the lines laid with Enter so far; the lay tool goes on from the end of the line laid |
|
||||
| `expect laypoints <count>` | the points of the lay tool clicked and not laid yet |
|
||||
| `expect layheights <fitted\|points\|level>` | the heights the line is laid at now: fitted to the ground (from the photo by itself till the heights are chosen), through the points clicked, level |
|
||||
| `expect laid steepest <per mille>`, `expect laywait <0\|1>`, `expect layguessed <count>` | the steepest grade of the tracks of the line laid last; the line waits for the terrain under its points to be laid; the points clicked whose height is a guess, no ground under them yet |
|
||||
| `expect station turnouts <count>`, `expect station turnout <0\|1> <type>`, `expect station moved <0\|1> <m> <tolerance>`, `expect station crossover <0\|1>` | the station traced on the photo last: the switches laid with its line; the type of the turnout it starts with (0) or ends with (1), `_` for spaces; how far the norms of the head moved that turnout; laid as a crossover of the solver |
|
||||
@@ -246,6 +247,8 @@ as on the photo):
|
||||
| `st_2_crossover` | from a click on a track to one on the track 4.75 m beside it, only the points along the crossover between them: the crossover of the solver, two turnouts Rz 60E1-300-1:9, one step |
|
||||
| `st_3_alongside` | a line clicked about 4.08 m off a straight track laid exactly alongside it at 4.0 m |
|
||||
| `st_4_head_moved` | a turnout traced 6.3 m past the end of the one before it on the main track moved on to keep the 7.5 m straight the norms ask between them at 50 km/h, told so |
|
||||
| `st_5_station_failed` | the station of `st_1` made to fail (`stationfail`) after its first turnout, then after both turnouts, the line between them not laid: each time the turnouts laid taken back, the main track as it was, the clicks kept but the last one on the main track, the reason told, nothing left for Ctrl+Y; the last click again lays the station in full |
|
||||
| `st_6_station_history_cap` | the station of `st_1` laid with the history at a cap of 2 steps (`historycap`), so its size stops growing while the turnouts and the line are laid: laid in full, not taken for failed and taken back |
|
||||
|
||||
and the assumptions of the project and the norms enforced when laying (`editor-project-setup.md`):
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
# Stations from the photo (Etap 5): what a station which fails half way leaves. The station of st_1 made to fail (stationfail) after its
|
||||
# first turnout is laid, then after both turnouts are laid and the line between them isn't: each time the turnouts laid are taken back,
|
||||
# the main track is as it was (one step of the history), the clicks are kept but the last one, on the main track, the reason is told and
|
||||
# Ctrl+Y has nothing to lay. The last click again lays the station in full. The empty ground north-east of the fixture (x 2000.., z 9000..)
|
||||
wait 5
|
||||
tap f3
|
||||
wait 2
|
||||
tap l
|
||||
wait 2
|
||||
laymode traced
|
||||
laysigma 0.1
|
||||
# the main track, 1 km straight
|
||||
layp 2000 9000 2500 9000 3000 9000
|
||||
layenter
|
||||
wait 2
|
||||
tap esc
|
||||
wait 2
|
||||
expect steps 1
|
||||
# the turnout it ends with not laid
|
||||
stationfail end
|
||||
layp 2199.50 9000.00 2208.04 9000.06 2215.03 9000.36 2222.05 9000.77 2229.02 9001.37 2238.04 9002.33 2250.01 9003.60 2260.03 9004.28 2270.05 9004.68 2320.02 9004.79 2399.95 9004.78 2499.98 9004.80 2599.96 9004.77 2679.97 9004.79 2729.95 9004.70 2739.98 9004.35 2749.96 9003.67 2761.99 9002.40 2768.54 9001.61 2800.50 9000.00
|
||||
wait 2
|
||||
expect steps 1
|
||||
expect station status The turnout couldn't be laid
|
||||
expect laypoints 19
|
||||
redo
|
||||
wait 2
|
||||
expect steps 1
|
||||
# the last click again: the station in full
|
||||
layp 2800.50 9000.00
|
||||
wait 2
|
||||
expect station turnouts 2
|
||||
expect station free 0
|
||||
expect station status Alongside
|
||||
expect steps 2
|
||||
undo
|
||||
wait 2
|
||||
expect steps 1
|
||||
tap esc
|
||||
wait 2
|
||||
# the line between the turnouts not laid, both of them laid before it
|
||||
stationfail line
|
||||
layp 2199.50 9000.00 2208.04 9000.06 2215.03 9000.36 2222.05 9000.77 2229.02 9001.37 2238.04 9002.33 2250.01 9003.60 2260.03 9004.28 2270.05 9004.68 2320.02 9004.79 2399.95 9004.78 2499.98 9004.80 2599.96 9004.77 2679.97 9004.79 2729.95 9004.70 2739.98 9004.35 2749.96 9003.67 2761.99 9002.40 2768.54 9001.61 2800.50 9000.00
|
||||
wait 2
|
||||
expect steps 1
|
||||
expect station status The track between the turnouts couldn't be laid
|
||||
expect laypoints 19
|
||||
redo
|
||||
wait 2
|
||||
expect steps 1
|
||||
layp 2800.50 9000.00
|
||||
wait 2
|
||||
expect station turnouts 2
|
||||
expect station free 0
|
||||
expect steps 2
|
||||
quit
|
||||
@@ -0,0 +1,27 @@
|
||||
# Stations from the photo (Etap 5): the station of st_1 laid with the history at a cap of 2 steps (historycap), so the size of the
|
||||
# history stops growing while its turnouts and its line are laid: the station is laid in full, not taken for failed, its turnouts not
|
||||
# taken back. The empty ground north-east of the fixture (x 2000.., z 9000..)
|
||||
wait 5
|
||||
tap f3
|
||||
wait 2
|
||||
tap l
|
||||
wait 2
|
||||
laymode traced
|
||||
laysigma 0.1
|
||||
# the main track, 1 km straight
|
||||
layp 2000 9000 2500 9000 3000 9000
|
||||
layenter
|
||||
wait 2
|
||||
tap esc
|
||||
wait 2
|
||||
expect steps 1
|
||||
historycap 2
|
||||
layp 2199.50 9000.00 2208.04 9000.06 2215.03 9000.36 2222.05 9000.77 2229.02 9001.37 2238.04 9002.33 2250.01 9003.60 2260.03 9004.28 2270.05 9004.68 2320.02 9004.79 2399.95 9004.78 2499.98 9004.80 2599.96 9004.77 2679.97 9004.79 2729.95 9004.70 2739.98 9004.35 2749.96 9003.67 2761.99 9002.40 2768.54 9001.61 2800.50 9000.00
|
||||
wait 2
|
||||
expect station turnouts 2
|
||||
expect station turnout 0 Rz_60E1-300-1:9
|
||||
expect station turnout 1 Rz_60E1-300-1:9
|
||||
expect station free 0
|
||||
expect station status Alongside
|
||||
expect laypoints 0
|
||||
quit
|
||||
@@ -412,3 +412,29 @@ TEST_CASE("trace_station: the arc joining the diverging track of a turnout onto
|
||||
// running alongside already, no arc
|
||||
CHECK_FALSE(trace_station::join_alongside({0.0, 4.75}, {1.0, 0.0}, alongside, {}, {}, 300.0).valid);
|
||||
}
|
||||
|
||||
TEST_CASE("trace_station: the track a station starts on picked by the height clicked before the distance in plan") {
|
||||
auto constexpr reach{1.5};
|
||||
// a flyover 7 m above the click, nearer in plan, and the track at the height clicked: the one at the height
|
||||
CHECK(trace_station::pick_station_track({{0.2, 7.0}, {1.1, 0.1}}, reach) == 1);
|
||||
// the other way round in the list: the same track
|
||||
CHECK(trace_station::pick_station_track({{1.1, 0.1}, {0.2, 7.0}}, reach) == 0);
|
||||
// a track in a cutting below the bridge clicked on: the bridge
|
||||
CHECK(trace_station::pick_station_track({{0.3, -8.5}, {1.2, -0.4}}, reach) == 1);
|
||||
// within one band of 3 m the nearer in plan, whatever the height: on a high embankment the click at the ground is 2.4 m below
|
||||
CHECK(trace_station::pick_station_track({{1.0, 0.2}, {0.4, 2.4}}, reach) == 1);
|
||||
// a station on an embankment, or clicked before the terrain came: the only track in reach is far above or below the click, still taken
|
||||
CHECK(trace_station::pick_station_track({{0.6, 12.0}}, reach) == 0);
|
||||
CHECK(trace_station::pick_station_track({{0.6, -30.0}}, reach) == 0);
|
||||
// of two far off the click the nearer in height first: 9.5 m above against 13 m below
|
||||
CHECK(trace_station::pick_station_track({{0.1, -13.0}, {1.4, 9.5}}, reach) == 1);
|
||||
// out of reach in plan: not taken, at any height
|
||||
CHECK(trace_station::pick_station_track({{1.5, 0.0}, {2.0, 0.0}}, reach) == -1);
|
||||
CHECK(trace_station::pick_station_track({{1.6, 0.0}, {0.9, 6.5}}, reach) == 1);
|
||||
CHECK(trace_station::pick_station_track({}, reach) == -1);
|
||||
// two alike: the first
|
||||
CHECK(trace_station::pick_station_track({{0.5, 1.0}, {0.5, -1.0}}, reach) == 0);
|
||||
// the bands are those asked for: 1 m bands tell 0.5 m from 2 m above apart
|
||||
CHECK(trace_station::pick_station_track({{0.1, 2.0}, {1.0, 0.5}}, reach, 1.0) == 1);
|
||||
CHECK(trace_station::pick_station_track({{0.1, 2.0}, {1.0, 0.5}}, reach) == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user