mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 04:47:06 +01:00
Merge feat/editor-legacy-takeover into feat/editor-model-turnouts-ui
# Conflicts: # editor/project/projectSession.cpp
This commit is contained in:
@@ -652,7 +652,7 @@ void editor_mode::ground_sources(editor_orthophoto &Layer)
|
||||
return true;
|
||||
// asked for, the tile goes onto it once it comes; not where no terrain is to be made of the model, as after the answer without
|
||||
// terrain
|
||||
if (m_nmt.placed() && (m_nmt_state.grow || EditorSettings.terrain_model().area))
|
||||
if (m_nmt.placed() && (m_nmt_state.grow || nmt_area()))
|
||||
m_nmt.request({X - 1.0, Z - 1.0}, {X + 1.0, Z + 1.0});
|
||||
return false;
|
||||
});
|
||||
@@ -1904,9 +1904,13 @@ void editor_mode::render_terrain_loading()
|
||||
if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip("%s", STR_C("Where the terrain of the scenery ends, the terrain model is made under the tracks as they're laid, around the cursor from the first point placed; "
|
||||
"the chunks there are stay as they are. Off, it's made only when asked for"));
|
||||
auto &model{EditorSettings.terrain_model()};
|
||||
if (ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &model.area))
|
||||
// as it is for the scenery open: off after the answer Without terrain, and ticked, on again and kept so in the settings
|
||||
if (bool area{nmt_area()}; ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &area))
|
||||
{
|
||||
m_nmt_state.declined = false;
|
||||
EditorSettings.terrain_model().area = area;
|
||||
EditorSettings.save();
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip("%s", STR_C("Makes the terrain from the terrain model within the area, around the camera wherever it goes,\n"
|
||||
"a chunk at a time while the editor is idle. The terrain there is already isn't touched.\n"
|
||||
@@ -6431,7 +6435,7 @@ void editor_mode::render_ground_warning(tutorial_lesson const &Lesson)
|
||||
// over a panel the pointer is over no ground, and in a scenery laid without terrain no ground is to be there
|
||||
if (Lesson.action != tutorial_lesson::trial::lay || ui()->mode() != nodebank_panel::TRACK || ImGui::GetIO().WantCaptureMouse || false == ImGui::IsMousePosValid())
|
||||
return;
|
||||
auto const expected{m_streamer.resident() > 0 || ((m_nmt_state.grow || EditorSettings.terrain_model().area) && m_nmt.placed())};
|
||||
auto const expected{m_streamer.resident() > 0 || ((m_nmt_state.grow || nmt_area()) && m_nmt.placed())};
|
||||
if (expected && false == GfxRenderer->Mouse_Hit())
|
||||
ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", STR_C("There is no ground under the mouse: the track will lie flat at height 0. Terrain model: F5"));
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "world/Sweep.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <chrono>
|
||||
@@ -394,6 +395,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
double band{300.0}; // m from the tracks the chunks made along them reach
|
||||
bool shape{true}; // the formation and the slopes of the tracks as modifiers of the terrain
|
||||
bool grow{true}; // while a track is laid, the terrain is made around the cursor where there's none
|
||||
// the answer Without terrain for the scenery open: nothing of the model is made around the camera by itself, whatever the
|
||||
// settings, which stay as they were for the other sceneries
|
||||
bool declined{false};
|
||||
bool laying{false}; // the tracks committed are being laid: they leave the terrain as it is
|
||||
bool follow{true}; // a track with its formation edited takes it along, the formation led anew
|
||||
bool grown{false}; // the chunks waiting were all asked for by growing: the formations aren't made anew after them
|
||||
@@ -665,8 +669,10 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
void nmt_place_scenery(glm::dvec2 const &Point);
|
||||
void nmt_accept_offer();
|
||||
// the answer without terrain: the tracks lie on the plane, nothing of the terrain model is loaded by itself any more, under the
|
||||
// tracks laid nor around the camera
|
||||
// tracks laid nor around the camera, in the scenery open; the settings stay as they are for the other sceneries
|
||||
void nmt_decline_offer();
|
||||
// the terrain of the download area made around the camera by itself: as the settings have it, unless declined for this scenery
|
||||
bool nmt_area() const;
|
||||
// the whole scenery: tracks, includes and models, moved up or down as one undo step
|
||||
std::size_t nmt_join_ends();
|
||||
// the turntables as they lie, each with the ends of the tracks running up to it on its rim
|
||||
@@ -1145,6 +1151,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
// false, with the reason, when one of the paths can't be changed, its file not taking the changes back
|
||||
static bool tracks_editable(std::vector<TTrack *> const &Tracks, std::string &Reason);
|
||||
void trim_history();
|
||||
// the serial of the step on top of the history, 0 with none
|
||||
std::uint64_t history_top() const;
|
||||
void restore_track_snapshot(EditorSnapshot const &Snapshot, std::vector<EditorSnapshot> &Opposite, bool const Undo);
|
||||
// changes of the kept alignments and switches go into the last step of the history, made just before them
|
||||
void records_to_history();
|
||||
@@ -1925,9 +1933,10 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
bool settings_open{false};
|
||||
bool details_open{false};
|
||||
bool notes_open{false};
|
||||
// the status tells of a line laid just now, as long as the history stays at the step it was laid with
|
||||
// the status tells of a line laid just now, as long as the history stays at the step it was laid with: the serial of the step on
|
||||
// top then, not the size of the history, which an undo and another step make the same again
|
||||
bool laid_now{false};
|
||||
std::size_t laid_step{0};
|
||||
std::uint64_t laid_step{0};
|
||||
// the line laid last, told in the inspector while the last of its tracks stays the selection the laying left
|
||||
struct laid_curve
|
||||
{
|
||||
@@ -3328,7 +3337,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
std::string badge; // the mouse or the keys drawn over the view, for the clips of the tutorial
|
||||
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 around the camera before nmtquestion
|
||||
std::optional<std::pair<bool, bool>> terrain_kept; // the terrain made while laying, and the answer without it, before nmtquestion
|
||||
};
|
||||
selftest m_selftest;
|
||||
using selftest_result = editor_selftest_result;
|
||||
|
||||
@@ -2179,7 +2179,7 @@ void editor_mode::lay_finish(editor_track::snap_target const &End)
|
||||
tool.points.clear();
|
||||
tool.modes.clear();
|
||||
tool.start = {};
|
||||
tool.laid_step = m_history.size();
|
||||
tool.laid_step = history_top();
|
||||
straight_refresh();
|
||||
}
|
||||
|
||||
@@ -2190,7 +2190,7 @@ void editor_mode::lay_told(double const Length, std::size_t const Tracks)
|
||||
tool.status_time = ImGui::GetTime();
|
||||
tool.laid_now = true;
|
||||
tool.notes_open = false;
|
||||
tool.laid_step = m_history.size();
|
||||
tool.laid_step = history_top();
|
||||
}
|
||||
|
||||
void editor_mode::lay_enter()
|
||||
@@ -2390,13 +2390,18 @@ alignment::limits editor_mode::laying_norms() const
|
||||
return norms;
|
||||
}
|
||||
|
||||
std::uint64_t editor_mode::history_top() const
|
||||
{
|
||||
return m_history.empty() ? 0 : m_history.back().serial;
|
||||
}
|
||||
|
||||
editor_mode::lay_state editor_mode::lay_panel_state() const
|
||||
{
|
||||
if (m_extend.active)
|
||||
return lay_state::extending;
|
||||
if (false == m_lay.points.empty())
|
||||
return lay_state::clicking;
|
||||
if (m_lay.laid_now && m_lay.laid_step == m_history.size())
|
||||
if (m_lay.laid_now && m_lay.laid_step == history_top())
|
||||
return lay_state::laid;
|
||||
return lay_state::ready;
|
||||
}
|
||||
|
||||
@@ -461,6 +461,18 @@ void editor_mode::model_run(std::vector<layout::command> Commands, model_context
|
||||
{
|
||||
std::vector<TTrack *> created;
|
||||
auto &session{model().session};
|
||||
// more than one: all of them tried on a copy first, one after another, so one refused leaves none of them carried out. Run one by one,
|
||||
// the radius of the first vertex stayed changed when the cant of the second was refused, under "Refused, nothing changed"
|
||||
if (Commands.size() > 1)
|
||||
{
|
||||
layout::model copy{session.network()};
|
||||
for (auto const &command : Commands)
|
||||
if (auto const outcome{copy.execute(command)}; false == outcome.done)
|
||||
{
|
||||
model_told(outcome, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (false == Commands.empty())
|
||||
{
|
||||
auto const &command{Commands.front()};
|
||||
@@ -1154,13 +1166,18 @@ bool editor_mode::model_delete(TTrack *Track)
|
||||
}
|
||||
if (Track->name().empty() || Track->name() == "none")
|
||||
return false;
|
||||
model_check_users({Track->name()}, [this, Track]() {
|
||||
// Shift as it was at the key press, not as it is at the click on "go on": Shift+Del of a double switch takes it all away
|
||||
auto const shift{Global.shiftState};
|
||||
model_check_users({Track->name()}, [this, Track, shift]() {
|
||||
if (Track->m_editorremoved)
|
||||
return;
|
||||
m_node = Track;
|
||||
ui()->set_node(m_node);
|
||||
m_model_delete_confirmed = true;
|
||||
auto const now{Global.shiftState};
|
||||
Global.shiftState = shift;
|
||||
delete_selected_track();
|
||||
Global.shiftState = now;
|
||||
m_model_delete_confirmed = false;
|
||||
});
|
||||
return true;
|
||||
|
||||
@@ -1085,7 +1085,7 @@ void editor_mode::nmt_area_terrain()
|
||||
WriteLog(std::string{"Editor: NMT - the terrain of the download area "} + (*Reason != '\0' ? std::string{"held: "} + Reason : std::string{"goes on"}), logtype::generic);
|
||||
}
|
||||
};
|
||||
if (false == area.run_only.value_or(EditorSettings.terrain_model().area))
|
||||
if (false == area.run_only.value_or(nmt_area()))
|
||||
return held("turned off");
|
||||
if (m_orthophoto.area().empty())
|
||||
return held("no area");
|
||||
@@ -1217,7 +1217,7 @@ void editor_mode::nmt_update()
|
||||
m_nmt_prefetched = wanted;
|
||||
// unless no terrain is made of the model by itself, as after the answer without terrain: what the terrain panel asks for then is
|
||||
// downloaded as it's asked for
|
||||
if (state.grow || EditorSettings.terrain_model().area)
|
||||
if (state.grow || nmt_area())
|
||||
m_nmt.prefetch(wanted);
|
||||
// the terrain around the camera looked at again within the new area
|
||||
m_area_terrain.listed = false;
|
||||
@@ -2142,13 +2142,18 @@ void editor_mode::render_download_area_ui(editor_orthophoto::statistics const &S
|
||||
}
|
||||
}
|
||||
auto &model{EditorSettings.terrain_model()};
|
||||
if (ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &model.area))
|
||||
// as it is for the scenery open: off after the answer Without terrain, and ticked, on again and kept so in the settings
|
||||
if (bool area{nmt_area()}; ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &area))
|
||||
{
|
||||
m_nmt_state.declined = false;
|
||||
model.area = area;
|
||||
EditorSettings.save();
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip("%s", STR_C("Makes the terrain from the terrain model within the area, around the camera wherever it goes,\n"
|
||||
"a chunk at a time while the editor is idle. The terrain there is already isn't touched.\n"
|
||||
"The chunks made wait in memory until the scenery is saved (Ctrl+S)."));
|
||||
if (model.area && m_area_terrain.made > 0)
|
||||
if (nmt_area() && m_area_terrain.made > 0)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("%s", format(STR_P("%zu chunk made", "%zu chunks made", m_area_terrain.made), m_area_terrain.made).c_str());
|
||||
@@ -2598,9 +2603,10 @@ void editor_mode::nmt_accept_offer()
|
||||
state.offset = 0.0;
|
||||
nmt_make(nmt_keys_around());
|
||||
state.prompt = false;
|
||||
// the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also after the other answer was
|
||||
// given for a scenery before; the model of the download area is put into the cache again if that answer stopped it
|
||||
// the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also where the settings had it
|
||||
// off; the model of the download area is put into the cache again if it was stopped
|
||||
state.grow = true;
|
||||
state.declined = false;
|
||||
EditorSettings.terrain_while_laying(true);
|
||||
EditorSettings.terrain_model().area = true;
|
||||
EditorSettings.save();
|
||||
@@ -2614,16 +2620,20 @@ void editor_mode::nmt_decline_offer()
|
||||
state.prompt = false;
|
||||
// nothing of the model loaded any more: not under the tracks as they're laid, as the checkbox of the layers turns it off, nor around
|
||||
// the camera within the download area, as the checkbox of the terrain panel does, nor the squares of the download area into the
|
||||
// cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log
|
||||
// cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log. For this scenery only:
|
||||
// the settings stay as they were, for the sceneries opened later
|
||||
state.grow = false;
|
||||
EditorSettings.terrain_while_laying(false);
|
||||
EditorSettings.terrain_model().area = false;
|
||||
EditorSettings.save();
|
||||
state.declined = true;
|
||||
m_nmt.prefetch({});
|
||||
// nor the squares asked for meanwhile, as the aerial photos asked for them to lie on
|
||||
m_nmt.cancel();
|
||||
}
|
||||
|
||||
bool editor_mode::nmt_area() const
|
||||
{
|
||||
return false == m_nmt_state.declined && EditorSettings.terrain_model().area;
|
||||
}
|
||||
|
||||
void editor_mode::render_nmt_prompt()
|
||||
{
|
||||
auto &state{m_nmt_state};
|
||||
|
||||
@@ -212,8 +212,24 @@ void norms_tool::forget(scene::basic_node const *Node)
|
||||
state.selected = -1;
|
||||
for (auto &line : state.lines)
|
||||
std::erase_if(line.entries, [Node](norms_report::entry const &Entry) { return Entry.track == Node; });
|
||||
for (auto &line : state.queue)
|
||||
std::erase_if(line.spans, [Node](norms_report::span const &Span) { return Span.track == Node; });
|
||||
// the span whose findings alone are kept moves down by the spans taken out before it; a line whose own span went has nothing left
|
||||
// to report
|
||||
auto const gone = [Node](norms_report::span const &Span) { return Span.track == Node; };
|
||||
auto line{state.queue.begin()};
|
||||
while (line != state.queue.end())
|
||||
{
|
||||
if (line->own >= 0 && line->own < static_cast<int>(line->spans.size()))
|
||||
{
|
||||
if (gone(line->spans[line->own]))
|
||||
{
|
||||
line = state.queue.erase(line);
|
||||
continue;
|
||||
}
|
||||
line->own -= static_cast<int>(std::count_if(line->spans.begin(), line->spans.begin() + line->own, gone));
|
||||
}
|
||||
std::erase_if(line->spans, gone);
|
||||
++line;
|
||||
}
|
||||
}
|
||||
|
||||
void norms_tool::render_class()
|
||||
|
||||
@@ -195,7 +195,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
|
||||
// to it out along their lines from the rim, against the model there
|
||||
// nmtstate logs how far the tracks going onto the terrain model are
|
||||
// nmtquestion <open|flat|restore> the question of the terrain of a new scenery opened, or answered without terrain as its card does;
|
||||
// restore: the settings of the terrain made by itself put back as they were before that answer
|
||||
// restore: the terrain made by itself as it was before that answer, which leaves the settings be
|
||||
// gradelines <file> the grade line each track shares written to the file, for a map of them
|
||||
// fitreport <file> to the file: the tracks off the terrain model, the switches off their plane, the rails on common timbers apart in height
|
||||
// gradeline <lift m|off|on|whole 0/1|state> the common grade line of the route open in the profile tool: its design lifted and applied, the route taken off it and back
|
||||
@@ -226,6 +226,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
|
||||
// expect joint <track> <start|end> <gap m> <angle deg> <cant step mm> the end of the first path against the end of another track
|
||||
// nearest to it within 1 m: the gap, the kink and the step of the cant between them, each at most
|
||||
// expect records <name> <count> [kind] the records of the switch store of the name, with the connections having the switch among theirs
|
||||
// expect shaped <switch> <yes|no> the switch keeps the shape its record says, or was bent out of it
|
||||
// expect speed <track> <km/h> [tolerance], expect gauge <track> <m> [tolerance] as editor_track::velocity gives it / the gauge
|
||||
// expect track <name> <present|removed>
|
||||
// expect route <track> <in|out> the track is a part of the line open in the route tool, or not
|
||||
@@ -280,8 +281,13 @@ void editor_mode::selftest_step()
|
||||
std::ifstream stream(file);
|
||||
std::string line;
|
||||
while (std::getline(stream, line))
|
||||
if (false == line.empty() && line.front() != '#')
|
||||
test.lines.push_back(line);
|
||||
{
|
||||
// an indented comment or a line of blanks is no command either
|
||||
auto const first{line.find_first_not_of(" \t\r")};
|
||||
if (first == std::string::npos || line[first] == '#')
|
||||
continue;
|
||||
test.lines.push_back(line.substr(first));
|
||||
}
|
||||
WriteLog("SELFTEST: " + std::to_string(test.lines.size()) + " steps from " + file);
|
||||
}
|
||||
++editor_selftest::frames();
|
||||
|
||||
@@ -51,6 +51,13 @@ inline std::size_t &failures()
|
||||
return count;
|
||||
}
|
||||
|
||||
// a command whose subject isn't there, a track name mistyped, fails the run as an expectation does
|
||||
inline void fail()
|
||||
{
|
||||
++expectations();
|
||||
++failures();
|
||||
}
|
||||
|
||||
// apart from the 1 of a start which failed or of an error which ended the editor
|
||||
inline constexpr int failed_exit_code{2};
|
||||
|
||||
|
||||
@@ -189,6 +189,24 @@ void expect_records(std::string const &What, std::istringstream &Words)
|
||||
expectation(count == wanted, What, std::to_string(count), std::to_string(wanted));
|
||||
}
|
||||
|
||||
// expect shaped <switch> <yes|no>: the switch keeps the shape its record says, or was bent out of it
|
||||
void expect_shaped(std::string const &What, std::istringstream &Words)
|
||||
{
|
||||
std::string name;
|
||||
std::string wanted;
|
||||
Words >> name >> wanted;
|
||||
if (malformed(What, Words))
|
||||
return;
|
||||
auto const *track{simulation::Paths.find(name)};
|
||||
if (track == nullptr || track->m_editorremoved)
|
||||
{
|
||||
expectation(false, What, "no track " + name, "a switch");
|
||||
return;
|
||||
}
|
||||
auto const shaped{switch_store::of(*track).has_value()};
|
||||
expectation(shaped == (wanted == "yes"), What, shaped ? "yes" : "no", wanted);
|
||||
}
|
||||
|
||||
// expect speed <track> <km/h> [tolerance], expect gauge <track> <m> [tolerance]
|
||||
void expect_track_value(std::string const &What, std::string const &Kind, std::istringstream &Words)
|
||||
{
|
||||
@@ -564,6 +582,8 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
|
||||
expect_joint(what, words, &editor_mode::cant_of_roll);
|
||||
else if (kind == "records")
|
||||
expect_records(what, words);
|
||||
else if (kind == "shaped")
|
||||
expect_shaped(what, words);
|
||||
else if (kind == "speed" || kind == "gauge")
|
||||
expect_track_value(what, kind, words);
|
||||
else if (kind == "track")
|
||||
@@ -585,14 +605,14 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
|
||||
else
|
||||
{
|
||||
shown_state shown{m_switch.status, ui()->refusal_shown(), ui()->status_line(), m_lay.mouse,
|
||||
{{"grow", m_nmt_state.grow}, {"area", EditorSettings.terrain_model().area}, {"prompt", m_nmt_state.prompt}}, tool_name(ui()->mode()),
|
||||
{{"grow", m_nmt_state.grow}, {"area", nmt_area()}, {"prompt", m_nmt_state.prompt}}, tool_name(ui()->mode()),
|
||||
{{"shortcuts", m_shortcuts_open}, {"settings", m_settings_open}, {"weather", m_environment_open}, {"orthophoto", m_orthophoto_window}}, std::nullopt,
|
||||
shown_lay_panel(), shown_switch_panel()};
|
||||
if (m_node != nullptr)
|
||||
shown.selected = m_node->location();
|
||||
if (false == expect_shown(kind, what, words, shown))
|
||||
expectation(false, what, "no expectation " + kind,
|
||||
"cant, joint, records, speed, gauge, track, route, norms, findings, height, lift, includes, status, statuslacks, refusal, statusline, laycursor, terrain, tool, window, "
|
||||
"cant, joint, records, shaped, speed, gauge, track, route, norms, findings, height, lift, includes, status, statuslacks, refusal, statusline, laycursor, terrain, tool, window, "
|
||||
"selected, laypanel, switchpanel or steps");
|
||||
}
|
||||
return selftest_result::handled;
|
||||
|
||||
@@ -513,26 +513,31 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co
|
||||
if (command == "nmtquestion")
|
||||
{
|
||||
// the question of the terrain of a new scenery: open, as the first L in an empty scenery opens it, or answered without
|
||||
// terrain, as its card does it; restore: the settings of the terrain made by itself as they were before the answer, which
|
||||
// keeps them with the editor
|
||||
// terrain, as its card does it; restore: the terrain made by itself as it was before the answer. The answer keeps to the
|
||||
// scenery open, so the settings of the tester aren't written
|
||||
std::string answer;
|
||||
words >> answer;
|
||||
auto &model{EditorSettings.terrain_model()};
|
||||
auto const &model{EditorSettings.terrain_model()};
|
||||
if (answer == "open")
|
||||
m_nmt_state.prompt = true;
|
||||
else if (answer == "flat")
|
||||
{
|
||||
m_selftest.terrain_kept = std::pair{m_nmt_state.grow, model.area};
|
||||
auto const kept{std::pair{EditorSettings.terrain_while_laying(), model.area}};
|
||||
m_selftest.terrain_kept = std::pair{m_nmt_state.grow, m_nmt_state.declined};
|
||||
nmt_decline_offer();
|
||||
// the settings as they were: the answer is for this scenery alone
|
||||
if (std::pair{EditorSettings.terrain_while_laying(), model.area} != kept)
|
||||
{
|
||||
editor_selftest::fail();
|
||||
WriteLog("SELFTEST FAIL nmtquestion flat: the settings of the terrain changed");
|
||||
}
|
||||
}
|
||||
else if (answer == "restore" && m_selftest.terrain_kept.has_value())
|
||||
{
|
||||
m_nmt_state.grow = m_selftest.terrain_kept->first;
|
||||
model.area = m_selftest.terrain_kept->second;
|
||||
EditorSettings.terrain_while_laying(m_nmt_state.grow);
|
||||
EditorSettings.save();
|
||||
m_nmt_state.declined = m_selftest.terrain_kept->second;
|
||||
}
|
||||
WriteLog(format("SELFTEST nmtquestion %s: prompt %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.grow ? 1 : 0, model.area ? 1 : 0));
|
||||
WriteLog(format("SELFTEST nmtquestion %s: prompt %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.grow ? 1 : 0, nmt_area() ? 1 : 0));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "nmtgrow")
|
||||
|
||||
@@ -404,8 +404,15 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm
|
||||
double gauge{1500.0};
|
||||
std::string name;
|
||||
words >> gauge >> name;
|
||||
auto *track{name.empty() ? nullptr : simulation::Paths.find(name)};
|
||||
if (false == name.empty() && (track == nullptr || track->m_editorremoved))
|
||||
{
|
||||
editor_selftest::fail();
|
||||
WriteLog("SELFTEST FAIL routegauge: no track " + name);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
// the line of the track opened in the route tool, as a click on it with the tool does, unless it's in the line open already
|
||||
if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved && std::ranges::find(m_route.chain.tracks, track) == m_route.chain.tracks.end())
|
||||
if (track != nullptr && std::ranges::find(m_route.chain.tracks, track) == m_route.chain.tracks.end())
|
||||
{
|
||||
m_track_tab = track_tab::route;
|
||||
m_route.single = false;
|
||||
@@ -426,7 +433,8 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm
|
||||
std::string reason;
|
||||
if (track == nullptr || track->m_editorremoved || index < 0 || index >= static_cast<int>(track->m_paths.size()) || false == editor_track::can_edit_geometry(*track, reason))
|
||||
{
|
||||
WriteLog("SELFTEST trackcant: no path " + name + " " + std::to_string(index) + " to edit " + reason);
|
||||
editor_selftest::fail();
|
||||
WriteLog("SELFTEST FAIL trackcant: no path " + name + " " + std::to_string(index) + " to edit " + reason);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
// as the field of the inspector takes it: the rolls of the path set, then the edit committed with the track as it was before
|
||||
|
||||
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "application/editormode.h"
|
||||
#include "application/editoruilayer.h"
|
||||
#include "application/editormodeselftest.h"
|
||||
#include "application/editormodeshared.h"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
@@ -2126,8 +2127,15 @@ editor_mode::selftest_result editor_mode::selftest_props(std::string const &Comm
|
||||
// the set made of the tracks, also of one, and the last of them selected, as the set stays the selection only with it
|
||||
m_track_set.clear();
|
||||
for (std::string name; Words >> name;)
|
||||
{
|
||||
if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved)
|
||||
{
|
||||
m_track_set.push_back(track);
|
||||
continue;
|
||||
}
|
||||
editor_selftest::fail();
|
||||
WriteLog("SELFTEST FAIL tracksetdelete: no track " + name);
|
||||
}
|
||||
m_node = m_track_set.empty() ? nullptr : m_track_set.back();
|
||||
m_track_point = {};
|
||||
ui()->set_node(m_node);
|
||||
|
||||
@@ -16,7 +16,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <type_traits>
|
||||
|
||||
namespace layout
|
||||
{
|
||||
@@ -25,6 +27,7 @@ namespace
|
||||
{
|
||||
|
||||
double constexpr kParallel{1e-9}; // rad: tangents within this run alike
|
||||
double constexpr kTouching{1e-6}; // m: a cut this close to the end of an element is at the end
|
||||
double constexpr kShortest{0.1}; // m: no part of a line split shorter; the simulation takes a path under 5 cm for one of no length
|
||||
|
||||
using reasons = std::vector<std::string>;
|
||||
@@ -305,13 +308,18 @@ reasons split_at(transaction &Change, line_id const Line, double const Chainage,
|
||||
auto const next{k + 1 == count ? geometry::plan_of(Change.view().find(original.end)->position) : vertices[k + 1].point};
|
||||
auto const in{glm::normalize(curve.point - previous)};
|
||||
auto const out{glm::normalize(next - curve.point)};
|
||||
if (std::abs(geometry::signed_angle(in, cut.heading)) <= kParallel && std::abs(cut.curvature) < 1e-12)
|
||||
// at the start or the end of the curve: where its transition leaves the straight, or at the tangent point of an arc with none,
|
||||
// whose curvature there is already the arc's
|
||||
auto const straight_there{std::abs(cut.curvature) < 1e-12};
|
||||
auto const arc_starts{e.role == element_role::arc && u < kTouching};
|
||||
auto const arc_ends{e.role == element_role::arc && u > e.length - kTouching};
|
||||
if (std::abs(geometry::signed_angle(in, cut.heading)) <= kParallel && (straight_there || arc_starts))
|
||||
{
|
||||
// right at the start of the curve
|
||||
take(0, k, before);
|
||||
take(k, count, after);
|
||||
}
|
||||
else if (std::abs(geometry::signed_angle(cut.heading, out)) <= kParallel && std::abs(cut.curvature) < 1e-12)
|
||||
else if (std::abs(geometry::signed_angle(cut.heading, out)) <= kParallel && (straight_there || arc_ends))
|
||||
{
|
||||
take(0, k + 1, before);
|
||||
take(k + 1, count, after);
|
||||
@@ -578,7 +586,7 @@ void hold_end(transaction &Change, node_id const Node, line_id const Line, line_
|
||||
|
||||
// a track the turnout lays itself, between the nodes, of the class of the line it lies on; a node of its own made where there's none yet,
|
||||
// holding the ends given
|
||||
void own_track(transaction &Change, line_id const Id, turnout_id const Turnout, node_id const From, node_id const To, line const &Like)
|
||||
void own_track(transaction &Change, line_id const Id, turnout const &Made, node_id const From, node_id const To, line const &Like)
|
||||
{
|
||||
auto const &view{Change.view()};
|
||||
if (view.find(Id) != nullptr)
|
||||
@@ -586,14 +594,16 @@ void own_track(transaction &Change, line_id const Id, turnout_id const Turnout,
|
||||
auto &track{Change.change(Id)};
|
||||
track.start = From;
|
||||
track.end = To;
|
||||
track.turnout = Turnout;
|
||||
track.turnout = Made.id;
|
||||
return;
|
||||
}
|
||||
line track;
|
||||
track.id = Id;
|
||||
track.turnout = Turnout;
|
||||
track.turnout = Made.id;
|
||||
track.start = From;
|
||||
track.end = To;
|
||||
// the kilometrage of the start of the turnout, as a diverging track has always had
|
||||
track.chainage_start = Made.chainage;
|
||||
track.category = Like.category;
|
||||
track.profile = Like.profile;
|
||||
track.shape.transition = Like.shape.transition;
|
||||
@@ -645,8 +655,8 @@ void add_own_tracks(transaction &Change, turnout const &Made, turnout_type const
|
||||
{
|
||||
case turnout_kind::twofold:
|
||||
{
|
||||
own_track(Change, Made.diverging, Made.id, Made.start, Made.diverging_end, Like);
|
||||
own_track(Change, Made.diverging2, Made.id, Made.second, Made.diverging2_end, Like);
|
||||
own_track(Change, Made.diverging, Made, Made.start, Made.diverging_end, Like);
|
||||
own_track(Change, Made.diverging2, Made, Made.second, Made.diverging2_end, Like);
|
||||
own_node(Change, Made.diverging_end, {{Made.diverging, line_end::end, 1}});
|
||||
own_node(Change, Made.diverging2_end, {{Made.diverging2, line_end::end, 1}});
|
||||
hold_end(Change, Made.start, Made.diverging, line_end::start, main_side);
|
||||
@@ -656,18 +666,18 @@ void add_own_tracks(transaction &Change, turnout const &Made, turnout_type const
|
||||
case turnout_kind::slip:
|
||||
case turnout_kind::crossing:
|
||||
{
|
||||
own_track(Change, Made.crossing, Made.id, Made.cross_start, Made.cross_end, Like);
|
||||
own_track(Change, Made.crossing, Made, Made.cross_start, Made.cross_end, Like);
|
||||
std::vector<end_ref> at_start{{Made.crossing, line_end::start, 1}};
|
||||
std::vector<end_ref> at_end{{Made.crossing, line_end::end, 1}};
|
||||
if (Type.slip_curves >= 1)
|
||||
{
|
||||
own_track(Change, Made.diverging, Made.id, Made.start, Made.cross_end, Like);
|
||||
own_track(Change, Made.diverging, Made, Made.start, Made.cross_end, Like);
|
||||
at_end.push_back({Made.diverging, line_end::end, 1});
|
||||
hold_end(Change, Made.start, Made.diverging, line_end::start, main_side);
|
||||
}
|
||||
if (Type.slip_curves >= 2)
|
||||
{
|
||||
own_track(Change, Made.diverging2, Made.id, Made.cross_start, Made.main_end, Like);
|
||||
own_track(Change, Made.diverging2, Made, Made.cross_start, Made.main_end, Like);
|
||||
at_start.push_back({Made.diverging2, line_end::start, 1});
|
||||
hold_end(Change, Made.main_end, Made.diverging2, line_end::end, side_at(view, Made.main, Made.main_end));
|
||||
}
|
||||
@@ -676,13 +686,13 @@ void add_own_tracks(transaction &Change, turnout const &Made, turnout_type const
|
||||
break;
|
||||
}
|
||||
case turnout_kind::symmetric:
|
||||
own_track(Change, Made.diverging, Made.id, Made.start, Made.diverging_end, Like);
|
||||
own_track(Change, Made.diverging, Made, Made.start, Made.diverging_end, Like);
|
||||
own_node(Change, Made.diverging_end, {{Made.diverging, line_end::end, 1}});
|
||||
hold_end(Change, Made.start, Made.diverging, line_end::start, main_side);
|
||||
break;
|
||||
case turnout_kind::ordinary:
|
||||
default:
|
||||
own_track(Change, Made.diverging, Made.id, Made.start, Made.diverging_end, Like);
|
||||
own_track(Change, Made.diverging, Made, Made.start, Made.diverging_end, Like);
|
||||
own_node(Change, Made.diverging_end, {{Made.diverging, line_end::end, 1}});
|
||||
hold_end(Change, Made.start, Made.diverging, line_end::start, main_side);
|
||||
break;
|
||||
@@ -751,7 +761,7 @@ reasons lay_symmetric(transaction &Change, outcome &Result, line const &Line, do
|
||||
made.main = given(Change, Ids.main);
|
||||
made.main_end = given(Change, Ids.main_end);
|
||||
own_ids(Change, made, Kind, Ids);
|
||||
own_track(Change, made.main, made.id, made.start, made.main_end, Line);
|
||||
own_track(Change, made.main, made, made.start, made.main_end, Line);
|
||||
own_node(Change, made.main_end, {{made.main, line_end::end, 1}});
|
||||
hold_end(Change, made.start, made.main, line_end::start, side);
|
||||
add_own_tracks(Change, made, Kind, Line);
|
||||
@@ -1342,8 +1352,10 @@ reasons join_curved(transaction &Change, outcome &Result, join_ends const &Comma
|
||||
bool fits{false};
|
||||
auto last{tangent(0.0, fits) - held};
|
||||
auto last_fits{fits};
|
||||
for (double free = 2.0; free <= 400.0; free += 2.0)
|
||||
for (int step{1}; step <= 200; ++step)
|
||||
{
|
||||
// every 2 m, as exact as the sum of the steps was
|
||||
auto const free{2.0 * step};
|
||||
auto const now{tangent(free, fits) - held};
|
||||
if (fits && last_fits && (now == 0.0 || (now < 0.0) != (last < 0.0)))
|
||||
{
|
||||
@@ -1387,7 +1399,8 @@ reasons propose(transaction &Change, outcome &Result, join_ends const &Command)
|
||||
return {"a line can't join a node to itself"};
|
||||
auto const from{free_end_at(view, Command.from, true, why)};
|
||||
auto const to{free_end_at(view, Command.to, false, why)};
|
||||
if (false == why.empty())
|
||||
// an end not found says why in Why
|
||||
if (false == from.has_value() || false == to.has_value())
|
||||
return why;
|
||||
auto const &neighbour{*view.find(from->held.line)};
|
||||
auto const category{neighbour.category};
|
||||
@@ -1544,6 +1557,39 @@ bool was_there(std::vector<notice> const &Earlier, notice const &Found)
|
||||
return std::ranges::any_of(Earlier, [&](notice const &Old) { return same_finding(Old, Found); });
|
||||
}
|
||||
|
||||
// the line whose vertices the command edits, which lays it anew in place: none for the other commands
|
||||
std::optional<line_id> reshaped(command const &Command)
|
||||
{
|
||||
return std::visit(
|
||||
[](auto const &Each) -> std::optional<line_id> {
|
||||
using kind = std::decay_t<decltype(Each)>;
|
||||
if constexpr (std::is_same_v<kind, move_vertex> || std::is_same_v<kind, set_vertex> || std::is_same_v<kind, insert_vertex> || std::is_same_v<kind, remove_vertex>)
|
||||
return Each.line;
|
||||
else
|
||||
return std::nullopt;
|
||||
},
|
||||
Command);
|
||||
}
|
||||
|
||||
// the joints of the old tracks of a line laid anew stay where they were on the ground: each at the point of the new line nearest to where it
|
||||
// was, in their order. Kept at their chainages, a curve made wider, which shortens the line, put a joint near its end past it, and the old
|
||||
// track there went with its name, events and isolated circuit
|
||||
void follow_joints(transaction &Change, line_id const Id, solved_line const &Before)
|
||||
{
|
||||
auto const *now{Change.view().find(Id)};
|
||||
if (now == nullptr || now->hard_splits.empty() || false == Before.valid() || false == now->solved.valid() || now->solved == Before)
|
||||
return;
|
||||
auto splits{now->hard_splits};
|
||||
double previous{0.0};
|
||||
for (auto &split : splits)
|
||||
{
|
||||
split.chainage = std::max(previous, now->solved.nearest(Before.position(std::clamp(split.chainage, 0.0, Before.length))));
|
||||
previous = split.chainage;
|
||||
}
|
||||
if (splits != now->hard_splits)
|
||||
Change.change(Id).hard_splits = std::move(splits);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
outcome model::execute(command const &Command, edit_policy const Policy)
|
||||
@@ -1553,11 +1599,18 @@ outcome model::execute(command const &Command, edit_policy const Policy)
|
||||
std::optional<network> earlier;
|
||||
if (Policy == edit_policy::no_new_block)
|
||||
earlier = m_network;
|
||||
// the line laid as it was, for its joints of old tracks to follow it
|
||||
auto const line{reshaped(Command)};
|
||||
std::optional<solved_line> before;
|
||||
if (auto const *shaped{line.has_value() ? m_network.find(*line) : nullptr}; shaped != nullptr && false == shaped->hard_splits.empty())
|
||||
before = shaped->solved;
|
||||
transaction change{m_network};
|
||||
auto why{std::visit([&](auto const &Each) { return propose(change, result, Each); }, Command)};
|
||||
if (why.empty())
|
||||
{
|
||||
settle(change);
|
||||
if (before.has_value())
|
||||
follow_joints(change, *line, *before);
|
||||
auto judged{check(m_network, change.touched_lines(), change.touched_nodes(), change.touched_turnouts())};
|
||||
if (earlier.has_value() && judged.reasons.empty() && false == judged.blocks.empty())
|
||||
{
|
||||
|
||||
@@ -35,26 +35,7 @@ int constexpr kIterations{40};
|
||||
// the nearest point of the line to the point of the plan: its chainage
|
||||
double nearest_on(solved_line const &Line, glm::dvec2 const &Point)
|
||||
{
|
||||
auto best{0.0};
|
||||
auto nearest{std::numeric_limits<double>::max()};
|
||||
auto const count{std::max(2, static_cast<int>(std::ceil(Line.length / 2.0)))};
|
||||
for (int i = 0; i <= count; ++i)
|
||||
{
|
||||
auto const s{Line.length * i / count};
|
||||
if (auto const d{glm::distance(Line.position(s), Point)}; d < nearest)
|
||||
{
|
||||
nearest = d;
|
||||
best = s;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
auto const shift{glm::dot(Point - Line.position(best), glm::normalize(Line.tangent(best)))};
|
||||
best = std::clamp(best + shift, 0.0, Line.length);
|
||||
if (std::abs(shift) < 1e-12)
|
||||
break;
|
||||
}
|
||||
return best;
|
||||
return Line.nearest(Point);
|
||||
}
|
||||
|
||||
// the end of the diverging track of the type laid on a straight from the origin along x: how far along, how far aside, its angle
|
||||
@@ -286,8 +267,10 @@ connection_plan plan_connection(network const &Network, connect_tracks const &Re
|
||||
// the spacing along the crossover: from the start of the first turnout as far as the start of the second one lies along the first line
|
||||
auto const reach{plan.straight * std::cos(std::abs(end.angle)) + 2.0 * end.along};
|
||||
plan.spacing_least = std::numeric_limits<double>::max();
|
||||
for (double s = 0.0; s <= reach + 1e-9; s += kStep)
|
||||
for (int step{0}; step * kStep <= reach + 1e-9; ++step)
|
||||
{
|
||||
// whole metres, as exact as the sum of the steps was
|
||||
auto const s{step * kStep};
|
||||
auto const station{std::clamp(s1 + Request.direction * s, 0.0, a.length)};
|
||||
auto const point{a.position(station)};
|
||||
auto const spacing{glm::distance(point, b.position(nearest_on(b, point)))};
|
||||
|
||||
@@ -13,8 +13,12 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "editor/editorGeometry.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace layout
|
||||
{
|
||||
@@ -412,10 +416,30 @@ class cutter
|
||||
std::map<std::string, int> m_counts;
|
||||
};
|
||||
|
||||
// the attributes of an old track without its events, for the pieces of its stretch which don't carry its name
|
||||
std::string without_events(std::string_view const Attributes)
|
||||
// which of the events of an old track a piece of its stretch takes (TTrack::m_events*, TrkFoll.cpp): event0 and eventall0, of a vehicle
|
||||
// standing on the track, each piece; event2 and eventall2, of one entering the track at its Point1, the piece at that end; event1 and
|
||||
// eventall1, entering it at its Point2, the piece at the other end
|
||||
struct piece_events
|
||||
{
|
||||
static constexpr std::array<std::string_view, 6> events{"event0", "event1", "event2", "eventall0", "eventall1", "eventall2"};
|
||||
bool standing{false};
|
||||
bool at_point1{false};
|
||||
bool at_point2{false};
|
||||
};
|
||||
|
||||
// the attributes of an old track with the events the piece takes; the keywords in any case, as the simulator lowers its tokens
|
||||
std::string attributes_of_piece(std::string_view const Attributes, piece_events const Kept)
|
||||
{
|
||||
auto const kept = [Kept](std::string_view const Word) -> std::optional<bool> {
|
||||
std::string lower;
|
||||
std::ranges::transform(Word, std::back_inserter(lower), [](char const C) { return static_cast<char>(std::tolower(static_cast<unsigned char>(C))); });
|
||||
if (lower == "event0" || lower == "eventall0")
|
||||
return Kept.standing;
|
||||
if (lower == "event2" || lower == "eventall2")
|
||||
return Kept.at_point1;
|
||||
if (lower == "event1" || lower == "eventall1")
|
||||
return Kept.at_point2;
|
||||
return std::nullopt;
|
||||
};
|
||||
std::string result;
|
||||
std::size_t at{0};
|
||||
bool skip{false};
|
||||
@@ -427,16 +451,23 @@ std::string without_events(std::string_view const Attributes)
|
||||
auto const end{std::min(Attributes.find(' ', start), Attributes.size())};
|
||||
auto const word{Attributes.substr(start, end - start)};
|
||||
at = end;
|
||||
auto const event{kept(word)};
|
||||
if (skip)
|
||||
skip = false;
|
||||
else if (std::ranges::find(events, word) != events.end())
|
||||
skip = true;
|
||||
else if (event.has_value() && false == *event)
|
||||
skip = true; // the event and its name after it
|
||||
else
|
||||
result += (result.empty() ? "" : " ") + std::string{word};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// the attributes of an old track without its events, for a part of it a split cut off
|
||||
std::string without_events(std::string_view const Attributes)
|
||||
{
|
||||
return attributes_of_piece(Attributes, {});
|
||||
}
|
||||
|
||||
// the pieces of the stretches of the old tracks named and written as each old track was: its name on the piece it ran into first, with
|
||||
// its events, <name>_2... on the others, its surface and its attributes, the path the way it ran; a piece out of any stretch as the generator
|
||||
// names and writes it
|
||||
@@ -457,15 +488,17 @@ void keep_old_tracks(line const &Line, std::vector<generated_piece> &Pieces, gen
|
||||
if (stretch < splits.size())
|
||||
{
|
||||
auto const &old{splits[stretch].track};
|
||||
auto const count{last - first};
|
||||
for (auto i = first; i < last; ++i)
|
||||
{
|
||||
auto &piece{Pieces[i]};
|
||||
// 0 at the Point1 of the old track
|
||||
auto const order{old.reversed ? last - 1 - i : i - first};
|
||||
if (false == old.name.empty() && false == old.continued)
|
||||
piece.name = order == 0 ? old.name : std::format("{}_{}", old.name, order + 1);
|
||||
if (old.reversed)
|
||||
piece.path = geometry::reversed(piece.path);
|
||||
auto attributes{order == 0 && false == old.continued ? old.attributes : without_events(old.attributes)};
|
||||
auto attributes{old.continued ? without_events(old.attributes) : attributes_of_piece(old.attributes, {true, order == 0, order + 1 == count})};
|
||||
if (old.attributes.empty())
|
||||
attributes = std::format("velocity {}", number_text(Line.category.vmax));
|
||||
piece.text = entry_text(piece, old.surface.empty() ? Options.surface : old.surface, attributes);
|
||||
@@ -479,6 +512,9 @@ void keep_old_tracks(line const &Line, std::vector<generated_piece> &Pieces, gen
|
||||
// one curve between their headings, the sharpest radius of them
|
||||
segment_data whole_path(std::vector<generated_piece> const &Pieces)
|
||||
{
|
||||
// a track the cutter gave no pieces of, its errors told: no path
|
||||
if (Pieces.empty())
|
||||
return {};
|
||||
if (Pieces.size() == 1)
|
||||
return Pieces.front().path;
|
||||
segment_data result;
|
||||
|
||||
@@ -217,6 +217,30 @@ glm::dvec3 solved_line::point(double const Chainage) const
|
||||
return {plan.x, elevation(Chainage), plan.y};
|
||||
}
|
||||
|
||||
double solved_line::nearest(glm::dvec2 const &Point) const
|
||||
{
|
||||
auto best{0.0};
|
||||
auto closest{std::numeric_limits<double>::max()};
|
||||
auto const count{std::max(2, static_cast<int>(std::ceil(length / 2.0)))};
|
||||
for (int i = 0; i <= count; ++i)
|
||||
{
|
||||
auto const s{length * i / count};
|
||||
if (auto const d{glm::distance(position(s), Point)}; d < closest)
|
||||
{
|
||||
closest = d;
|
||||
best = s;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
auto const shift{glm::dot(Point - position(best), glm::normalize(tangent(best)))};
|
||||
best = std::clamp(best + shift, 0.0, length);
|
||||
if (std::abs(shift) < 1e-12)
|
||||
break;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
solved_line solve(line_shape const &Shape, end_condition const &Start, end_condition const &End)
|
||||
{
|
||||
solved_line result;
|
||||
@@ -464,6 +488,7 @@ norms::line described(solved_line const &Line, norms::line_class const &Class, s
|
||||
element.length = e.length;
|
||||
element.curvature_start = e.curvature(0.0);
|
||||
element.curvature_end = e.curvature(e.length);
|
||||
element.bloss = e.kind == element_kind::bloss;
|
||||
element.speed = Class.vmax;
|
||||
auto const from{e.position(0.0)};
|
||||
auto const to{e.position(e.length)};
|
||||
|
||||
@@ -163,6 +163,8 @@ struct solved_line
|
||||
double elevation(double const Chainage) const;
|
||||
double grade(double const Chainage) const;
|
||||
glm::dvec3 point(double const Chainage) const;
|
||||
// the chainage of the point of the line nearest to the point of the plan
|
||||
double nearest(glm::dvec2 const &Point) const;
|
||||
};
|
||||
|
||||
// the line laid between the end conditions; the vertices and the breaks as given, the ends from the nodes
|
||||
|
||||
@@ -156,7 +156,8 @@ norms::element reversed(norms::element Element, double const Length)
|
||||
// the elements run on alike: the same kind, the curvature going on as it did
|
||||
bool runs_on(norms::element const &A, norms::element const &B)
|
||||
{
|
||||
if (A.kind != B.kind || std::abs(A.curvature_end - B.curvature_start) > kCurvature || A.speed != B.speed || A.features != B.features)
|
||||
// two halves of Bloss curves make no Bloss curve
|
||||
if (A.kind != B.kind || A.bloss || B.bloss || std::abs(A.curvature_end - B.curvature_start) > kCurvature || A.speed != B.speed || A.features != B.features)
|
||||
return false;
|
||||
if (A.kind != norms::element_kind::transition)
|
||||
return std::abs(A.curvature_start - B.curvature_end) <= kCurvature;
|
||||
@@ -494,6 +495,8 @@ std::vector<chain_part> chain_of(network const &Network, line_id const Line)
|
||||
{
|
||||
auto const &last{result.back()};
|
||||
auto const *owner{Network.find(last.line)};
|
||||
if (owner == nullptr)
|
||||
break;
|
||||
auto const beyond{last.forward ? line_end::end : line_end::start};
|
||||
auto const *other{across(owner->node_at(beyond), last.line, beyond)};
|
||||
if (other == nullptr || contains(other->line) || Network.find(other->line) == nullptr)
|
||||
@@ -505,6 +508,8 @@ std::vector<chain_part> chain_of(network const &Network, line_id const Line)
|
||||
{
|
||||
auto const &head{result.front()};
|
||||
auto const *owner{Network.find(head.line)};
|
||||
if (owner == nullptr)
|
||||
break;
|
||||
auto const behind{head.forward ? line_end::start : line_end::end};
|
||||
auto const *other{across(owner->node_at(behind), head.line, behind)};
|
||||
if (other == nullptr || contains(other->line) || Network.find(other->line) == nullptr)
|
||||
@@ -520,7 +525,12 @@ described_chain describe_chain(network const &Network, std::vector<chain_part> c
|
||||
double offset{0.0};
|
||||
for (auto const &part : Chain)
|
||||
{
|
||||
auto const &owner{*Network.find(part.line)};
|
||||
// the chain is made of the lines of the network: one gone is a chain out of date, of which the rest is described
|
||||
auto const *found{Network.find(part.line)};
|
||||
result.starts.push_back(offset);
|
||||
if (found == nullptr)
|
||||
continue;
|
||||
auto const &owner{*found};
|
||||
auto own{described(owner.solved, owner.category)};
|
||||
auto const length{owner.solved.length};
|
||||
// a line of a connection of the tracks, the track between the turnouts of a crossover, is judged as their tracks are
|
||||
@@ -543,7 +553,6 @@ described_chain describe_chain(network const &Network, std::vector<chain_part> c
|
||||
element.speed = std::min(element.speed > 0.0 ? element.speed : speed, speed);
|
||||
}
|
||||
}
|
||||
result.starts.push_back(offset);
|
||||
if (false == part.forward)
|
||||
{
|
||||
for (auto &element : own.elements)
|
||||
@@ -676,7 +685,12 @@ void check_node(network const &Network, node const &Node, verdict &Result)
|
||||
continue;
|
||||
}
|
||||
auto const *switched{owner_of(Network, end.line)};
|
||||
auto const carrying = [&](bool const SameSide) {
|
||||
if (switched == nullptr)
|
||||
{
|
||||
ends.push_back(end);
|
||||
continue;
|
||||
}
|
||||
auto const carrying = [&Network, &Node, &end, switched](bool const SameSide) {
|
||||
return std::ranges::any_of(Node.ends, [&](end_ref const &Each) {
|
||||
auto const *owner{owner_of(Network, Each.line)};
|
||||
return owner != nullptr && owner->id == switched->id && false == branch_end(Network, Each) && (Each.side() == end.side()) == SameSide;
|
||||
@@ -733,12 +747,13 @@ void check_norms(network const &Network, std::set<line_id> const &Lines, verdict
|
||||
for (auto const &part : chain)
|
||||
{
|
||||
done.insert(part.line);
|
||||
laid = laid && Network.find(part.line)->solved.valid();
|
||||
auto const *line{Network.find(part.line)};
|
||||
laid = laid && line != nullptr && line->solved.valid();
|
||||
}
|
||||
if (false == laid)
|
||||
continue;
|
||||
auto const described{describe_chain(Network, chain)};
|
||||
auto const &first{*Network.find(chain.front().line)};
|
||||
auto const &first{*Network.find(chain.front().line)}; // NOSONAR: every line of the chain was found just above
|
||||
// the profile of the lines' own wins over the areas: the lines of a chain have the same
|
||||
auto areas{Network.areas};
|
||||
if (first.profile.has_value())
|
||||
@@ -750,7 +765,7 @@ void check_norms(network const &Network, std::set<line_id> const &Lines, verdict
|
||||
// the line it's on, by the chainage along the chain
|
||||
auto part{static_cast<std::size_t>(std::upper_bound(described.starts.begin(), described.starts.end(), finding.chainage + 1e-9) - described.starts.begin())};
|
||||
part = part > 0 ? part - 1 : 0;
|
||||
auto const &owner{*Network.find(chain[part].line)};
|
||||
auto const &owner{*Network.find(chain[part].line)}; // NOSONAR: every line of the chain was found just above
|
||||
auto const along{finding.chainage - described.starts[part]};
|
||||
auto const chainage{chain[part].forward ? along : owner.solved.length - along};
|
||||
auto const text{finding_text(finding)};
|
||||
@@ -760,7 +775,7 @@ void check_norms(network const &Network, std::set<line_id> const &Lines, verdict
|
||||
auto const position_at = [&](double const At) {
|
||||
auto index{static_cast<std::size_t>(std::upper_bound(described.starts.begin(), described.starts.end(), At + 1e-9) - described.starts.begin())};
|
||||
index = index > 0 ? index - 1 : 0;
|
||||
auto const &line{Network.find(chain[index].line)->solved};
|
||||
auto const &line{Network.find(chain[index].line)->solved}; // NOSONAR: every line of the chain was found above
|
||||
auto const local{At - described.starts[index]};
|
||||
return line.position(std::clamp(chain[index].forward ? local : line.length - local, 0.0, line.length));
|
||||
};
|
||||
@@ -810,13 +825,15 @@ verdict check(network const &Network, std::set<line_id> const &Lines, std::set<n
|
||||
}
|
||||
// the lines of the turnouts touched are judged with them
|
||||
std::set<line_id> lines{Lines};
|
||||
// the turnouts are the owners of lines found in the network
|
||||
std::erase_if(turnouts, [&Network](turnout_id const Id) { return Network.find(Id) == nullptr; });
|
||||
for (auto const id : turnouts)
|
||||
for (auto const track : tracks_of(*Network.find(id)))
|
||||
for (auto const track : tracks_of(*Network.find(id))) // NOSONAR: the turnouts not found were taken out above
|
||||
lines.insert(track);
|
||||
if (false == result.reasons.empty())
|
||||
return result;
|
||||
for (auto const id : turnouts)
|
||||
check_turnout(Network, *Network.find(id), result);
|
||||
check_turnout(Network, *Network.find(id), result); // NOSONAR: the turnouts not found were taken out above
|
||||
if (result.reasons.empty())
|
||||
check_norms(Network, lines, result);
|
||||
return result;
|
||||
|
||||
@@ -431,7 +431,7 @@ solved_line lay_on_transition(turnout_frame const &Frame, turnout_type const &Ty
|
||||
k1 = bent(basic_at(reached), main1);
|
||||
auto const rate1{k1 - main1 * std::cos(off)};
|
||||
turned = 0.5 * (rate0 + rate1) * ds;
|
||||
if (false == last && std::abs(made + turned) <= std::abs(turn))
|
||||
if ((false == last && std::abs(made + turned) <= std::abs(turn)) || std::abs(turned) < 1e-15)
|
||||
break;
|
||||
ds *= (turn - made) / turned;
|
||||
}
|
||||
@@ -683,6 +683,13 @@ solved_line lay_diverging(turnout_frame const &Frame, turnout_type const &Type,
|
||||
if (Frame.varying)
|
||||
return lay_on_transition(Frame, Type, Hand);
|
||||
solved_line result;
|
||||
// the main track not laid: no place to lay the diverging one from, which would otherwise start at the origin and take its end
|
||||
// node there
|
||||
if (false == Frame.valid)
|
||||
{
|
||||
result.errors.push_back(std::format("{}: the main track isn't laid, so the diverging track has nowhere to start", Type.name));
|
||||
return result;
|
||||
}
|
||||
auto const curvature{Frame.curvature};
|
||||
auto const bending{bending_of(curvature, Hand)};
|
||||
auto const hand{static_cast<double>(Hand)};
|
||||
|
||||
@@ -207,7 +207,8 @@ enum class element_kind
|
||||
arc
|
||||
};
|
||||
|
||||
// an element of the line in the plan: the curvature changes evenly along it from its start to its end, signed, positive turning left
|
||||
// an element of the line in the plan: the curvature changes evenly along it from its start to its end (or as a Bloss curve does),
|
||||
// signed, positive turning left
|
||||
struct element
|
||||
{
|
||||
element_kind kind{element_kind::straight};
|
||||
@@ -215,6 +216,9 @@ struct element
|
||||
double length{0.0};
|
||||
double curvature_start{0.0}; // 1/m
|
||||
double curvature_end{0.0};
|
||||
// a transition whose curvature follows the Bloss curve, 3t^2 - 2t^3 of the change: gentle at its ends, 1.5 times as fast as an
|
||||
// even one in its middle, the arc moved in by L^2 / 40R instead of L^2 / 24R
|
||||
bool bloss{false};
|
||||
double speed{0.0}; // km/h, the highest on it; 0: the one of the line class
|
||||
unsigned features{0}; // switch_track, movable_frog, curved_switch, crossing, expansion, diverging, platform, station
|
||||
// the element is cut by the end of the line or by a switch: its length isn't its own
|
||||
|
||||
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "editor/norms/norms.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
|
||||
@@ -27,6 +28,7 @@ namespace
|
||||
|
||||
double constexpr kC{11.8};
|
||||
double constexpr kSame{1e-6}; // m: points closer along the line are one
|
||||
int constexpr kBlossPieces{8}; // a Bloss transition seen as this many pieces, as the cant ramps of the same shape are
|
||||
double constexpr kCurve{1.0 / 50000.0}; // 1/m: a curve, not a straight
|
||||
double constexpr kJumpCurvature{1e-6}; // 1/m
|
||||
double constexpr kStep{0.5}; // mm: a smaller step of the cant isn't one
|
||||
@@ -85,7 +87,8 @@ double curvature_at(element const &Element, double const Chainage)
|
||||
{
|
||||
if (Element.length <= kSame)
|
||||
return Element.curvature_end;
|
||||
return std::lerp(Element.curvature_start, Element.curvature_end, std::clamp((Chainage - Element.start) / Element.length, 0.0, 1.0));
|
||||
auto const t{std::clamp((Chainage - Element.start) / Element.length, 0.0, 1.0)};
|
||||
return std::lerp(Element.curvature_start, Element.curvature_end, Element.bloss ? t * t * (3.0 - 2.0 * t) : t);
|
||||
}
|
||||
|
||||
// a point inside an element where the curvature and the cant are known from inside it
|
||||
@@ -191,6 +194,16 @@ class checker
|
||||
continue;
|
||||
result.push_back({point.chainage, curvature_at(Element, point.chainage), point.cant});
|
||||
}
|
||||
// the curvature of a Bloss curve doesn't change evenly: eight pieces of it, for its steeper middle to be seen
|
||||
if (Element.bloss)
|
||||
{
|
||||
for (int i = 1; i < kBlossPieces; ++i)
|
||||
{
|
||||
auto const chainage{Element.start + Element.length * i / kBlossPieces};
|
||||
result.push_back({chainage, curvature_at(Element, chainage), cant_at(m_line.cant, chainage, true)});
|
||||
}
|
||||
std::ranges::sort(result, {}, &station::chainage);
|
||||
}
|
||||
result.push_back({end, Element.curvature_end, cant_at(m_line.cant, end, false)});
|
||||
return result;
|
||||
}
|
||||
@@ -290,8 +303,9 @@ class checker
|
||||
if (element.kind == element_kind::transition)
|
||||
{
|
||||
check(parameter::transition_length, element.length, Index, Here, element.start, element.length);
|
||||
// the arc moved in by a cubic parabola or a clothoid: L^2 / 24 times the change of the curvature (ST-T1-A6 tab. 9.11)
|
||||
auto const shift{element.length * element.length * std::abs(element.curvature_end - element.curvature_start) / 24.0};
|
||||
// the arc moved in by a cubic parabola or a clothoid: L^2 / 24 times the change of the curvature (ST-T1-A6 tab. 9.11), by a
|
||||
// Bloss curve L^2 / 40
|
||||
auto const shift{element.length * element.length * std::abs(element.curvature_end - element.curvature_start) / (element.bloss ? 40.0 : 24.0)};
|
||||
check(parameter::transition_shift, shift, Index, Here, element.start, element.length);
|
||||
return;
|
||||
}
|
||||
@@ -374,15 +388,22 @@ class checker
|
||||
return result;
|
||||
}
|
||||
|
||||
// the shortest element between two jumps for them to be taken apart: the longest the profiles of the element between them ask for
|
||||
// the shortest element between two jumps for them to be taken apart: the longest the profiles of the element between them ask for.
|
||||
// TSI INF and EN 13803 limit the jump but say nothing of jumps close together, so with only them there the longest any profile
|
||||
// asks for is taken: otherwise two jumps a metre apart would each pass a limit their sum breaks
|
||||
double intermediate(std::size_t const Index, double const Speed) const
|
||||
{
|
||||
auto const &element{m_line.elements[Index]};
|
||||
double result{0.0};
|
||||
for (auto const profile : profiles(element))
|
||||
if (auto const bound{limits(profile, parameter::intermediate_length, where(element, Speed, 0.0)).block})
|
||||
result = std::max(result, bound->value);
|
||||
return result;
|
||||
auto const longest = [this, &element, Speed](auto const &Profiles) {
|
||||
double result{0.0};
|
||||
for (auto const profile : Profiles)
|
||||
if (auto const bound{limits(profile, parameter::intermediate_length, where(element, Speed, 0.0)).block})
|
||||
result = std::max(result, bound->value);
|
||||
return result;
|
||||
};
|
||||
if (auto const own{longest(profiles(element))}; own > 0.0)
|
||||
return own;
|
||||
return longest(std::array{profile_id::plk, profile_id::tsi, profile_id::en13803, profile_id::ch});
|
||||
}
|
||||
|
||||
// ST-T1-A6 9.11 pkt 8 - 13: the jumps closer than the intermediate length, changing the cant deficiency the same way, are taken
|
||||
|
||||
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
@@ -30,6 +31,13 @@ namespace
|
||||
using layout::line_id;
|
||||
using layout::node_id;
|
||||
using layout::turnout_id;
|
||||
|
||||
// the path for a message, as UTF-8: generic_string() throws on Windows for a name the code page can't hold
|
||||
std::string shown(std::filesystem::path const &Path)
|
||||
{
|
||||
auto const text{Path.generic_u8string()};
|
||||
return std::string(text.begin(), text.end());
|
||||
}
|
||||
using layout::vertex_id;
|
||||
|
||||
// the shortest form which reads back to the same double
|
||||
@@ -170,6 +178,14 @@ class record
|
||||
fail(std::format("{} {} is out of range", What, value));
|
||||
return static_cast<std::uint32_t>(value);
|
||||
}
|
||||
// the identifier handed out last, of the next one written: they start at 1, so 0 would wrap around
|
||||
std::uint32_t next_id(std::string_view const What)
|
||||
{
|
||||
auto const value{id(What)};
|
||||
if (false == failed() && value == 0u)
|
||||
fail(std::format("{} 0: the identifiers start at 1", What));
|
||||
return value > 0u ? value - 1u : 0u;
|
||||
}
|
||||
// one of the names, the index of it
|
||||
template <std::size_t Count>
|
||||
std::size_t choice(std::string_view const What, std::array<std::string_view, Count> const &Names)
|
||||
@@ -754,13 +770,13 @@ read_result read(std::string_view const Text)
|
||||
{
|
||||
layout::network::handed_out last;
|
||||
words.expect("node");
|
||||
last.node = words.id("the next node") - 1u;
|
||||
last.node = words.next_id("the next node");
|
||||
words.expect("line");
|
||||
last.line = words.id("the next line") - 1u;
|
||||
last.line = words.next_id("the next line");
|
||||
words.expect("vertex");
|
||||
last.vertex = words.id("the next vertex") - 1u;
|
||||
last.vertex = words.next_id("the next vertex");
|
||||
words.expect("turnout");
|
||||
last.turnout = words.id("the next turnout") - 1u;
|
||||
last.turnout = words.next_id("the next turnout");
|
||||
words.finish();
|
||||
next = last;
|
||||
}
|
||||
@@ -1034,7 +1050,7 @@ read_result load(std::filesystem::path const &Path)
|
||||
if (false == file.is_open())
|
||||
{
|
||||
read_result result;
|
||||
result.error = "there's no project file " + Path.generic_string();
|
||||
result.error = "there's no project file " + shown(Path);
|
||||
return result;
|
||||
}
|
||||
std::string const text{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
@@ -1050,13 +1066,18 @@ bool save(document const &Project, std::filesystem::path const &Path, std::strin
|
||||
std::ofstream file{temporary, std::ios::binary | std::ios::trunc};
|
||||
if (false == file.is_open())
|
||||
{
|
||||
Error = "can't write " + temporary.generic_string();
|
||||
Error = "can't write " + shown(temporary);
|
||||
return false;
|
||||
}
|
||||
file.write(text.data(), static_cast<std::streamsize>(text.size()));
|
||||
if (false == file.good())
|
||||
// closed before it's looked at: the last of the text is written by the flush of the close, and a file cut short there must not
|
||||
// take the place of the project
|
||||
file.close();
|
||||
if (file.fail())
|
||||
{
|
||||
Error = "can't write " + temporary.generic_string();
|
||||
Error = "can't write " + shown(temporary);
|
||||
std::error_code ignored;
|
||||
std::filesystem::remove(temporary, ignored);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1064,7 +1085,7 @@ bool save(document const &Project, std::filesystem::path const &Path, std::strin
|
||||
std::filesystem::rename(temporary, Path, error);
|
||||
if (error)
|
||||
{
|
||||
Error = "can't put " + temporary.generic_string() + " in the place of the project file: " + error.message();
|
||||
Error = "can't put " + shown(temporary) + " in the place of the project file: " + error.message();
|
||||
std::filesystem::remove(temporary, error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,21 +137,34 @@ struct switch_block
|
||||
double constexpr kOnLine{0.01}; // m: the start of a switch lies on a line within this
|
||||
double constexpr kAlong{1e-3}; // of the sine: its direction runs along the line within this
|
||||
|
||||
// the type of the catalogue the switch of the editor is of: its kind, type, rail, radius, ratio and a (and b of an ordinary one) as its record
|
||||
// gives them, the first of them in the order of the catalogue; empty where none is
|
||||
std::string catalogue_type(switch_store::record const &Record)
|
||||
// the entry of the catalogue is of the type, rail, radius, ratio and a (and b of an ordinary one) the record gives. A switch bent into a
|
||||
// curve is written as Rlj or Rld (switch_store::classify) with the radius of the ordinary switch it's bent from, an Rz of the catalogue
|
||||
bool same_type(switch_design::design const &Entry, switch_store::record const &Record)
|
||||
{
|
||||
auto const kind{Record.type == "Rlj" || Record.type == "Rld" ? std::string_view{"Rz"} : std::string_view{Record.type}};
|
||||
if (Entry.type != kind || Entry.rail != Record.rail || std::abs(Entry.ratio - Record.ratio) > 0.01 || std::abs(Entry.a - Record.a) > 0.002)
|
||||
return false;
|
||||
if (Entry.type != "Skrz" && std::abs(Entry.radius - Record.radius) > 0.5)
|
||||
return false;
|
||||
return (Entry.type != "Rz" && Entry.type != "Rls") || std::abs(Entry.b - Record.b) <= 0.002;
|
||||
}
|
||||
|
||||
// the type of the catalogue the switch of the editor is of; empty where none is, or where the record fits more than one, Why told then.
|
||||
// A frog with a movable nose isn't in the record: the ordinary frog is taken where the catalogue has both
|
||||
std::string catalogue_type(switch_store::record const &Record, std::string &Why)
|
||||
{
|
||||
std::vector<switch_design::design const *> found;
|
||||
for (auto const &entry : switch_design::catalogue_entries())
|
||||
if (same_type(entry, Record))
|
||||
found.push_back(&entry);
|
||||
if (std::ranges::any_of(found, [](switch_design::design const *Entry) { return false == Entry->movable; }))
|
||||
std::erase_if(found, [](switch_design::design const *Entry) { return Entry->movable; });
|
||||
if (found.size() > 1)
|
||||
{
|
||||
if (entry.type != Record.type || entry.rail != Record.rail || std::abs(entry.ratio - Record.ratio) > 0.01 || std::abs(entry.a - Record.a) > 0.002)
|
||||
continue;
|
||||
if (entry.type != "Skrz" && std::abs(entry.radius - Record.radius) > 0.5)
|
||||
continue;
|
||||
if ((entry.type == "Rz" || entry.type == "Rls") && std::abs(entry.b - Record.b) > 0.002)
|
||||
continue;
|
||||
return entry.name;
|
||||
Why = std::format("{} fits {} types of the catalogue, {} and {}, which the record doesn't tell apart", Record.type, found.size(), found[0]->name, found[1]->name);
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
return found.empty() ? std::string{} : found.front()->name;
|
||||
}
|
||||
|
||||
// the line of its own the switch starts on, along it or against it: its chainage there
|
||||
@@ -203,7 +216,14 @@ layout::line_id switch_turnout(layout::network &Network, switch_store::record co
|
||||
Why = "its outer track lifted, which the domain has no place for";
|
||||
return layout::line_id::none;
|
||||
}
|
||||
auto const type{catalogue_type(Record)};
|
||||
if (Record.kind == "slip" || Record.kind == "crossing")
|
||||
{
|
||||
Why = std::format("a {}, whose record doesn't tell the side of its crossing track", Record.kind);
|
||||
return layout::line_id::none;
|
||||
}
|
||||
auto const type{catalogue_type(Record, Why)};
|
||||
if (false == Why.empty())
|
||||
return layout::line_id::none;
|
||||
if (type.empty())
|
||||
{
|
||||
Why = std::format("no {} of the catalogue of {} R {:.0f} 1:{:.3f} a {:.3f} b {:.3f}", Record.type, Record.rail, Record.radius, Record.ratio, Record.a, Record.b);
|
||||
@@ -222,7 +242,13 @@ layout::line_id switch_turnout(layout::network &Network, switch_store::record co
|
||||
}
|
||||
// bent as its record says, the line under it bent so
|
||||
auto const *line{Network.find(place->line)};
|
||||
auto const length{layout::turnout_type_of(type)->length};
|
||||
auto const catalogued{layout::turnout_type_of(type)};
|
||||
if (line == nullptr || false == catalogued.has_value())
|
||||
{
|
||||
Why = std::format("{}: not a type the domain lays", type);
|
||||
return layout::line_id::none;
|
||||
}
|
||||
auto const length{catalogued->length};
|
||||
auto const curvature{std::abs(line->solved.curvature(std::clamp(place->chainage + place->direction * 0.5 * length, 0.0, line->solved.length)))};
|
||||
if ((Record.main_radius == 0.0) != (curvature < 1e-6) || (Record.main_radius != 0.0 && std::abs(1.0 / curvature - std::abs(Record.main_radius)) > 0.05 * std::abs(Record.main_radius)))
|
||||
{
|
||||
@@ -230,7 +256,9 @@ layout::line_id switch_turnout(layout::network &Network, switch_store::record co
|
||||
return layout::line_id::none;
|
||||
}
|
||||
layout::model model{Network};
|
||||
auto const made{model.execute(layout::insert_turnout{place->line, place->chainage, type, Record.hand == 'L' ? 1 : -1, place->direction}, layout::edit_policy::no_new_block)};
|
||||
// the store writes R where the diverging end lies to the positive cross of the direction (switch_store::classify), the side of
|
||||
// hand 1 of the domain, whose curvature above 0 turns that way
|
||||
auto const made{model.execute(layout::insert_turnout{place->line, place->chainage, type, Record.hand == 'R' ? 1 : -1, place->direction}, layout::edit_policy::no_new_block)};
|
||||
if (false == made.done)
|
||||
{
|
||||
Why = type + ":";
|
||||
@@ -670,9 +698,8 @@ std::vector<marked_file> marked_files(std::filesystem::path const &Folder, std::
|
||||
// the templates (*.inc) are a part of the layer including them, their own lines are the descriptions (//$e)
|
||||
if (scenery_text::lowered(file.name).ends_with(".inc"))
|
||||
continue;
|
||||
std::ifstream input{Folder / file.name, std::ios::binary};
|
||||
std::string const text{std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()};
|
||||
auto lines{marked_lines(text)};
|
||||
auto const text{scenery_text::file_text(Folder / file.name)};
|
||||
auto lines{marked_lines(text.value_or(std::string{}))};
|
||||
if (lines.empty())
|
||||
continue;
|
||||
result.push_back({file.name, file.context, std::move(lines)});
|
||||
@@ -684,13 +711,20 @@ opened open_project(std::filesystem::path const &Folder, std::string const &Map,
|
||||
{
|
||||
opened result;
|
||||
auto const path{path_of(Folder / Map)};
|
||||
if (std::filesystem::exists(path))
|
||||
if (std::error_code error; std::filesystem::exists(path, error))
|
||||
{
|
||||
result.project = load(path);
|
||||
return result;
|
||||
}
|
||||
auto made{migrate(marked_files(Folder, Map), Areas)};
|
||||
result.notes = std::move(made.notes);
|
||||
// no //$ lines: no file is written next to the map, which would be one more stray file in a working copy of the data. The project,
|
||||
// empty, is written as the editor saves the scenery once it has something
|
||||
if (made.project.network.lines().empty() && made.project.network.nodes().empty())
|
||||
{
|
||||
result.project.project = std::move(made.project);
|
||||
return result;
|
||||
}
|
||||
std::string error;
|
||||
if (false == save(made.project, path, error))
|
||||
{
|
||||
|
||||
@@ -66,7 +66,7 @@ std::vector<marked_file> marked_files(std::filesystem::path const &Folder, std::
|
||||
struct opened
|
||||
{
|
||||
read_result project;
|
||||
bool migrated{false}; // there was no project file: it was made of the //$ lines and written
|
||||
bool migrated{false}; // there was no project file: it was made of the //$ lines and written; with none of them, nothing is written
|
||||
std::vector<std::string> notes;
|
||||
};
|
||||
// the project of the map: its file read, or made of the //$ lines of the files of the map where there's none yet and written next to it;
|
||||
|
||||
@@ -15,6 +15,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace project
|
||||
{
|
||||
@@ -177,7 +180,17 @@ void session::record_written(layout::line_id const Line, std::vector<written_pie
|
||||
|
||||
void session::record_written(layout::line_id const Line, std::vector<written_piece> const &Pieces)
|
||||
{
|
||||
// the records of the line, of whatever kind and file, give way to the ones written now
|
||||
// the scenery writes only the tracks changed since it was saved: the records of the other tracks the line still has stay as they
|
||||
// were, or after a track moved and moved back the line would keep a record of that one track alone, and own only it when opened
|
||||
std::set<std::string> current;
|
||||
for (auto const &piece : generate(Line).pieces)
|
||||
current.insert(piece.name);
|
||||
auto const written_now = [&Pieces](std::string const &Name) { return std::ranges::any_of(Pieces, [&Name](written_piece const &Piece) { return Piece.name == Name; }); };
|
||||
std::vector<generated_node> kept;
|
||||
for (auto const &node : m_project.generated)
|
||||
if (node.kind == "track" && node.line == Line && current.contains(node.name) && false == written_now(node.name))
|
||||
kept.push_back(node);
|
||||
// the other records of the line, of whatever kind and file, give way to the ones written now
|
||||
std::erase_if(m_project.generated, [&](generated_node const &Node) { return Node.line == Line; });
|
||||
for (auto const &piece : Pieces)
|
||||
{
|
||||
@@ -189,6 +202,7 @@ void session::record_written(layout::line_id const Line, std::vector<written_pie
|
||||
node.sum = checksum(piece.text);
|
||||
m_project.generated.push_back(std::move(node));
|
||||
}
|
||||
m_project.generated.insert(m_project.generated.end(), kept.begin(), kept.end());
|
||||
// written again by the editor: the author decided
|
||||
m_project.hand_changed.erase(Line);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,13 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
|
||||
@@ -27,6 +31,8 @@ namespace
|
||||
|
||||
using scenery_text::statement;
|
||||
|
||||
|
||||
|
||||
// the files the files include, by a quick look at their words, each file looked at once for all the scenarios: a scenario whose includes
|
||||
// don't reach the file of the map doesn't use it, and isn't read as a whole
|
||||
class include_graph
|
||||
@@ -62,9 +68,8 @@ class include_graph
|
||||
auto found{m_includes.find(Key)};
|
||||
if (found != m_includes.end())
|
||||
return found->second;
|
||||
std::ifstream file{m_folder / Name, std::ios::binary};
|
||||
std::string const text{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
return m_includes.emplace(Key, scenery_text::includes_in(text)).first->second;
|
||||
auto const text{scenery_text::file_text(m_folder / Name)};
|
||||
return m_includes.emplace(Key, scenery_text::includes_in(text.value_or(std::string{}))).first->second;
|
||||
}
|
||||
|
||||
std::filesystem::path m_folder;
|
||||
@@ -242,9 +247,10 @@ scenario_index index_scenarios(std::filesystem::path const &Folder, std::string
|
||||
std::error_code error;
|
||||
for (std::filesystem::directory_iterator file{Folder, std::filesystem::directory_options::skip_permission_denied, error}, end; file != end; file.increment(error))
|
||||
{
|
||||
auto const name{file->path().filename().generic_string()};
|
||||
if (file->is_regular_file(error) && scenery_text::lowered(name).ends_with(".scn"))
|
||||
scenarios.push_back(name);
|
||||
if (false == scenery_text::has_extension(file->path(), u8".scn") || false == file->is_regular_file(error))
|
||||
continue;
|
||||
if (auto name{scenery_text::name_of(file->path())})
|
||||
scenarios.push_back(std::move(*name));
|
||||
}
|
||||
std::ranges::sort(scenarios, [](std::string const &A, std::string const &B) { return scenery_text::lowered(A) < scenery_text::lowered(B); });
|
||||
|
||||
|
||||
@@ -49,11 +49,14 @@ index_fingerprint fingerprint_of(std::filesystem::path const &Folder, std::strin
|
||||
std::error_code error;
|
||||
for (std::filesystem::directory_iterator file{Folder, std::filesystem::directory_options::skip_permission_denied, error}, end; file != end; file.increment(error))
|
||||
{
|
||||
auto const name{file->path().filename().generic_string()};
|
||||
if (false == file->is_regular_file(error) || false == scenery_text::lowered(name).ends_with(".scn"))
|
||||
// the extension looked at before the name is made a string, which throws on Windows outside of the code page
|
||||
if (false == scenery_text::has_extension(file->path(), u8".scn") || false == file->is_regular_file(error))
|
||||
continue;
|
||||
auto name{scenery_text::name_of(file->path())};
|
||||
if (false == name.has_value())
|
||||
continue;
|
||||
index_fingerprint::file entry;
|
||||
entry.name = name;
|
||||
entry.name = std::move(*name);
|
||||
entry.size = file->file_size(error);
|
||||
entry.time = std::chrono::duration_cast<std::chrono::seconds>(file->last_write_time(error).time_since_epoch()).count();
|
||||
result.files.push_back(std::move(entry));
|
||||
|
||||
@@ -9,13 +9,16 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "editor/project/sceneryText.hpp"
|
||||
#include "utilities/utilities.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
|
||||
namespace scenery_text
|
||||
@@ -93,13 +96,6 @@ std::string normalized(std::string_view const Name)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::optional<std::string> file_text(std::filesystem::path const &Path)
|
||||
{
|
||||
std::ifstream file{Path, std::ios::binary};
|
||||
if (false == file.is_open())
|
||||
return std::nullopt;
|
||||
return std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
}
|
||||
|
||||
// (p1), (p2)... put in place by the parameters of the include, a missing one as none (cParser::substituteParameters())
|
||||
void substitute(std::string &Text, std::vector<std::string> const &Parameters)
|
||||
@@ -443,6 +439,40 @@ std::optional<std::string> node_text(std::string_view const Text, std::string_vi
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::string> name_of(std::filesystem::path const &Path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Path.filename().generic_string();
|
||||
}
|
||||
catch (std::system_error const &)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
bool has_extension(std::filesystem::path const &Path, std::u8string_view const Extension)
|
||||
{
|
||||
auto const extension{Path.extension().u8string()};
|
||||
return extension.size() == Extension.size() && std::ranges::equal(extension, Extension, [](char8_t const A, char8_t const B) { return std::tolower(static_cast<unsigned char>(A)) == std::tolower(static_cast<unsigned char>(B)); });
|
||||
}
|
||||
|
||||
std::optional<std::string> file_text(std::filesystem::path const &Path)
|
||||
{
|
||||
std::ifstream file{Path, std::ios::binary};
|
||||
if (false == file.is_open())
|
||||
{
|
||||
// named in another case, as the game finds it on Linux
|
||||
auto const cased{FileCased(Path)};
|
||||
if (cased.empty())
|
||||
return std::nullopt;
|
||||
file.open(cased, std::ios::binary);
|
||||
if (false == file.is_open())
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
}
|
||||
|
||||
bool same_file(std::string_view const A, std::string_view const B)
|
||||
{
|
||||
return normalized(A) == normalized(B);
|
||||
|
||||
@@ -102,6 +102,15 @@ struct scenery
|
||||
// the scenery from the file Root, relative to the folder, with all its includes
|
||||
scenery read(std::filesystem::path const &Folder, std::string const &Root, read_options const &Options = {});
|
||||
|
||||
// the name of the file as the strings of the game hold it, none where the code page can't (Windows): generic_string() throws there,
|
||||
// and the game couldn't open such a file by its name either
|
||||
std::optional<std::string> name_of(std::filesystem::path const &Path);
|
||||
// the file has the extension, in any case, without its name being made a string
|
||||
bool has_extension(std::filesystem::path const &Path, std::u8string_view const Extension);
|
||||
|
||||
// the text of the file, also where it's named in another case, as the game finds it (FileCased); none when it can't be read
|
||||
std::optional<std::string> file_text(std::filesystem::path const &Path);
|
||||
|
||||
// the same names of files, the case and the slashes aside
|
||||
bool same_file(std::string_view const A, std::string_view const B);
|
||||
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
wait 5
|
||||
switchplace Rz_60E1-300-1:9 40 150 1 1
|
||||
expect records z1 1 switch
|
||||
expect shaped z1 yes
|
||||
# the end of the diverging path of z1 moved aside with the gizmo: z1 no longer has the shape its record says
|
||||
select z1
|
||||
gizmo begin translate 1 end
|
||||
gizmo offset 0.5 0 0
|
||||
gizmo end
|
||||
# the drag went through: without it the case would only delete a switch which kept its shape
|
||||
expect shaped z1 no
|
||||
expect records z1 1 switch
|
||||
deletetrack z1
|
||||
expect track z1 removed
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# First steps: the answer Without terrain to the question of the terrain of a new empty scenery turns off the terrain made of the
|
||||
# terrain model by itself: under the tracks as they're laid (the checkbox of the layers) and around the camera within the download
|
||||
# area (the checkbox of the terrain panel), so nothing of the model is asked for. The question asked as the first L in an empty
|
||||
# scenery asks it (the fixture has tracks, so it isn't asked by itself)
|
||||
# area (the checkbox of the terrain panel), so nothing of the model is asked for. For this scenery only: the settings, kept for the
|
||||
# sceneries opened later, stay as they were (nmtquestion flat fails the run if they changed). The question asked as the first L
|
||||
# in an empty scenery asks it (the fixture has tracks, so it isn't asked by itself)
|
||||
wait 5
|
||||
nmtsettings grow 1
|
||||
wait 2
|
||||
|
||||
@@ -34,17 +34,17 @@ Line n01: 988.0 m, 11 elements, 19 findings
|
||||
828.0 note cant change rate 42 mm/s, PLK recommends at most 35 mm/s (tab. 9.13) [n13]
|
||||
|
||||
Norms: TSI INF, line 100 km/h, slow trains 60 km/h, mixed traffic, main track, 5 Tg a year, the speed of the tracks where they have one
|
||||
Line n01: 988.0 m, 11 elements, 3 findings
|
||||
Line n01: 988.0 m, 11 elements, 4 findings
|
||||
478.0 hard limit abrupt change of the cant deficiency 191 mm, TSI INF allows at most 130 mm (4.2.4.4(1)) [n07]
|
||||
598.0 hard limit break of the grade with no vertical curve, TSI INF asks for a radius of at least 900 m (4.2.3.5(1)) [n10]
|
||||
648.0 hard limit cant ramp 3.00 mm/m, EN 13803-1 allows at most 2.50 mm/m (5.2.5) [n11]
|
||||
648.0 hard limit break of the grade with no vertical curve, TSI INF asks for a radius of at least 500 m (4.2.3.5(1)) [n11]
|
||||
|
||||
Norms: EN 13803, line 100 km/h, slow trains 60 km/h, mixed traffic, main track, 5 Tg a year, the speed of the tracks where they have one
|
||||
Line n01: 988.0 m, 11 elements, 10 findings
|
||||
Line n01: 988.0 m, 11 elements, 9 findings
|
||||
210.0 warning cant deficiency 137 mm, EN 13803 allows at most 130 mm (5.2.3, tab. 1) [n03]
|
||||
398.0 warning abrupt change of the cant deficiency 106 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n06]
|
||||
478.0 warning abrupt change of the cant deficiency 106 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n07]
|
||||
488.0 warning abrupt change of the cant deficiency 85 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n08]
|
||||
478.0 hard limit abrupt change of the cant deficiency 191 mm, TSI INF allows at most 130 mm (4.2.4.4(1)) [n07]
|
||||
548.0 warning abrupt change of the cant deficiency 85 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n09]
|
||||
598.0 hard limit break of the grade with no vertical curve, TSI INF asks for a radius of at least 900 m (4.2.3.5(1)) [n10]
|
||||
648.0 hard limit cant ramp 3.00 mm/m, EN 13803 allows at most 2.50 mm/m (5.2.5) [n11]
|
||||
|
||||
@@ -78,7 +78,7 @@ inline segment_data path_between(layout::solved_line const &Line, glm::dvec3 con
|
||||
inline old_line cut(layout::solved_line const &Line, unsigned const Seed, double const Shortest, double const Longest, noise const &Noise) {
|
||||
old_line result;
|
||||
result.line = Line;
|
||||
std::mt19937 random{Seed};
|
||||
std::mt19937 random{Seed}; // NOSONAR: seeded for repeatable tests, nothing secret is drawn
|
||||
std::uniform_real_distribution<double> length{Shortest, Longest};
|
||||
std::uniform_real_distribution<double> shake{-1.0, 1.0};
|
||||
std::bernoulli_distribution backwards{0.3};
|
||||
|
||||
@@ -1180,7 +1180,8 @@ TEST_CASE("alignment: the cant ramp the norms ask for, which a track laid on fro
|
||||
CHECK(alignment::cant_ramp_length(100.0, 120.0, gentle) == doctest::Approx(100.0));
|
||||
// the ramp is never shorter at a higher speed
|
||||
double previous{0.0};
|
||||
for (double speed = 20.0; speed <= 200.0; speed += 10.0) {
|
||||
for (int step{0}; step <= 18; ++step) {
|
||||
auto const speed{20.0 + 10.0 * step};
|
||||
auto const length{alignment::cant_ramp_length(speed, 80.0, norms)};
|
||||
CHECK(length >= previous);
|
||||
previous = length;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// the cant of the tracks the editor lays and joins: from mm to the roll of the paths and back, signed with the turn, and matched
|
||||
// across the joints of the tracks
|
||||
//
|
||||
// the inspector of the editor shows and takes the cant on a base of 1500 mm in lambdas of its own (application/editormodetrack.cpp);
|
||||
// named, as editor_mode::cant_of_roll() and roll_of_cant(), they come with the quick fixes of the track editing, and their tests with them
|
||||
// the inspector of the editor shows and takes the cant on a base of 1500 mm through editor_mode::cant_of_roll() and roll_of_cant()
|
||||
// (application/editormodetrack.cpp). They live in the editor, which the unit tests don't link, so the self-test cases check them
|
||||
// through the inspector: tests/editor/cases/1_inspector_cant.txt
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
|
||||
@@ -34,7 +34,8 @@ track_points along(layout::network const &Network, std::vector<line_id> const &L
|
||||
track_points result;
|
||||
for (auto const id : Lines) {
|
||||
auto const &solved{Network.find(id)->solved};
|
||||
for (double s = 0.0; s < solved.length; s += Step) {
|
||||
for (int i{0}; i * Step < solved.length; ++i) {
|
||||
auto const s{i * Step};
|
||||
result.points.push_back(solved.point(s));
|
||||
result.cants.push_back(solved.cant_at(s));
|
||||
}
|
||||
@@ -58,7 +59,8 @@ void check_same_track(layout::network const &Before, line_id const Whole, layout
|
||||
auto const &first{After.find(First)->solved};
|
||||
auto const &second{After.find(Second)->solved};
|
||||
CHECK(first.length + second.length == doctest::Approx(whole.length).epsilon(1e-9));
|
||||
for (double s = 0.0; s <= whole.length; s += 7.3) {
|
||||
for (int i{0}; i * 7.3 <= whole.length; ++i) {
|
||||
auto const s{i * 7.3};
|
||||
CAPTURE(s);
|
||||
auto const &part{s < first.length ? first : second};
|
||||
auto const local{s < first.length ? s : s - first.length};
|
||||
@@ -200,6 +202,34 @@ TEST_CASE("layout commands: a line split on a straight, in an arc and in a cloth
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("layout commands: a line split right at the tangent points of an arc with no transitions keeps the track") {
|
||||
// one gentle curve with neither transitions nor cant, so its curvature jumps at the tangent points
|
||||
for (auto const share : {0.0, 1.0}) {
|
||||
CAPTURE(share);
|
||||
layout::model model;
|
||||
layout::create_line gentle;
|
||||
gentle.start = {0.0, 100.0, 0.0};
|
||||
gentle.end = {1200.0, 100.0, 50.0};
|
||||
layout::vertex bend;
|
||||
bend.point = {600.0, 0.0};
|
||||
bend.radius = 4000.0;
|
||||
gentle.vertices = {bend};
|
||||
gentle.category = line_class();
|
||||
auto const made{model.execute(gentle)};
|
||||
CAPTURE(reasons_of(made));
|
||||
REQUIRE(made.done);
|
||||
auto const before{model.state()};
|
||||
auto const &line{only_line(model)};
|
||||
auto const id{line.id};
|
||||
auto const chainage{inside(line, layout::element_role::arc, layout::number(line.shape.vertices[0].id), share)};
|
||||
auto const split{model.execute(layout::split_line{id, chainage})};
|
||||
CAPTURE(reasons_of(split));
|
||||
REQUIRE(split.done);
|
||||
check_invariants(model.state());
|
||||
check_same_track(before, id, model.state(), id, split.lines.front());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("layout commands: a split inside a vertical curve or a Bloss transition is refused; outside them it's kept") {
|
||||
layout::model model;
|
||||
REQUIRE(model.execute(three_curves(layout::transition_shape::bloss)).done);
|
||||
@@ -281,7 +311,7 @@ namespace {
|
||||
|
||||
// random edits of the network: moved vertices, new radii, transitions and cants, splits, joins, deletions, undoing and redoing
|
||||
void random_edits(unsigned const Seed, int const Count) {
|
||||
std::mt19937 random{Seed};
|
||||
std::mt19937 random{Seed}; // NOSONAR: seeded for repeatable tests, nothing secret is drawn
|
||||
auto const uniform = [&](double const Low, double const High) { return std::uniform_real_distribution<double>{Low, High}(random); };
|
||||
auto const pick = [&](std::size_t const Size) { return std::uniform_int_distribution<std::size_t>{0, Size - 1}(random); };
|
||||
layout::model model;
|
||||
|
||||
@@ -116,7 +116,8 @@ TEST_CASE("layout elements: an arc keeps its radius and its centre, points offse
|
||||
auto const e{layout::make_arc({5.0, 7.0}, {0.0, 1.0}, -1.0 / R, 200.0)};
|
||||
// turning right from heading +z: the centre to the right, at +x
|
||||
glm::dvec2 const centre{5.0 + R, 7.0};
|
||||
for (double s = 0.0; s <= 200.0; s += 25.0) {
|
||||
for (int step{0}; step <= 8; ++step) {
|
||||
auto const s{25.0 * step};
|
||||
CAPTURE(s);
|
||||
CHECK(glm::distance(e.position(s), centre) == doctest::Approx(R).epsilon(1e-12));
|
||||
CHECK(e.curvature(s) == -1.0 / R);
|
||||
|
||||
@@ -287,7 +287,7 @@ namespace {
|
||||
// other type, taken out, with splits, joins and deletions of the lines, undoing and redoing; after each the invariants, a refusal changing
|
||||
// nothing, an undo giving the state before
|
||||
void random_kind_edits(unsigned const Seed, int const Count) {
|
||||
std::mt19937 random{Seed};
|
||||
std::mt19937 random{Seed}; // NOSONAR: seeded for repeatable tests, nothing secret is drawn
|
||||
auto const uniform = [&](double const Low, double const High) { return std::uniform_real_distribution<double>{Low, High}(random); };
|
||||
auto const pick = [&](std::size_t const Size) { return std::uniform_int_distribution<std::size_t>{0, Size - 1}(random); };
|
||||
auto const types{layout::turnout_types()};
|
||||
|
||||
@@ -247,7 +247,8 @@ TEST_CASE("layout generator G: the diverging track of Rz 60E1-2500-1:26,5 within
|
||||
CHECK(std::abs(diverging.length() - 2500.0 * std::atan(1.0 / 26.5)) < 0.001);
|
||||
double least{1.0};
|
||||
double most{0.0};
|
||||
for (double s = 0.0; s + 30.0 <= diverging.length(); s += 1.0) {
|
||||
for (int metre{0}; metre + 30.0 <= diverging.length(); ++metre) {
|
||||
auto const s{static_cast<double>(metre)};
|
||||
auto const a{diverging.at(s)};
|
||||
auto const b{diverging.at(s + 30.0)};
|
||||
auto const middle{diverging.at(s + 15.0)};
|
||||
|
||||
@@ -110,6 +110,19 @@ TEST_CASE("layout turnouts: the ordinary switches of the catalogue are laid, the
|
||||
CHECK(why.find("catalogue") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("layout turnouts: no diverging track is laid from a main track that isn't laid") {
|
||||
auto const type{layout::turnout_type_of("Rz 60E1-300-1:9")};
|
||||
REQUIRE(type.has_value());
|
||||
// a frame left as it is when the main track isn't solved: at the origin, along x
|
||||
layout::turnout_frame frame;
|
||||
frame.heading = {1.0, 0.0};
|
||||
REQUIRE_FALSE(frame.valid);
|
||||
auto const laid{layout::lay_diverging(frame, *type, 1)};
|
||||
CHECK_FALSE(laid.valid());
|
||||
REQUIRE_FALSE(laid.errors.empty());
|
||||
CHECK(laid.errors.front().find("main track isn't laid") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("layout turnouts: the legs on a straight against the catalogue: the main track a + b, the centre at a, the diverging end at 1:n") {
|
||||
for (auto const *name : {"Rz 60E1-190-1:9", "Rz 60E1-500-1:12", "Rz 60E1-1200-1:18,5", "Rz 49E1-500-1:14"}) {
|
||||
for (auto const hand : {1, -1}) {
|
||||
@@ -334,7 +347,8 @@ TEST_CASE("layout turnouts: moved along its line, changed, taken out with the li
|
||||
auto const &again{model.state().lines().begin()->second.solved};
|
||||
auto const &original{whole.find(line)->solved};
|
||||
CHECK(again.length == doctest::Approx(original.length).epsilon(1e-12));
|
||||
for (double s = 0.0; s <= original.length; s += 3.7) {
|
||||
for (int i{0}; i * 3.7 <= original.length; ++i) {
|
||||
auto const s{i * 3.7};
|
||||
CAPTURE(s);
|
||||
CHECK(glm::distance(again.point(s), original.point(s)) < 1e-6);
|
||||
CHECK(std::abs(again.cant_at(s) - original.cant_at(s)) < 1e-6);
|
||||
@@ -480,7 +494,8 @@ TEST_CASE("layout commands: a line joined to a free end in a curve goes on from
|
||||
REQUIRE(link.shape.vertices.size() == 1);
|
||||
CHECK(link.shape.vertices.front().radius == doctest::Approx(800.0));
|
||||
CHECK(link.shape.vertices.front().transition_out == doctest::Approx(transition).epsilon(1e-6));
|
||||
for (double s = 0.0; s <= link.solved.length; s += 5.0) {
|
||||
for (int i{0}; i * 5.0 <= link.solved.length; ++i) {
|
||||
auto const s{i * 5.0};
|
||||
CAPTURE(s);
|
||||
CHECK(glm::distance(link.solved.point(s), original.point(at + s)) < 1e-6);
|
||||
}
|
||||
@@ -556,7 +571,7 @@ std::vector<std::string> const kTypes{"Rz 60E1-190-1:9", "Rz 60E1-300-1:9", "Rz
|
||||
// out, splits, joins, deletions), undoing and redoing; after each the invariants, a refusal changing nothing, an undo giving the state
|
||||
// before. Policy: of the norms; with no_new_block the network starts from one breaking them and no BLOCK finding is added
|
||||
void random_turnout_edits(unsigned const Seed, int const Count, layout::edit_policy const Policy = layout::edit_policy::refuse_block) {
|
||||
std::mt19937 random{Seed};
|
||||
std::mt19937 random{Seed}; // NOSONAR: seeded for repeatable tests, nothing secret is drawn
|
||||
auto const uniform = [&](double const Low, double const High) { return std::uniform_real_distribution<double>{Low, High}(random); };
|
||||
auto const pick = [&](std::size_t const Size) { return std::uniform_int_distribution<std::size_t>{0, Size - 1}(random); };
|
||||
layout::model model;
|
||||
|
||||
@@ -36,6 +36,11 @@ public:
|
||||
m_line.elements.back().features = Features;
|
||||
return *this;
|
||||
}
|
||||
// the last transition a Bloss curve
|
||||
line_builder &bloss() {
|
||||
m_line.elements.back().bloss = true;
|
||||
return *this;
|
||||
}
|
||||
norms::line done() {
|
||||
if (m_line.grades.empty()) {
|
||||
m_line.grades.push_back({0.0, m_end, 0.0, 0.0});
|
||||
@@ -237,6 +242,21 @@ TEST_CASE("norms engine: the abrupt changes over a straight shorter than tab. 9.
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("norms engine: TSI and EN, which say nothing of jumps close together, take them together over the intermediate length of the other profiles") {
|
||||
// the reverse curves of the test above, 10 m apart: each jump of 106.2 mm passes the TSI, their 212.4 mm don't
|
||||
auto const each{11.8 * 60 * 60 / 400.0};
|
||||
for (auto const profile : {profile_id::tsi, profile_id::en13803}) {
|
||||
CAPTURE(static_cast<int>(profile));
|
||||
line_builder builder;
|
||||
builder.straight(100, 60).arc(400, 80, 60).straight(10.0, 60).arc(-400, 80, 60).straight(100, 60);
|
||||
auto const found{of(evaluate(builder.done(), mixed_main(60), profile), parameter::deficiency_jump)};
|
||||
auto const summed{std::ranges::find_if(found, [](norms::finding const &Finding) { return std::abs(Finding.chainage - 180.0) < 1e-6; })};
|
||||
REQUIRE(summed != found.end());
|
||||
CHECK(summed->value == doctest::Approx(2.0 * each));
|
||||
CHECK(summed->length == doctest::Approx(10.0));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("norms engine: the gradient and the rate of change of the cant along a ramp, the rate of change of the deficiency along a transition") {
|
||||
// 100 mm over 50 m at 120 km/h: 2 mm/m, 66.7 mm/s
|
||||
line_builder ramp;
|
||||
@@ -270,6 +290,39 @@ TEST_CASE("norms engine: the gradient and the rate of change of the cant along a
|
||||
CHECK(change.front().level == tier::block);
|
||||
}
|
||||
|
||||
TEST_CASE("norms engine: a Bloss transition changes the cant deficiency fastest in its middle, and moves the arc in by L^2 / 40R") {
|
||||
// 60 m into R 600 m at 100 km/h, the cant evenly up to 60 mm: 136.7 mm of deficiency, 63.3 mm/s along an even transition, and
|
||||
// 1.5 * 196.7 - 60 = 235 mm per its length in the middle of a Bloss curve, 108.8 mm/s, past the 80 mm/s of the hard limit
|
||||
auto const findings = [](bool const Bloss) {
|
||||
line_builder curve;
|
||||
curve.straight(100, 100).transition(0, 600, 60, 100);
|
||||
if (Bloss)
|
||||
curve.bloss();
|
||||
curve.arc(600, 100, 100).transition(600, 0, 60, 100);
|
||||
if (Bloss)
|
||||
curve.bloss();
|
||||
curve.straight(100, 100);
|
||||
curve.cant(0, 0).cant(100, 0).cant(160, 60).cant(260, 60).cant(320, 0);
|
||||
return evaluate(curve.done(), mixed_main(100));
|
||||
};
|
||||
auto const fastest = [](std::vector<norms::finding> const &Found) {
|
||||
double result{0.0};
|
||||
for (auto const &finding : of(Found, parameter::deficiency_rate))
|
||||
result = std::max(result, finding.value);
|
||||
return result;
|
||||
};
|
||||
auto const even{findings(false)};
|
||||
auto const bloss{findings(true)};
|
||||
CHECK(fastest(even) == doctest::Approx((11.8 * 100 * 100 / 600.0 - 60.0) * 100 / (3.6 * 60.0)).epsilon(0.01));
|
||||
// seen as eight pieces, a little below the peak of the curve
|
||||
CHECK(fastest(bloss) > 100.0);
|
||||
CHECK(fastest(bloss) < 109.0);
|
||||
auto const blocked{of(bloss, parameter::deficiency_rate)};
|
||||
CHECK(std::ranges::any_of(blocked, [](norms::finding const &Finding) { return Finding.level == tier::block; }));
|
||||
for (auto const &finding : of(bloss, parameter::transition_shift))
|
||||
CHECK(finding.value == doctest::Approx(60.0 * 60.0 / (600.0 * 40.0)));
|
||||
}
|
||||
|
||||
TEST_CASE("norms engine: the lengths of the elements, the transition curves and the radius") {
|
||||
line_builder builder;
|
||||
builder.straight(100, 100).arc(400, 20, 100).straight(28, 100).transition(0, 400, 20, 100).arc(400, 100, 100).transition(400, 0, 60, 100).straight(100, 100);
|
||||
|
||||
@@ -149,16 +149,15 @@ TEST_CASE("norms report: the cant of a curve laid by the editor leans into it, b
|
||||
}
|
||||
}
|
||||
CHECK(curved > 50);
|
||||
// so at 80 km/h the arc falls short by 11.8 V^2 / R - 80 mm, not by more
|
||||
// so at 90 km/h the arc falls short by 11.8 V^2 / R - 80 mm, not by more: 159 mm, past the 110 mm of a finding (at 80 km/h
|
||||
// the 108.8 mm would make none, and the check would never run)
|
||||
norms_report::options options;
|
||||
options.line.vmax = 80.0;
|
||||
options.line.vmax = 90.0;
|
||||
options.track_speeds = false;
|
||||
auto const checked{norms_report::check(spans, options)};
|
||||
for (auto const &found : checked.entries) {
|
||||
if (found.finding.what == norms::parameter::cant_deficiency && found.kind == norms::element_kind::arc) {
|
||||
CHECK(found.finding.value == doctest::Approx(11.8 * 80 * 80 / 400.0 - 80.0).epsilon(0.02));
|
||||
}
|
||||
}
|
||||
auto const deficient{std::ranges::find_if(checked.entries, [](auto const &Found) { return Found.finding.what == norms::parameter::cant_deficiency && Found.kind == norms::element_kind::arc; })};
|
||||
REQUIRE(deficient != checked.entries.end());
|
||||
CHECK(deficient->finding.value == doctest::Approx(11.8 * 90 * 90 / 400.0 - 80.0).epsilon(0.02));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +286,10 @@ TEST_CASE("project file: a newer schema is refused cleanly, and a file which isn
|
||||
REQUIRE(lower.project.has_value());
|
||||
CHECK(lower.project->network.handed() == layout::network::handed_out{5, 3, 2});
|
||||
CHECK_FALSE(lower.notes.empty());
|
||||
// next 0: the identifiers start at 1, so it isn't taken as the last one handed out wrapped round to 0xffffffff
|
||||
auto const zero{with("next node 6 line 4 vertex 3 turnout 1", "next node 0 line 4 vertex 3 turnout 1")};
|
||||
CHECK_FALSE(zero.project.has_value());
|
||||
CHECK(zero.error.find("the next node 0") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("project file: the identifiers aren't handed out again after deletions and a save and a load") {
|
||||
|
||||
@@ -168,6 +168,16 @@ TEST_CASE("project migration: the golden //$ lines of data/records made into a p
|
||||
CHECK(station->name == editor_records::read_station(files[7].lines.at('s')[1])->name);
|
||||
}
|
||||
|
||||
TEST_CASE("project migration: a map with no //$ lines gets an empty project and no file next to it") {
|
||||
test::scratch_folder folder{"project_migration_none"};
|
||||
std::ofstream{folder.root() / "pusta.scm", std::ios::binary} << "node -1 0 t1 track normal 100 1.435 0.2 25 20 0 flat vis 0 0 0 0 0 0 0 0 0 0 100 0 endtrack\n";
|
||||
auto const opened{project::open_project(folder.root(), "pusta.scm")};
|
||||
REQUIRE_MESSAGE(opened.project.project.has_value(), opened.project.error);
|
||||
CHECK(opened.project.project->network.lines().empty());
|
||||
CHECK_FALSE(opened.migrated);
|
||||
CHECK_FALSE(std::filesystem::exists(folder.root() / "pusta.eu07proj"));
|
||||
}
|
||||
|
||||
TEST_CASE("project migration: a map opened for the first time gets its project of the //$ lines of its files; the files stay as they were") {
|
||||
test::scratch_folder folder{"project_migration"};
|
||||
auto const source{std::filesystem::path{EU07_UNIT_TESTS_DATA} / "project" / "migration"};
|
||||
@@ -284,10 +294,20 @@ TEST_CASE("project migration: the //$r switches on the lines made of the alignme
|
||||
REQUIRE(by_type.contains("Rz 60E1-190-1:9"));
|
||||
auto const &first{*by_type.at("Rz 60E1-500-1:12")};
|
||||
auto const &second{*by_type.at("Rz 60E1-190-1:9")};
|
||||
CHECK(first.hand == 1);
|
||||
// the hands as the records have them: L to the negative cross of the direction of the switch, R to the positive one, as
|
||||
// switch_store::classify() tells them; checked where the diverging track ends, not only by the number
|
||||
CHECK(first.hand == -1);
|
||||
CHECK(first.direction == 1);
|
||||
CHECK(second.hand == -1);
|
||||
CHECK(second.hand == 1);
|
||||
CHECK(second.direction == -1);
|
||||
auto const side = [&network](layout::turnout const &Turnout, glm::dvec2 const &Direction) {
|
||||
auto const &diverging{network.find(Turnout.diverging)->solved};
|
||||
auto const start{geometry::plan_of(network.find(Turnout.start)->position)};
|
||||
// the diverging track is laid from the start of the turnout
|
||||
return geometry::cross(Direction, geometry::plan_of(diverging.end.position) - start);
|
||||
};
|
||||
CHECK(side(first, {0.0, 1.0}) < 0.0); // z1, L
|
||||
CHECK(side(second, {0.0, -1.0}) > 0.0); // z2, R
|
||||
CHECK(glm::distance(geometry::plan_of(network.find(first.start)->position), glm::dvec2{0.0, 200.0}) < 1e-9);
|
||||
CHECK(glm::distance(geometry::plan_of(network.find(second.start)->position), glm::dvec2{0.0, 450.0}) < 1e-9);
|
||||
// each a record of its own with its main track; the rest of the block kept as written, why with it
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
@@ -63,8 +64,9 @@ TEST_CASE("project session: the map opened gets its project, a command tried cha
|
||||
project::session session;
|
||||
auto const opened{session.open(folder.root(), "mapa.scn")};
|
||||
REQUIRE(opened.done);
|
||||
CHECK(opened.migrated);
|
||||
CHECK(std::filesystem::exists(folder.root() / "mapa.eu07proj"));
|
||||
// nothing to migrate: no file yet, it's written as the scenery is saved
|
||||
CHECK_FALSE(opened.migrated);
|
||||
CHECK_FALSE(std::filesystem::exists(folder.root() / "mapa.eu07proj"));
|
||||
CHECK(session.file() == folder.root() / "mapa.eu07proj");
|
||||
CHECK(session.network().lines().empty());
|
||||
|
||||
@@ -164,6 +166,34 @@ TEST_CASE("project session: each command a step the editor takes back and brings
|
||||
CHECK(session.undoable() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("project session: a save writing one track of a line keeps the records of its other tracks") {
|
||||
test::scratch_folder folder{"project_session_partial"};
|
||||
folder.write("mapa.scn", "// a new scenery\n");
|
||||
project::session session;
|
||||
REQUIRE(session.open(folder.root(), "mapa.scn").done);
|
||||
REQUIRE(session.execute(three_curves()).outcome.done);
|
||||
write_tracks(session, folder, "mapa.scn", {line_id{1}});
|
||||
auto const of_line = [&session]() {
|
||||
std::set<std::string> names;
|
||||
for (auto const &node : session.project().generated)
|
||||
if (node.line == line_id{1})
|
||||
names.insert(node.name);
|
||||
return names;
|
||||
};
|
||||
auto const all{of_line()};
|
||||
REQUIRE(all.size() > 1);
|
||||
// a track moved and moved back (Ctrl+Z): the scenery writes that one alone
|
||||
auto const piece{session.generate(line_id{1}).pieces.front()};
|
||||
session.record_written(line_id{1}, {{piece.name, piece.text}}, "mapa.scn");
|
||||
CHECK(of_line() == all);
|
||||
std::string error;
|
||||
REQUIRE(session.save(error));
|
||||
auto const opened{session.open(folder.root(), "mapa.scn")};
|
||||
REQUIRE(opened.done);
|
||||
CHECK(opened.hand_changes.empty());
|
||||
CHECK(of_line() == all);
|
||||
}
|
||||
|
||||
TEST_CASE("project session: the tracks written recorded, one changed in the file marks its line, written over only when the author decides") {
|
||||
test::scratch_folder folder{"project_session_hand"};
|
||||
folder.write("mapa.scn", "// a new scenery\n");
|
||||
|
||||
@@ -59,7 +59,7 @@ void check_found(layout::line_shape const &Original, layout::recognized_line con
|
||||
CAPTURE(vertex.radius);
|
||||
auto const *match{nearest(Found.shape, vertex.point, 5.0)};
|
||||
REQUIRE(match != nullptr);
|
||||
CHECK(std::abs(match->radius - vertex.radius) < vertex.radius * 0.01);
|
||||
CHECK(std::abs(match->radius - vertex.radius) < vertex.radius * 0.01); // NOSONAR: REQUIRE above ends the test on none
|
||||
CHECK(same_transition(Turned ? match->transition_out : match->transition_in, vertex.transition_in, vertex.radius));
|
||||
CHECK(same_transition(Turned ? match->transition_in : match->transition_out, vertex.transition_out, vertex.radius));
|
||||
CHECK(std::abs(match->cant - vertex.cant) < 3.0);
|
||||
@@ -114,7 +114,7 @@ TEST_CASE("takeover fit: the same line whichever old track the walk starts from,
|
||||
CAPTURE(seed);
|
||||
// the tracks in another order: the walk starts from another one of them, somewhere along the line
|
||||
auto shuffled{tracks};
|
||||
std::mt19937 random{seed};
|
||||
std::mt19937 random{seed}; // NOSONAR: seeded for repeatable tests, nothing secret is drawn
|
||||
std::ranges::shuffle(shuffled, random);
|
||||
auto const plan{layout::plan_takeover(shuffled, take_all(shuffled))};
|
||||
REQUIRE(plan.lines.size() == 1);
|
||||
|
||||
@@ -99,7 +99,7 @@ TEST_CASE("takeover scenery: the plain tracks taken over as three lines within t
|
||||
// line a: the curve of R 500 m, its clothoids of 60 m and 80 mm read back; held at the switch, in its heading
|
||||
auto const *a{line_with(plan, scenery, "a_1")};
|
||||
REQUIRE(a != nullptr);
|
||||
CHECK(a->chain.links.size() == 26);
|
||||
CHECK(a->chain.links.size() == 26); // NOSONAR: REQUIRE above ends the test on none
|
||||
CHECK(a->chain.end.kind == layout::legacy_end_kind::held);
|
||||
CHECK(a->chain.start.kind == layout::legacy_end_kind::free);
|
||||
REQUIRE(a->fit.shape.vertices.size() == 1);
|
||||
@@ -191,19 +191,28 @@ TEST_CASE("takeover scenery: the tracks made again end at the old joints with th
|
||||
auto const piece{std::ranges::find_if(made.pieces, [](layout::generated_piece const &Each) { return Each.name == "a_3"; })};
|
||||
REQUIRE(piece != made.pieces.end());
|
||||
CHECK(geometry::plan_distance(piece->path.points[segment_data::point::start], a3.paths.front().points[segment_data::point::start]) < 0.02);
|
||||
// the curve made wider by 20 m: the lines laid again, the old tracks where they were along it
|
||||
// the curve made wider by 20 m: the lines laid again, the old tracks where they were on the ground, each joint at the point of the
|
||||
// new line nearest to where it was; the line shorter, none of them past its end
|
||||
auto const before{network.find(id)->solved};
|
||||
auto const splits{network.find(id)->hard_splits};
|
||||
auto const &vertex{network.find(id)->shape.vertices.front()};
|
||||
auto const changed{model.execute(layout::set_vertex{id, vertex.id, vertex.radius + 20.0, {}, {}, {}}, layout::edit_policy::no_new_block)};
|
||||
REQUIRE_MESSAGE(changed.done, first_reason(changed));
|
||||
CHECK(model.state().find(id)->hard_splits == splits);
|
||||
auto const &widened{*model.state().find(id)};
|
||||
REQUIRE(widened.hard_splits.size() == splits.size());
|
||||
for (std::size_t i = 0; i < splits.size(); ++i) {
|
||||
CAPTURE(i);
|
||||
CHECK(widened.hard_splits[i].track == splits[i].track);
|
||||
CHECK(widened.hard_splits[i].chainage <= widened.solved.length);
|
||||
CHECK(widened.hard_splits[i].chainage == doctest::Approx(widened.solved.nearest(before.position(splits[i].chainage))));
|
||||
}
|
||||
check_made(model.state());
|
||||
// written into the project file and read back the same
|
||||
project::document document;
|
||||
document.network = model.state();
|
||||
auto const read{project::read(project::write(document))};
|
||||
REQUIRE(read.project.has_value());
|
||||
CHECK(read.project->network.find(id)->hard_splits == splits);
|
||||
CHECK(read.project->network.find(id)->hard_splits == widened.hard_splits);
|
||||
}
|
||||
|
||||
TEST_CASE("takeover scenery: the anchors of the lineside objects, with their confidence, follow a change of their line") {
|
||||
|
||||
@@ -182,6 +182,22 @@ TEST_CASE("track text: what the game writes otherwise than it was given, the sam
|
||||
// what doesn't survive yet: each fails until it does, then doctest reports the test passing against should_fail, and the entry goes
|
||||
// over to the files of the entries which come out the same
|
||||
|
||||
// what those tests start from, checked apart from them: under should_fail a missing file or entry would pass for a loss
|
||||
TEST_CASE("track text: the entries known to be lost are there, with what they're about, and read") {
|
||||
track_reading const reading;
|
||||
struct known {
|
||||
char const *name;
|
||||
char const *about;
|
||||
};
|
||||
for (auto const &[name, about] : {known{"angles", " angle1 15 "}, known{"fouling", " fouling1 ukres_a "}, known{"tor1@iso1", "tor1@iso1"}, known{"digits", " digits "}}) {
|
||||
CAPTURE(name);
|
||||
auto const text{entry("known_lost.scn", name)};
|
||||
REQUIRE(false == text.empty());
|
||||
CHECK(text.find(about) != std::string::npos);
|
||||
CHECK(read_track(text) != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("track text: the angles the ends are cut at are written back (known lost: read and dropped)" * doctest::should_fail()) {
|
||||
track_reading const reading;
|
||||
round_trip const trip{entry("known_lost.scn", "angles")};
|
||||
|
||||
Reference in New Issue
Block a user