mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 22:07:55 +01:00
75ce03b95a
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.
159 lines
6.1 KiB
C++
159 lines
6.1 KiB
C++
/*
|
|
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
|