mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 12:57:06 +01:00
feat(editor): the parallel tool beside a line of the model lays a line of the model, its arcs concentric
Continues E4b (editor-tracks-domain.md §8, "Odsuń tor równoległy"): with the editing on the model on, the parallel tool beside a track of a line of the model lays a new line of the model at the spacing, one create_line, checked by the norms. - editor/layout/layoutParallel: the line alongside a line, pure: the legs of the tangents offset, the vertices where the offset legs meet, the arcs concentric with the line's, the radius less on the inside of a curve and more on the outside, the transitions recomputed from the shift of the arc so the centre stays the line's; the cant and the class of the line, its grade breaks at the same share of the length. In a curve the spacing is widened by the widening of the gauge of both tracks on the sides facing each other (PLK tom II annex 1, gauge::curve_widening, under R 250 m), where the transitions of the curve can take it; where they can't, told so. The norms of the track geometry have no spacing of their own yet. - The tool tells the line laid, the spacing in each curve widened, what the norms warn of; refused, why, nothing changed. Self-test: expect modelspacing <line> <other> <m> <low> <high>. The case m_13_parallel (a line laid on the inside of the curve of a line of the model, 4.5 m on the straight and in the arc, one step). Tests: U: the line alongside a straight and alongside three curves on both sides, laid, the arcs concentric within 2 mm; alongside a curve of R 200 m the spacing widened by the gauges, the transitions longer on the inside and shorter on the outside; not widened where a curve has no transitions, told why. lang/editor_pl.po: the Polish of the new texts.
This commit is contained in:
@@ -223,6 +223,7 @@ set(SOURCES
|
||||
"editor/layout/layoutTurnout.cpp"
|
||||
"editor/layout/layoutGenerator.cpp"
|
||||
"editor/layout/layoutConnection.cpp"
|
||||
"editor/layout/layoutParallel.cpp"
|
||||
"editor/layout/layoutRecognition.cpp"
|
||||
"editor/layout/layoutLegacy.cpp"
|
||||
"editor/layout/layoutAnchors.cpp"
|
||||
|
||||
@@ -1406,6 +1406,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
void render_switch_record(TTrack const &Track) const;
|
||||
void route_store();
|
||||
bool digitize_drawn(std::vector<TTrack *> const &Created, bool const Alone = true) override;
|
||||
bool model_parallel(TTrack &Source, double const Spacing, int const Side, std::string &Status, std::string &Error) override;
|
||||
bool digitize_chain(editor_track::chain const &Chain, std::string *Reason = nullptr, TTrack **Culprit = nullptr);
|
||||
int digitize_parts(editor_track::chain const &Chain, std::string *Reason, int &Skipped);
|
||||
// the lines kept, the paths left out
|
||||
|
||||
@@ -1682,6 +1682,20 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm
|
||||
expectation(marked.size() == wanted, "handlines", std::to_string(marked.size()) + lines, std::to_string(wanted));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (what == "modelspacing")
|
||||
{
|
||||
// how far the other line runs from the point of the line at the chainage, within the bounds
|
||||
unsigned line{0}, other{0};
|
||||
double chainage{0.0}, low{0.0}, high{0.0};
|
||||
words >> line >> other >> chainage >> low >> high;
|
||||
auto const *one{model_network().find(static_cast<layout::line_id>(line))};
|
||||
auto const *two{model_network().find(static_cast<layout::line_id>(other))};
|
||||
auto got{std::numeric_limits<double>::quiet_NaN()};
|
||||
if (one != nullptr && two != nullptr && one->solved.valid() && two->solved.valid())
|
||||
layout::chainage_of(two->solved, one->solved.position(std::clamp(chainage, 0.0, one->solved.length)), &got);
|
||||
expectation(got >= low && got <= high, format("modelspacing %u %u %.1f", line, other, chainage), format("%.4f", got), format("%.4f .. %.4f", low, high));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (what == "modelnodes")
|
||||
{
|
||||
// the nodes of the model: a line laid on from the free end of another one shares the node there
|
||||
|
||||
@@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "application/editormodeshared.h"
|
||||
#include "application/editoruilayer.h"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/layout/layoutParallel.hpp"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/translation.h"
|
||||
#include "world/Track.h"
|
||||
@@ -360,3 +361,52 @@ void editor_mode::render_model_curves()
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
|
||||
// a track laid alongside a line of the model by the parallel tool
|
||||
|
||||
bool editor_mode::model_parallel(TTrack &Source, double const Spacing, int const Side, std::string &Status, std::string &Error)
|
||||
{
|
||||
auto const *managed{model_track(&Source)};
|
||||
if (managed == nullptr)
|
||||
return false;
|
||||
Status.clear();
|
||||
Error.clear();
|
||||
if (layout::owner_of(model_network(), managed->line) != nullptr)
|
||||
{
|
||||
Error = STR_C("A turnout has no line of its own: select a track of a line beside it");
|
||||
return true;
|
||||
}
|
||||
// the side of the tool and the left of the model: the same offset of the axis
|
||||
auto const plan{layout::parallel_line(model_network(), managed->line, Spacing * static_cast<double>(Side))};
|
||||
if (false == plan.valid)
|
||||
{
|
||||
for (auto const &error : plan.errors)
|
||||
Error += (Error.empty() ? "" : "\n") + model_tr(error);
|
||||
return true;
|
||||
}
|
||||
model_context context;
|
||||
context.surface = model_surface_of(Source);
|
||||
auto const line{managed->line};
|
||||
auto const spacings{plan.spacings};
|
||||
context.done = [this, &Status, line, Spacing, spacings](std::vector<TTrack *> const &Created) {
|
||||
if (false == Created.empty())
|
||||
{
|
||||
m_node = Created.back();
|
||||
ui()->set_node(m_node);
|
||||
}
|
||||
Status = format(STR_C("A line alongside line %s, %.2f m away"), line_name(line).c_str(), Spacing);
|
||||
for (std::size_t i = 0; i < spacings.size(); ++i)
|
||||
if (spacings[i] > Spacing + 1e-4)
|
||||
Status += "\n" + format(STR_C("In the curve at W%zu: %.3f m"), i + 1, spacings[i]);
|
||||
Status += "\n" + model_shown();
|
||||
for (auto const ¬ice : model_notices())
|
||||
Status += "\n" + notice;
|
||||
};
|
||||
model_run({plan.command}, context);
|
||||
if (model_refused())
|
||||
Error = model_shown();
|
||||
for (auto const ¬e : plan.notes)
|
||||
(model_refused() ? Error : Status) += "\n" + model_tr(note);
|
||||
WriteLog(format("Editor: model: a line alongside line %s, %.2f m to the %s: %s", line_name(line).c_str(), Spacing, Side > 0 ? "right" : "left", editor_selftest::one_line(model_message()).c_str()), logtype::generic);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -326,6 +326,12 @@ void parallel_tool::parallel_update()
|
||||
void parallel_tool::parallel_build()
|
||||
{
|
||||
auto &tool{m_parallel};
|
||||
// beside a line of the model: a line of the model at the spacing, its curves concentric, checked by the norms
|
||||
if (auto *source{parallel_source()}; source != nullptr && m_design.model_parallel(*source, tool.spacing, tool.side, tool.status, tool.error))
|
||||
{
|
||||
tool.built_for = nullptr;
|
||||
return;
|
||||
}
|
||||
parallel_update();
|
||||
if (tool.pieces.empty())
|
||||
return;
|
||||
|
||||
@@ -262,6 +262,10 @@ class editor_track_design
|
||||
virtual alignment::limits const &route_norms() const = 0;
|
||||
virtual bool digitize_drawn(std::vector<TTrack *> const &Created, bool const Alone = true) = 0;
|
||||
virtual void straight_refresh() = 0;
|
||||
// a track laid alongside a line of the model by its command, with the editing on the model: false where the source isn't a track of one,
|
||||
// for the old way. Status: what came of it; Error: why it was refused. Side: 1 to the right of the line, -1 to the left, as the parallel
|
||||
// tool takes them
|
||||
virtual bool model_parallel(TTrack &Source, double const Spacing, int const Side, std::string &Status, std::string &Error) = 0;
|
||||
|
||||
protected:
|
||||
~editor_track_design() = default;
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "editor/layout/layoutParallel.hpp"
|
||||
#include "editor/editorGauge.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
|
||||
namespace layout
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// m the arc of a curve is moved in from its tangents by a transition of the length: the shift of the clothoid, L^2 / 24 R, as the cubic
|
||||
// parabola has it too
|
||||
double shift_of(double const Radius, double const Transition)
|
||||
{
|
||||
return Radius > 0.0 ? Transition * Transition / (24.0 * Radius) : 0.0;
|
||||
}
|
||||
|
||||
// the transition giving the shift at the radius
|
||||
double transition_of(double const Radius, double const Shift)
|
||||
{
|
||||
return Shift > 0.0 ? std::sqrt(24.0 * Radius * Shift) : 0.0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
parallel_plan parallel_line(network const &Network, line_id const Line, double const Offset, bool const Widen)
|
||||
{
|
||||
parallel_plan result;
|
||||
auto const *line{Network.find(Line)};
|
||||
if (line == nullptr)
|
||||
{
|
||||
result.errors.push_back(std::format("there's no line {}", number(Line)));
|
||||
return result;
|
||||
}
|
||||
auto const *start{Network.find(line->start)};
|
||||
auto const *end{Network.find(line->end)};
|
||||
if (start == nullptr || end == nullptr || false == line->solved.valid())
|
||||
{
|
||||
result.errors.push_back(std::format("line {} isn't laid", number(Line)));
|
||||
return result;
|
||||
}
|
||||
if (std::abs(Offset) < 0.1)
|
||||
{
|
||||
result.errors.push_back(std::format("a spacing of {:.2f} m", std::abs(Offset)));
|
||||
return result;
|
||||
}
|
||||
// the polygon of the tangents and the directions of its legs
|
||||
std::vector<glm::dvec2> corners{{start->position.x, start->position.z}};
|
||||
for (auto const &vertex : line->shape.vertices)
|
||||
corners.push_back(vertex.point);
|
||||
corners.push_back({end->position.x, end->position.z});
|
||||
std::vector<glm::dvec2> legs;
|
||||
for (std::size_t i = 0; i + 1 < corners.size(); ++i)
|
||||
{
|
||||
auto const leg{corners[i + 1] - corners[i]};
|
||||
if (glm::length(leg) < 1e-9)
|
||||
{
|
||||
result.errors.push_back(std::format("line {} has a leg of no length", number(Line)));
|
||||
return result;
|
||||
}
|
||||
legs.push_back(glm::normalize(leg));
|
||||
}
|
||||
auto &command{result.command};
|
||||
auto const startleft{left_of(legs.front())};
|
||||
auto const endleft{left_of(legs.back())};
|
||||
command.start = {start->position.x + startleft.x * Offset, start->position.y, start->position.z + startleft.y * Offset};
|
||||
command.end = {end->position.x + endleft.x * Offset, end->position.y, end->position.z + endleft.y * Offset};
|
||||
auto const spacing{std::abs(Offset)};
|
||||
for (std::size_t i = 0; i < line->shape.vertices.size(); ++i)
|
||||
{
|
||||
auto const &source{line->shape.vertices[i]};
|
||||
auto const &before{legs[i]};
|
||||
auto const &after{legs[i + 1]};
|
||||
auto const deflection{geometry::signed_angle(before, after)};
|
||||
vertex made{source};
|
||||
made.id = vertex_id::none;
|
||||
// where the offset legs meet: the vertex moved along the bisector of its legs
|
||||
auto const turn{1.0 + glm::dot(before, after)};
|
||||
if (turn < 1e-6)
|
||||
{
|
||||
result.errors.push_back(std::format("line {} turns back at its vertex {}", number(Line), i + 1));
|
||||
return result;
|
||||
}
|
||||
made.point = source.point + (left_of(before) + left_of(after)) * (Offset / turn);
|
||||
if (std::abs(deflection) < 1e-12)
|
||||
{
|
||||
command.vertices.push_back(made);
|
||||
result.spacings.push_back(spacing);
|
||||
continue;
|
||||
}
|
||||
// the new track on the inside of the curve, or on the outside
|
||||
auto const inner{(deflection > 0.0) == (Offset > 0.0)};
|
||||
auto const radius{source.radius};
|
||||
// widened by what the gauge of each track widens by on the side of the other one: the inner track on its outer side, the outer
|
||||
// track on its inner side
|
||||
double widening{0.0};
|
||||
if (Widen)
|
||||
{
|
||||
auto const inside{inner ? radius - spacing : radius};
|
||||
auto const outside{inner ? radius : radius + spacing};
|
||||
widening = gauge::curve_widening(std::max(1.0, inside), false) + gauge::curve_widening(outside, true);
|
||||
}
|
||||
auto const shift_in{shift_of(radius, source.transition_in)};
|
||||
auto const shift_out{shift_of(radius, source.transition_out)};
|
||||
// the arcs concentric: the centre the same distance from the offset tangents as the arc of the line is from its own, the arc
|
||||
// nearer the other track by the widening; on the outside its shift less by it, which a curve with no transition to take it from
|
||||
// hasn't, nor one whose transitions are shorter than that
|
||||
if (widening > 0.0 && (source.transition_in <= 0.0 || source.transition_out <= 0.0 || (false == inner && std::min(shift_in, shift_out) < widening)))
|
||||
{
|
||||
result.notes.push_back(std::format("the spacing in the curve at vertex {} isn't widened by {:.0f} mm: its transitions can't take it", i + 1, widening * 1000.0));
|
||||
widening = 0.0;
|
||||
}
|
||||
made.radius = inner ? radius - spacing - widening : radius + spacing + widening;
|
||||
if (made.radius < 1.0)
|
||||
{
|
||||
result.errors.push_back(std::format("the curve at vertex {} would be of a radius of {:.1f} m alongside", i + 1, made.radius));
|
||||
return result;
|
||||
}
|
||||
auto const change{inner ? widening : -widening};
|
||||
made.transition_in = source.transition_in > 0.0 ? transition_of(made.radius, shift_in + change) : 0.0;
|
||||
made.transition_out = source.transition_out > 0.0 ? transition_of(made.radius, shift_out + change) : 0.0;
|
||||
command.vertices.push_back(made);
|
||||
result.spacings.push_back(spacing + widening);
|
||||
}
|
||||
// the grade line as the line's, its breaks where they lie across, the same share of the length along it
|
||||
double across{0.0};
|
||||
for (std::size_t i = 0; i + 1 < corners.size(); ++i)
|
||||
across += glm::distance(i == 0 ? glm::dvec2{command.start.x, command.start.z} : command.vertices[i - 1].point, i + 1 < corners.size() - 1 ? command.vertices[i].point : glm::dvec2{command.end.x, command.end.z});
|
||||
double polygon{0.0};
|
||||
for (std::size_t i = 0; i + 1 < corners.size(); ++i)
|
||||
polygon += glm::distance(corners[i], corners[i + 1]);
|
||||
for (auto grade : line->shape.grades)
|
||||
{
|
||||
grade.chainage *= polygon > 0.0 ? across / polygon : 1.0;
|
||||
command.grades.push_back(grade);
|
||||
}
|
||||
command.transition = line->shape.transition;
|
||||
command.ramp = line->shape.ramp;
|
||||
command.category = line->category;
|
||||
command.chainage_start = line->chainage_start;
|
||||
result.valid = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace layout
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "editor/layout/layoutCommands.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// A track laid alongside a line of the track geometry (editor-tracks-domain.md §8, "Odsuń tor równoległy"): a new line at a constant
|
||||
// spacing, its straights offset and its arcs concentric with the line's, the radius less on the inside of a curve and more on the outside,
|
||||
// the transition curves recomputed so the arcs stay concentric: the shift of the arc from its tangents taken so its centre is the line's.
|
||||
// In a curve the spacing is widened, where the line's curve has transitions to take it, by the widening of the gauge of both tracks on the
|
||||
// sides facing each other (PLK tom II annex 1, editorGauge.hpp): the norms of the track geometry have no spacing of their own yet. The new
|
||||
// line is a create_line command, checked by the norms when it's carried out.
|
||||
namespace layout
|
||||
{
|
||||
|
||||
struct parallel_plan
|
||||
{
|
||||
bool valid{false};
|
||||
create_line command;
|
||||
std::vector<std::string> errors; // why there's none
|
||||
std::vector<std::string> notes; // a curve the spacing isn't widened in, and why
|
||||
std::vector<double> spacings; // m, in the arc of each curve, the widening with it
|
||||
};
|
||||
|
||||
// the line alongside the line at the offset, m, above 0 to its left as it runs (left_of), its spacing in the curves widened where Widen
|
||||
parallel_plan parallel_line(network const &Network, line_id const Line, double const Offset, bool const Widen = true);
|
||||
|
||||
} // namespace layout
|
||||
@@ -15131,6 +15131,15 @@ msgstr "Zgodne z normami"
|
||||
msgid "Curves added or taken out here aren't applied to a line of the model: add a curve or take one out with the buttons of the line"
|
||||
msgstr "Łuki dodane lub usunięte tutaj nie trafiają do linii modelu: dodaj łuk albo go usuń przyciskami linii"
|
||||
|
||||
msgid "A line alongside line %s, %.2f m away"
|
||||
msgstr "Linia obok linii %s, w odległości %.2f m"
|
||||
|
||||
msgid "In the curve at W%zu: %.3f m"
|
||||
msgstr "W łuku przy W%zu: %.3f m"
|
||||
|
||||
msgid "A turnout has no line of its own: select a track of a line beside it"
|
||||
msgstr "Rozjazd nie ma własnej linii: zaznacz tor linii obok niego"
|
||||
|
||||
msgid "line {1} at {2} m: {3}"
|
||||
msgstr "linia {1} w {2} m: {3}"
|
||||
|
||||
|
||||
@@ -196,3 +196,4 @@ and the rest of the editing on the model (E4b), with the setting on:
|
||||
| `m_10_grade_curves` | a break of the grade line put in the profile tool is the line's command, one step; one the model can't lay refused; a curve added in the route design, bent, taken out, a step each |
|
||||
| `m_11_vertex_drag` | the vertex of a curve dragged on the map with the mouse: the line as the model would lay it tried while it's dragged, one command let go |
|
||||
| `m_12_lay_from_end` | a line laid on from the free end of a line of the model shares its node, the ends to the bit before and after a reopen |
|
||||
| `m_13_parallel` | the parallel tool beside a line of the model lays a line of the model, its arc concentric at the spacing, one step |
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Editing on the model (E4b): the parallel tool beside a line of the model lays a line of the model at the spacing: its straights offset,
|
||||
# its arc concentric with the line's, the radius less on the inside of the curve, the transitions recomputed, the spacing in the curve
|
||||
# widened by the widening of the gauge of both tracks (none at this radius); checked by the norms, one step. The empty ground east of k0..k3 (x 800..1300)
|
||||
wait 5
|
||||
modelediting 1
|
||||
layclicks 0 600 800 -300 800 100 1100 400
|
||||
wait 2
|
||||
expect modellines 1
|
||||
expect steps 1
|
||||
modelselect @1.0
|
||||
# on the inside of the curve, which turns to +x: to the right of the line as it runs
|
||||
parallel 4.5 -1
|
||||
wait 2
|
||||
modeltracks
|
||||
expect modelrefused 0
|
||||
expect modellines 2
|
||||
expect managed @2.0 2
|
||||
expect modelends
|
||||
expect steps 2
|
||||
# 4.5 m on the straight and in the arc, concentric (no widening of the gauge in a curve of R 250 m or more)
|
||||
expect modelspacing 1 2 10 4.4999 4.5001
|
||||
expect modelspacing 1 2 400 4.498 4.502
|
||||
undo
|
||||
wait 2
|
||||
expect modellines 1
|
||||
expect steps 1
|
||||
quit
|
||||
@@ -65,6 +65,7 @@ add_executable(${UNIT_TESTS_NAME}
|
||||
"${CMAKE_SOURCE_DIR}/editor/layout/layoutTurnout.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/editor/layout/layoutGenerator.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/editor/layout/layoutConnection.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/editor/layout/layoutParallel.cpp"
|
||||
# the old tracks taken over: their recognition, the anchors of the lineside objects (test_takeover_*.cpp)
|
||||
"${CMAKE_SOURCE_DIR}/editor/layout/layoutRecognition.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/editor/layout/layoutLegacy.cpp"
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "layout_fixture.h"
|
||||
#include "scratch.h"
|
||||
|
||||
#include "editor/editorGauge.hpp"
|
||||
#include "editor/layout/layoutParallel.hpp"
|
||||
#include "editor/layout/layoutTurnout.hpp"
|
||||
#include "editor/project/projectSession.hpp"
|
||||
|
||||
@@ -138,6 +140,120 @@ TEST_CASE("layout editing: a line laid on from the free end of another one share
|
||||
CHECK(model.state().nodes().size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("layout editing: the line alongside a straight and alongside the curves, the arcs concentric, the spacing widened in the curves") {
|
||||
layout::model model;
|
||||
REQUIRE(model.execute(straight_along_z(0.0, 0.0, 400.0)).done);
|
||||
auto const straight{last_line(model)};
|
||||
// to the left of a line running along z: toward -x
|
||||
auto const beside{layout::parallel_line(model.state(), straight, 4.5)};
|
||||
REQUIRE(beside.valid);
|
||||
CHECK(beside.command.start == glm::dvec3{-4.5, 10.0, 0.0});
|
||||
CHECK(beside.command.end == glm::dvec3{-4.5, 10.0, 400.0});
|
||||
CHECK(beside.command.vertices.empty());
|
||||
CHECK_FALSE(layout::parallel_line(model.state(), straight, 0.0).valid);
|
||||
CHECK_FALSE(layout::parallel_line(model.state(), line_id{99}, 4.0).valid);
|
||||
|
||||
REQUIRE(model.execute(three_curves()).done);
|
||||
auto const curves{last_line(model)};
|
||||
auto const &source{*model.state().find(curves)};
|
||||
for (double const offset : {4.0, -4.0}) {
|
||||
auto const plan{layout::parallel_line(model.state(), curves, offset)};
|
||||
REQUIRE(plan.valid);
|
||||
REQUIRE(plan.command.vertices.size() == source.shape.vertices.size());
|
||||
REQUIRE(plan.spacings.size() == source.shape.vertices.size());
|
||||
auto copy{model};
|
||||
auto const laid{copy.execute(plan.command)};
|
||||
REQUIRE_MESSAGE(laid.done, reasons_of(laid));
|
||||
auto const &alongside{*copy.state().find(last_line(copy))};
|
||||
for (std::size_t i = 0; i < source.shape.vertices.size(); ++i) {
|
||||
auto const &vertex{source.shape.vertices[i]};
|
||||
auto const &made{plan.command.vertices[i]};
|
||||
// the inside of the curve the side it turns to: the radius less by the spacing and the widening of both gauges
|
||||
auto const inner{std::abs(made.radius) < vertex.radius};
|
||||
auto const widening{gauge::curve_widening(inner ? made.radius : vertex.radius, false) + gauge::curve_widening(inner ? vertex.radius : made.radius, true)};
|
||||
CHECK(plan.spacings[i] == doctest::Approx(4.0 + widening).epsilon(1e-3));
|
||||
CHECK(std::abs(made.radius - vertex.radius) == doctest::Approx(4.0 + widening).epsilon(1e-6));
|
||||
CHECK(made.cant == vertex.cant);
|
||||
// the arcs concentric: the middle of the arc alongside as far from the line's as the spacing in the curve, within 2 mm
|
||||
double middle{-1.0};
|
||||
for (auto const &e : source.solved.elements) {
|
||||
if (e.role == layout::element_role::arc && e.vertex == layout::number(vertex.id)) {
|
||||
middle = e.chainage + 0.5 * e.length;
|
||||
}
|
||||
}
|
||||
REQUIRE(middle >= 0.0);
|
||||
double distance{0.0};
|
||||
layout::chainage_of(alongside.solved, source.solved.position(middle), &distance);
|
||||
CHECK(distance == doctest::Approx(plan.spacings[i]).epsilon(0.002 / 4.0));
|
||||
}
|
||||
// on the straights, the spacing as asked
|
||||
double distance{0.0};
|
||||
layout::chainage_of(alongside.solved, source.solved.position(5.0), &distance);
|
||||
CHECK(distance == doctest::Approx(4.0).epsilon(1e-6));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("layout editing: alongside a curve under 250 m the spacing is widened by the gauges of both tracks, on the inside by a longer transition") {
|
||||
// a siding of 30 km/h with a curve of R 200 m and transitions of 30 m: the gauge widens there (PLK tom II annex 1)
|
||||
layout::create_line sharp;
|
||||
sharp.start = {0.0, 0.0, 0.0};
|
||||
sharp.end = {400.0, 0.0, 400.0};
|
||||
sharp.category = line_class();
|
||||
sharp.category.vmax = 30.0;
|
||||
sharp.category.track = norms::track_kind::side;
|
||||
layout::vertex corner;
|
||||
corner.point = {0.0, 400.0};
|
||||
corner.radius = 200.0;
|
||||
corner.transition_in = corner.transition_out = 30.0;
|
||||
sharp.vertices = {corner};
|
||||
layout::model model;
|
||||
auto const laid{model.execute(sharp)};
|
||||
REQUIRE_MESSAGE(laid.done, reasons_of(laid));
|
||||
auto const id{last_line(model)};
|
||||
auto const &source{*model.state().find(id)};
|
||||
// the curve turns from +z to +x: to the left of the line (above 0) is the outside of it
|
||||
for (double const offset : {-4.0, 4.0}) {
|
||||
auto const plan{layout::parallel_line(model.state(), id, offset)};
|
||||
REQUIRE(plan.valid);
|
||||
REQUIRE(plan.spacings.size() == 1);
|
||||
auto const inner{plan.command.vertices.front().radius < 200.0};
|
||||
// of the inner track on its outer side and of the outer one on its inner side, at their radii the spacing apart
|
||||
auto const widening{inner ? gauge::curve_widening(196.0, false) + gauge::curve_widening(200.0, true) : gauge::curve_widening(200.0, false) + gauge::curve_widening(204.0, true)};
|
||||
CHECK(widening > 0.1);
|
||||
CHECK(plan.spacings.front() == doctest::Approx(4.0 + widening).epsilon(1e-6));
|
||||
CHECK(plan.notes.empty());
|
||||
// on the inside the transitions longer, keeping the arc concentric nearer the line; on the outside shorter
|
||||
CHECK((plan.command.vertices.front().transition_in > 30.0) == inner);
|
||||
auto copy{model};
|
||||
auto const alongside{copy.execute(plan.command)};
|
||||
REQUIRE_MESSAGE(alongside.done, reasons_of(alongside));
|
||||
auto const &made{copy.state().find(last_line(copy))->solved};
|
||||
double middle{0.0};
|
||||
for (auto const &e : source.solved.elements) {
|
||||
if (e.role == layout::element_role::arc) {
|
||||
middle = e.chainage + 0.5 * e.length;
|
||||
}
|
||||
}
|
||||
double distance{0.0};
|
||||
layout::chainage_of(made, source.solved.position(middle), &distance);
|
||||
CHECK(distance == doctest::Approx(plan.spacings.front()).epsilon(0.003 / 4.0));
|
||||
}
|
||||
// with no transitions to take it, the spacing isn't widened, and told why
|
||||
auto plain{sharp};
|
||||
plain.vertices.front().transition_in = plain.vertices.front().transition_out = 0.0;
|
||||
plain.start.x += 1000.0;
|
||||
plain.end.x += 1000.0;
|
||||
plain.vertices.front().point.x += 1000.0;
|
||||
layout::model other;
|
||||
auto const plain_laid{other.execute(plain)};
|
||||
if (plain_laid.done) {
|
||||
auto const plan{layout::parallel_line(other.state(), last_line(other), -4.0)};
|
||||
REQUIRE(plan.valid);
|
||||
CHECK(plan.spacings.front() == doctest::Approx(4.0));
|
||||
CHECK(plan.notes.size() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("project session: the switch track of a turnout made by the session, the tracks of a line written into two files recorded") {
|
||||
test::scratch_folder folder{"layout_editing_session"};
|
||||
folder.write("mapa.scn", "// a new scenery\n");
|
||||
|
||||
Reference in New Issue
Block a user