mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 22:07:55 +01:00
feat(editor): the catalogue of the turnouts a data file, the switch tool and the domain model reading it
The first part of E5 (editor-tracks-domain.md §7, "Katalog jako dane"): the types the editor lays its switches from were a table in switch_design::catalogue() and two in editor_track::standard_switch_templates(); now they are editor/data/turnouts.txt, one type a line, built into the executable as its text (CMakeLists.txt writes it out as editor_turnouts_txt.inc, as it does the icons), so the game data doesn't need it, and read once when first needed. - The format, which the templates of the user (eu07_switch_templates.txt) share: switch <name> <key> <value>... source <the rest>. A type of the catalogue gives its geometry as the instruction does (type, rail, radius, ratio, a, b, diverging, the blades tangent or secant, the cut tip of the blade; stagger and the keys of the second switch of a double one; middle and the half length of a slip; fit for the three fitted to measured tangents), the parts made of it as before; a template of the user gives its parts. What §7 asks besides the geometry, - where the source has nothing: the frog (fixed or movable), the locks (Id-4 tab. 14-3), the drive, the speed of the diverging track (ST-T1-A6 tab. 11.2), the bending (tab. 11.9), the least spacing for a crossover (tab. 11.2) and the source of the values, unconfirmed ones said so: the cut tips of SKMd-4 (190, 300, 500, 1200 m; 760 m the editor's own), the secant blades of S42 at 25' and the one fitted for S42-140-1:7, the a and b of 2500-1:26,5, the slips' blades (not found), the tip of a blade with no data by the rule sqrt(2R 0.005) - 0.125. - read_designs() reads the format, a line which isn't one left out with why; catalogue() the switches as before, in the same order, slips() the slips and the crossings, catalogue_entries() all of them, read once (secant_blade() no longer builds the catalogue at each call). - The slip curve and slip_of() moved from editor_track to switch_design, which the domain model lays its slips with (E5); editor_track keeps the names. - A template of the user with a movable nose writes frog movable, which it lost before; without one the line is what the builds before wrote (they leave out a template with a key they don't know). The lines they wrote read as they did. Tests: U: every switch of the data file the same to the bit as the catalogue of the code (kept in the test as it was), the slips and the crossings as the switch tool had them; every line read, with its source; each switch against Id-4 and ST-T1-A6: R, 1:n, a, the main track a + b, the pre-blade stretch, the blades (the tip lead + cut where the sheets give it, about sqrt(2R 0.005) - 0.125 where they don't; secant at 25'), the speed of tab. 11.2, the bending of tab. 11.9, the spacing of tab. 11.2; the rule of the tip against the sheets (190 m +3 mm, 300 m +105 mm, 500 m -56 mm, 1200 m +3 mm; the 4.5 mm rule +60, +143, -44, -49 mm); a template keeping its movable nose, an old line read as before; lines left out with why. Unit tests 1070 -> 1077.
This commit is contained in:
+14
-157
@@ -3176,81 +3176,6 @@ std::optional<editor_track::switch_template> editor_track::template_of(switch_de
|
||||
return entry;
|
||||
}
|
||||
|
||||
glm::dvec2 editor_track::slip_curve::point(double const Along) const
|
||||
{
|
||||
auto const arc = [](glm::dvec2 const &From, double const Heading, double const Radius, double const Length) {
|
||||
if (Radius <= 0.0)
|
||||
return From + glm::dvec2{std::cos(Heading), std::sin(Heading)} * Length;
|
||||
auto const to{Heading + Length / Radius};
|
||||
return From + Radius * glm::dvec2{std::sin(to) - std::sin(Heading), std::cos(Heading) - std::cos(to)};
|
||||
};
|
||||
auto const along{Along - lead};
|
||||
auto result{arc({0.0, 0.0}, 0.0, 0.0, std::min(Along, lead))};
|
||||
if (along > 0.0)
|
||||
result = arc(result, entry, radius, std::min(along, ends));
|
||||
if (along > ends)
|
||||
result = arc(result, heading(lead + ends), middle, std::min(along - ends, between));
|
||||
if (along > ends + between)
|
||||
result = arc(result, heading(lead + ends + between), radius, std::min(along - ends - between, ends));
|
||||
if (along > 2.0 * ends + between)
|
||||
result = arc(result, angle, 0.0, along - 2.0 * ends - between);
|
||||
return result;
|
||||
}
|
||||
|
||||
double editor_track::slip_curve::heading(double const Along) const
|
||||
{
|
||||
if (Along < lead)
|
||||
return 0.0;
|
||||
if (Along > length() - lead)
|
||||
return angle;
|
||||
auto const along{Along - lead};
|
||||
auto const inside{std::clamp(along - ends, 0.0, between)};
|
||||
return entry + (std::min(along, ends) + std::max(0.0, along - ends - between)) / radius + (middle > 0.0 ? inside / middle : 0.0);
|
||||
}
|
||||
|
||||
double editor_track::slip_curve::tangent() const
|
||||
{
|
||||
auto const end{point(length())};
|
||||
return end.x - end.y / std::tan(angle);
|
||||
}
|
||||
|
||||
double editor_track::slip_curve::offset() const
|
||||
{
|
||||
return glm::distance(point(length() * 0.5), glm::dvec2{tangent(), 0.0});
|
||||
}
|
||||
|
||||
editor_track::slip_curve editor_track::slip_of(double const Radius, double const Middle, double const Angle, double const Pass, double const Lead, double const Entry)
|
||||
{
|
||||
if (Entry > 0.0 && Angle * 0.5 <= Entry + 1e-6)
|
||||
return slip_of(Radius, Middle, Angle, Pass);
|
||||
auto const make = [&](double const Turn) {
|
||||
return slip_curve{Radius, Radius * Turn, Middle, Middle * (Angle - 2.0 * (Turn + Entry)), Angle, 0.0, Lead, Entry};
|
||||
};
|
||||
if (Middle < 0.0 && Angle >= 1e-6)
|
||||
{
|
||||
// a straight in the middle, as long as the arcs of Radius turning by a half of Angle pass the crossing as near
|
||||
auto low{0.0};
|
||||
auto high{4.0 * Pass / std::tan(Angle * 0.5)};
|
||||
for (int i = 0; i < 60; ++i)
|
||||
{
|
||||
auto const between{(low + high) * 0.5};
|
||||
(slip_curve{Radius, Radius * (Angle * 0.5 - Entry), 0.0, between, Angle, 0.0, Lead, Entry}.offset() > Pass ? high : low) = between;
|
||||
}
|
||||
return {Radius, Radius * (Angle * 0.5 - Entry), 0.0, (low + high) * 0.5, Angle, 0.0, Lead, Entry};
|
||||
}
|
||||
if (Middle <= 0.0 || Angle < 1e-6)
|
||||
return make(Angle * 0.5 - Entry);
|
||||
// the curve passes the crossing nearer as its end arcs turn further, the middle one being flatter
|
||||
auto low{0.0};
|
||||
auto high{Angle * 0.5 - Entry};
|
||||
for (int i = 0; i < 60; ++i)
|
||||
{
|
||||
auto const turn{(low + high) * 0.5};
|
||||
((make(turn).offset() > Pass) == (Middle > Radius) ? low : high) = turn;
|
||||
}
|
||||
return make((low + high) * 0.5);
|
||||
}
|
||||
|
||||
std::string editor_track::rail_of(TTrack const *Track)
|
||||
{
|
||||
if (Track == nullptr || (Track->iCategoryFlag & 15) != 1)
|
||||
@@ -3283,96 +3208,28 @@ std::vector<editor_track::switch_template> editor_track::standard_switch_templat
|
||||
entry->design = static_cast<int>(i);
|
||||
result.push_back(std::move(*entry));
|
||||
}
|
||||
// the slips and crossings of Id-4: the angle comes from the straights clicked, the half length from the crossing to the joint
|
||||
// to a and the label; the slips with the blades outside of the diamond have a straight in the middle of their curves, along which
|
||||
// the near rails touch. The asymmetric slips of Id-4 (1:9/1:7,5, 1:9/1:6,6) are left out, both of their curves being the same here
|
||||
struct slipping
|
||||
{
|
||||
char const *type;
|
||||
char const *name;
|
||||
double radius;
|
||||
double middle;
|
||||
double half;
|
||||
};
|
||||
slipping const slips[] = {
|
||||
{"Rkp", "60E1-190-1:9", 190.0, 0.0, 16.615},
|
||||
{"Rkp", "49E1-190-1:9", 190.0, 0.0, 16.615},
|
||||
{"Rkp", "49E1-190-1:6,6", 190.0, -1.0, 17.396},
|
||||
{"Rkp", "49E1-300-1:9", 300.0, -1.0, 22.639},
|
||||
{"Rkp", "49E1-500-1:9", 500.0, -1.0, 27.693},
|
||||
{"Rkp", "S42-230-1:9,51", 230.0, 0.0, 18.642},
|
||||
{"Rkp", "S42-265-1:10", 265.0, 0.0, 19.192},
|
||||
{"Rkpd", "60E1-190-1:9", 190.0, 0.0, 16.615},
|
||||
{"Rkpd", "49E1-190-1:9", 190.0, 0.0, 16.615},
|
||||
{"Rkpd", "49E1-190-1:6,6", 190.0, -1.0, 17.396},
|
||||
{"Rkpd", "49E1-300-1:9", 300.0, -1.0, 22.639},
|
||||
{"Rkpd", "49E1-500-1:9", 500.0, -1.0, 27.693},
|
||||
{"Rkpd", "49E1-190-1:9 gauge 1524", 190.0, 0.0, 17.420},
|
||||
{"Rkpd", "S42-205-1:9", 205.0, 0.0, 17.591},
|
||||
{"Rkpd", "S42-205-1:9 II", 205.0, 0.0, 18.394},
|
||||
{"Rkpd", "S42-230-1:9,51", 230.0, 0.0, 18.642},
|
||||
{"Rkpd", "S42-230-1:9,51 Ia", 230.0, 0.0, 18.342},
|
||||
{"Rkpd", "S42-265-1:10", 265.0, 0.0, 19.192},
|
||||
};
|
||||
auto const ratio_of = [](std::string const &Name) {
|
||||
auto const at{Name.find("1:")};
|
||||
auto number{Name.substr(at + 2)};
|
||||
std::replace(number.begin(), number.end(), ',', '.');
|
||||
return std::stod(number);
|
||||
};
|
||||
for (auto const &entry : slips)
|
||||
// the slips and crossings of the catalogue (Id-4): the angle comes from the straights clicked, the half length from the crossing to the
|
||||
// joint to a and the label; the slips with the blades outside of the diamond have a straight in the middle of their curves, along
|
||||
// which the near rails touch
|
||||
for (auto const &entry : switch_design::slips())
|
||||
{
|
||||
switch_template slip;
|
||||
slip.double_slip = true;
|
||||
slip.type = entry.type;
|
||||
slip.radius = entry.radius;
|
||||
slip.middle = entry.middle;
|
||||
slip.a = entry.half;
|
||||
slip.ratio = ratio_of(entry.name);
|
||||
slip.rail = std::string{entry.name}.substr(0, std::string{entry.name}.find('-'));
|
||||
slip.label = std::string{entry.type} + ' ' + entry.name + format(" a %.3f", entry.half) + (slip.type == "Rkp" ? " single slip" : " double slip") +
|
||||
(entry.middle < 0.0 ? ", the blades outside of the diamond" : "") +
|
||||
(slip.type == "Rkp" ? " (click at a crossing of two straights, on the side of the joined tracks, or drag it out on a straight)" : " (click at a crossing of two straights, or drag it out on a straight)");
|
||||
slip.a = entry.a;
|
||||
slip.ratio = entry.ratio;
|
||||
slip.rail = entry.rail;
|
||||
// the name of the catalogue after its type, which the label puts before it
|
||||
auto const name{entry.name.starts_with(entry.type + ' ') ? entry.name.substr(entry.type.size() + 1) : entry.name};
|
||||
if (slip.type == "Skrz")
|
||||
slip.label = std::string{"Skrz "} + name + format(" a %.3f", entry.a) + " crossing (click at a crossing of two straights, or drag it out on a straight)";
|
||||
else
|
||||
slip.label = slip.type + ' ' + name + format(" a %.3f", entry.a) + (slip.type == "Rkp" ? " single slip" : " double slip") + (entry.middle < 0.0 ? ", the blades outside of the diamond" : "") +
|
||||
(slip.type == "Rkp" ? " (click at a crossing of two straights, on the side of the joined tracks, or drag it out on a straight)" : " (click at a crossing of two straights, or drag it out on a straight)");
|
||||
result.push_back(slip);
|
||||
}
|
||||
struct crossing
|
||||
{
|
||||
char const *name;
|
||||
double half;
|
||||
};
|
||||
crossing const crossings[] = {
|
||||
{"60E1-1:9", 16.615},
|
||||
{"60E1-1:4,444", 10.907},
|
||||
{"49E1-1:2,9008", 6.904},
|
||||
{"49E1-1:3,224", 7.920},
|
||||
{"49E1-1:3,683", 9.881},
|
||||
{"49E1-1:4,44", 10.907},
|
||||
{"49E1-1:6,6", 17.396},
|
||||
{"49E1-1:7,5", 18.512},
|
||||
{"49E1-1:9", 16.615},
|
||||
{"49E1-1:9 long", 17.016},
|
||||
{"49E1-1:18,5", 32.409},
|
||||
{"S42-1:2", 5.743},
|
||||
{"S42-1:2,9008", 8.250},
|
||||
{"S42-1:3,429", 9.681},
|
||||
{"S42-1:3,43", 8.421},
|
||||
{"S42-1:4,44", 11.788},
|
||||
{"S42-1:4,444 gauge 1524", 12.189},
|
||||
{"S42-1:7", 12.932},
|
||||
{"S42-1:9", 17.591},
|
||||
{"S42-1:10", 19.192},
|
||||
};
|
||||
for (auto const &entry : crossings)
|
||||
{
|
||||
switch_template plain;
|
||||
plain.double_slip = true;
|
||||
plain.type = "Skrz";
|
||||
plain.a = entry.half;
|
||||
plain.ratio = ratio_of(entry.name);
|
||||
plain.rail = std::string{entry.name}.substr(0, std::string{entry.name}.find('-'));
|
||||
plain.label = std::string{"Skrz "} + entry.name + format(" a %.3f", entry.half) + " crossing (click at a crossing of two straights, or drag it out on a straight)";
|
||||
result.push_back(plain);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user