mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 01:32:43 +01:00
db5a171ccd
Stage E1 of editor-tracks-domain.md (§3, §6): the norms stand on their own in editor/norms, with no scene, no tracks and no user interface, so they are tested whole in tests/unit. Nothing of the editor uses them yet but the report of the next commit; alignment::limits stays as the laying tools use it. - The profiles are tables of rows (normsTables.cpp). A row holds the limits of PREFER / WARN / BLOCK of one parameter where its conditions hold (a band of the speed, of the radius or of the load, main or side track, the traffic, a switch and its frog, a crossing, an expansion device, a platform, a station track, ballastless track, crest or sag), with the table or the paragraph of its document. Where several rows hold the strictest limit of each tier counts. A cell can be unconfirmed: it warns, never blocks. - PLK, ST-T1-A6 v1.0: P0 PREFER, P1 WARN, P2 BLOCK; tab. 8.1, 9.1, 9.2, 9.6 - 9.8, 9.10, 9.12 - 9.16, 10.1, 10.2, formula 9.8. - TSI only, Reg. 1299/2014 consolidated 28.9.2023: BLOCK; 4.2.3.3 - 4.2.3.5, 4.2.4.2 - 4.2.4.4. - EN 13803-1:2010 5.2.1 - 5.2.5: normal WARN, exceptional BLOCK. - CH, AB-EBV AB 17 (Normalspur, 1.7.2024): Grenzwert im Normalfall WARN, maximaler Grenzwert BLOCK. - In every profile the global hard limits of §6.3: the TSI rows and the cant gradient of 2.5 mm/m (EN 13803-1 5.2.5, the twist). - The line class: Vmax, Vmin of the slow trains (by tab. 8.1 when not given), passenger / mixed / freight, main or side track, the load, and what holds along the line (platform, station, ballastless, suburban, tilting). - One engine (normsEngine.cpp) over a line of elements (straights, transitions, arcs, the curvature changing evenly along each), its cant (points, a step being two at one chainage) and its grade line: I at Vmax and E at Vmin; dI/dt along the transitions and the ramps; ΔI at every jump of the curvature or of the cant, the jumps closer than the intermediate length of the profile (tab. 9.16) taken together while the deficiency keeps changing one way (9.11 pkt 8 - 13); dD/ds and dD/dt along the ramps, a step of the cant as its twist on the 5 m base; the lengths of the straights, arcs and transitions and the shift of the arc; R; D with (R - 50) / 1.5 and the least cant; Rv and the breaks of the grade over 2 per mille; the held grades. A finding names the parameter, the value, the limit, the tier, the profile, the source, confirmed or not, hard or not, and the chainage. The module makes no text, its users write the messages. - Areas (§6.4): the default profile of the scenery, areas outlined in the plan, lines by name (a line's own wins). An element with its ends under two profiles is checked against both, the worse kept (the stricter one); an arc across a boundary is a warning. - describe() reads a line from samples along it (the curvature, the cant and the grade simplified by Douglas and Peucker), with a precision of 0.2 % for the values measured on it. - The formulas of ST-T1-A6 9.1 - 9.10: Deq, Dreg, I, E, Dmin, Dmax, Rmin, V. The sources, and what they gave: - The cells of ST-T1-A6 spanning two or three columns (tab. 9.1, 9.6, 9.7, 9.13 - 9.15, 10.1, 10.2; §6.5 pkt 4) were read on the pages of the PDF. Tab. 9.15 has for the connections of tracks P0 = P1 = 80 mm at 100 < V <= 160 and 60 mm at 160 < V <= 200, P2 160 - 0.35 V; the table of §6.2 has P1 = 160 - 0.35 V there. Tab. 9.1 has P1 = P0 (one cell), not "-". - TSI tab. 8 (§6.5 pkt 3): the 153 mm spans both columns up to 300 km/h, 100 mm only above 300 km/h. - Unconfirmed, warning only: tab. 9.8, 5 < q <= 10, P0 95 mm, and tab. 9.7, movable frog 230 < V <= 250, P2 110 mm (as printed, out of line with the rows around them); EN 13803-2:2006+A1:2009 7.1.3, ΔI of the plain line 50 / 40 / 30 mm, read from a garbled preview. - Not there: ST-T1-A6 tab. 9.4 (a picture); EN 13803-1 dD/dt, dI/dt, ΔI in S&C, element lengths, Rv and grades (beyond the part of the standard published as its preview); AB-EBV a limit of the grade of a line, the least cant, the table of the buffer locking of 5.4.2; the TSI has no dD/ds, dD/dt nor dI/dt. DB (Ril 800.0110) is left out: it isn't published, its values are known from secondary sources only. - Simplified: the (R - 50) / 1.5 of the TSI holds for every R < 305 m of mixed and freight traffic, leaving out its condition of a ramp steeper than 1 mm/m; the intermediate element of tab. 9.16 between transitions is the one of tab. 9.1 at P2 (tab. 9.10 at P2 would do there); a switch has a fixed frog unless the track says it moves; the track is ballasted unless the class says not. Tests: test_norms_tables.cpp, every value of the PLK tables and of the TSI with its table in the name of the test, the edges of the bands (a speed on the boundary, R 300, 250 and 200 m), some of EN and AB-EBV; test_norms_engine.cpp, the examples of ST-T1-A6 (Z1-1, Z1-2, załącznik 2, the ramps of Z3-2 and Z3-3), I at Vmax and E at Vmin, ΔI of arcs turning alike and the other way, taken together over a short straight or not, dD/ds, dD/dt, a step of the cant, dI/dt, the lengths, the vertical curves, the areas and the boundary, describe().
567 lines
21 KiB
C++
567 lines
21 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/norms/norms.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <tuple>
|
|
|
|
// the engine: one for all the profiles (editor-tracks-domain.md §6.3). Along the line it finds the cant deficiency at the highest speed
|
|
// and the cant excess at the speed of the slow trains, the abrupt changes of the cant deficiency at every jump of the curvature or of
|
|
// the cant, taken together over elements shorter than the profile lets them be taken apart, the gradient and the rate of change of
|
|
// the cant along the ramps, the rate of change of the cant deficiency along the transitions and the ramps, the lengths of the
|
|
// elements, the radii, the cant, the vertical curves and the grades
|
|
namespace norms
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
double constexpr kC{11.8};
|
|
double constexpr kSame{1e-6}; // m: points closer along the line are one
|
|
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
|
|
double constexpr kTwistBase{5.0}; // m: a step of the cant felt over the base of the twist, ST-T1-A6 tab. 9.12
|
|
double constexpr kBreak{0.002}; // a change of the grade up to 2 per mille needn't be rounded (ST-T1-A6 10.2 pkt 2, AB 17 7.1.3)
|
|
|
|
double sign(double const Value)
|
|
{
|
|
if (Value > 0.0)
|
|
return 1.0;
|
|
return Value < 0.0 ? -1.0 : 0.0;
|
|
}
|
|
|
|
// the lateral acceleration in the track plane as mm of cant, signed with the curvature: 11.8 V^2 K - D
|
|
double lateral(double const Speed, double const Curvature, double const Cant)
|
|
{
|
|
return kC * Speed * Speed * Curvature - Cant;
|
|
}
|
|
|
|
// I: above 0 the cant falls short of the curve
|
|
double deficiency(double const Speed, double const Curvature, double const Cant)
|
|
{
|
|
if (std::abs(Curvature) < kCurve)
|
|
return -std::abs(Cant);
|
|
return sign(Curvature) * lateral(Speed, Curvature, Cant);
|
|
}
|
|
|
|
// E: above 0 the cant is more than the curve asks for at the speed; on a straight all of the cant
|
|
double excess(double const Speed, double const Curvature, double const Cant)
|
|
{
|
|
if (std::abs(Curvature) < kCurve)
|
|
return std::abs(Cant);
|
|
return sign(Curvature) * Cant - kC * Speed * Speed * std::abs(Curvature);
|
|
}
|
|
|
|
// the cant at the chainage, before a step there or after it
|
|
double cant_at(std::vector<cant_point> const &Points, double const Chainage, bool const After)
|
|
{
|
|
if (Points.empty())
|
|
return 0.0;
|
|
auto const first{std::ranges::lower_bound(Points, Chainage - kSame, {}, &cant_point::chainage)};
|
|
auto const last{std::ranges::upper_bound(Points, Chainage + kSame, {}, &cant_point::chainage)};
|
|
if (first != last)
|
|
return After ? std::prev(last)->cant : first->cant;
|
|
if (last == Points.begin())
|
|
return Points.front().cant;
|
|
if (first == Points.end())
|
|
return Points.back().cant;
|
|
auto const &before{*std::prev(first)};
|
|
auto const &next{*first};
|
|
auto const run{next.chainage - before.chainage};
|
|
return run > kSame ? std::lerp(before.cant, next.cant, (Chainage - before.chainage) / run) : next.cant;
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
// a point inside an element where the curvature and the cant are known from inside it
|
|
struct station
|
|
{
|
|
double chainage;
|
|
double curvature;
|
|
double cant;
|
|
};
|
|
|
|
class checker
|
|
{
|
|
public:
|
|
checker(line const &Line, line_class const &Class, area_map const &Areas) : m_line{Line}, m_class{Class}, m_areas{Areas} {}
|
|
|
|
std::vector<finding> run()
|
|
{
|
|
for (std::size_t i = 0; i < m_line.elements.size(); ++i)
|
|
check_element(i);
|
|
check_jumps();
|
|
check_ramps();
|
|
check_grades();
|
|
return ordered();
|
|
}
|
|
|
|
private:
|
|
line const &m_line;
|
|
line_class const &m_class;
|
|
area_map const &m_areas;
|
|
std::vector<finding> m_found;
|
|
|
|
double speed(element const &Element) const { return Element.speed > 0.0 ? Element.speed : m_class.vmax; }
|
|
double slow(double const Speed) const
|
|
{
|
|
auto const vmin{m_class.vmin > 0.0 ? m_class.vmin : slow_speed(m_class.kind, m_class.vmax)};
|
|
return std::min(vmin, Speed);
|
|
}
|
|
|
|
std::vector<profile_id> profiles(element const &Element) const
|
|
{
|
|
std::vector<profile_id> result{m_areas.at(Element.from, m_line.name)};
|
|
if (auto const other{m_areas.at(Element.to, m_line.name)}; other != result.front())
|
|
result.push_back(other);
|
|
return result;
|
|
}
|
|
|
|
query where(element const &Element, double const Speed, double const Radius, unsigned const Extra = 0) const
|
|
{
|
|
query result;
|
|
result.speed = Speed;
|
|
result.radius = Radius;
|
|
result.load = m_class.load;
|
|
result.kind = m_class.kind;
|
|
result.track = m_class.track;
|
|
result.features = m_class.features | Element.features | Extra;
|
|
return result;
|
|
}
|
|
|
|
// the element the chainage lies on, the one starting there at a joint
|
|
std::size_t element_at(double const Chainage) const
|
|
{
|
|
auto const next{std::ranges::upper_bound(m_line.elements, Chainage + kSame, {}, &element::start)};
|
|
return next == m_line.elements.begin() ? 0 : static_cast<std::size_t>(std::distance(m_line.elements.begin(), next) - 1);
|
|
}
|
|
|
|
// the value checked against each of the profiles, the worst kept
|
|
void check(parameter const What, double const Value, std::size_t const Index, query const &Where, double const Chainage, double const Length = 0.0)
|
|
{
|
|
auto const &element{m_line.elements[Index]};
|
|
std::optional<finding> worst;
|
|
for (auto const profile : profiles(element))
|
|
{
|
|
auto const verdict{assess(What, Value, limits(profile, What, Where), hard_limits(What, Where), m_line.precision)};
|
|
if (verdict.level == tier::none || (worst.has_value() && verdict.level <= worst->level))
|
|
continue;
|
|
finding found;
|
|
found.what = What;
|
|
found.level = verdict.level;
|
|
found.value = Value;
|
|
found.limit = verdict.passed.value;
|
|
found.profile = profile;
|
|
found.from = verdict.passed.from;
|
|
found.confirmed = verdict.passed.confirmed;
|
|
found.hard = verdict.hard;
|
|
found.chainage = Chainage;
|
|
found.length = Length;
|
|
found.element = Index;
|
|
found.speed = Where.speed;
|
|
worst = found;
|
|
}
|
|
if (worst.has_value())
|
|
m_found.push_back(*worst);
|
|
}
|
|
|
|
std::vector<station> stations(element const &Element) const
|
|
{
|
|
std::vector<station> result;
|
|
auto const end{Element.end()};
|
|
result.push_back({Element.start, Element.curvature_start, cant_at(m_line.cant, Element.start, true)});
|
|
for (auto const &point : m_line.cant)
|
|
{
|
|
if (point.chainage <= Element.start + kSame || point.chainage >= end - kSame)
|
|
continue;
|
|
result.push_back({point.chainage, curvature_at(Element, point.chainage), point.cant});
|
|
}
|
|
result.push_back({end, Element.curvature_end, cant_at(m_line.cant, end, false)});
|
|
return result;
|
|
}
|
|
|
|
// an arc meeting another curvature with no transition at one of its ends
|
|
bool abrupt(std::size_t const Index) const
|
|
{
|
|
auto const &element{m_line.elements[Index]};
|
|
if (element.kind != element_kind::arc)
|
|
return false;
|
|
auto const jump_before{Index > 0 && std::abs(m_line.elements[Index - 1].curvature_end - element.curvature_start) > kCurve};
|
|
auto const jump_after{Index + 1 < m_line.elements.size() && std::abs(m_line.elements[Index + 1].curvature_start - element.curvature_end) > kCurve};
|
|
return jump_before || jump_after;
|
|
}
|
|
|
|
// the greatest of a value along an element, and where
|
|
struct peak
|
|
{
|
|
double value{0.0};
|
|
double chainage{0.0};
|
|
double length{0.0};
|
|
|
|
void take(double const Value, double const Chainage, double const Length = 0.0)
|
|
{
|
|
if (Value <= value)
|
|
return;
|
|
value = Value;
|
|
chainage = Chainage;
|
|
length = Length;
|
|
}
|
|
};
|
|
|
|
// a transition next to an arc reaches its radius and its cant deficiency only where the arc begins: the arc has them checked
|
|
bool beside_arc(std::size_t const Index) const
|
|
{
|
|
auto const arc_at = [this](std::size_t const At) { return At < m_line.elements.size() && m_line.elements[At].kind == element_kind::arc; };
|
|
return m_line.elements[Index].kind == element_kind::transition && ((Index > 0 && arc_at(Index - 1)) || arc_at(Index + 1));
|
|
}
|
|
|
|
void check_element(std::size_t const Index)
|
|
{
|
|
auto const &element{m_line.elements[Index]};
|
|
auto const fast{speed(element)};
|
|
auto const sharpest{std::max(std::abs(element.curvature_start), std::abs(element.curvature_end))};
|
|
auto const radius{sharpest >= kCurve ? 1.0 / sharpest : 0.0};
|
|
auto const here{where(element, fast, radius, abrupt(Index) ? feature::abrupt : 0u)};
|
|
auto const points{stations(element)};
|
|
auto const vmin{slow(fast)};
|
|
peak cant;
|
|
peak most_deficiency;
|
|
peak most_excess;
|
|
peak fastest_change;
|
|
for (std::size_t i = 0; i < points.size(); ++i)
|
|
{
|
|
auto const &point{points[i]};
|
|
cant.take(std::abs(point.cant), point.chainage);
|
|
most_deficiency.take(deficiency(fast, point.curvature, point.cant), point.chainage);
|
|
most_excess.take(excess(vmin, point.curvature, point.cant), point.chainage);
|
|
if (i == 0)
|
|
continue;
|
|
// along the piece between two points the curvature and the cant change evenly, and so does the cant deficiency
|
|
auto const &previous{points[i - 1]};
|
|
auto const run{point.chainage - previous.chainage};
|
|
if (run < 0.5)
|
|
continue;
|
|
auto const change{std::abs(lateral(fast, point.curvature, point.cant) - lateral(fast, previous.curvature, previous.cant))};
|
|
fastest_change.take(change * fast / (3.6 * run), previous.chainage, run);
|
|
}
|
|
auto const own_curve{false == beside_arc(Index)};
|
|
if (radius > 0.0 && own_curve)
|
|
check(parameter::radius, radius, Index, here, element.start, element.length);
|
|
if (cant.value > kStep)
|
|
check(parameter::cant, cant.value, Index, here, cant.chainage);
|
|
if (element.kind == element_kind::arc && cant.value > kStep)
|
|
check(parameter::cant_min, cant.value, Index, here, element.start, element.length);
|
|
if (most_deficiency.value > 0.0 && own_curve)
|
|
check(parameter::cant_deficiency, most_deficiency.value, Index, here, most_deficiency.chainage);
|
|
if (most_excess.value > 0.0 && own_curve)
|
|
{
|
|
// the limits by the speed band of the element, the excess at the speed of the slow trains
|
|
auto const before{m_found.size()};
|
|
check(parameter::cant_excess, most_excess.value, Index, here, most_excess.chainage);
|
|
if (m_found.size() > before)
|
|
m_found.back().speed = vmin;
|
|
}
|
|
if (fastest_change.value > 0.0)
|
|
check(parameter::deficiency_rate, fastest_change.value, Index, here, fastest_change.chainage, fastest_change.length);
|
|
check_lengths(Index, here);
|
|
check_boundary(Index);
|
|
}
|
|
|
|
void check_lengths(std::size_t const Index, query const &Here)
|
|
{
|
|
auto const &element{m_line.elements[Index]};
|
|
if (element.open_start || element.open_end)
|
|
return;
|
|
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};
|
|
check(parameter::transition_shift, shift, Index, Here, element.start, element.length);
|
|
return;
|
|
}
|
|
check(parameter::element_length, element.length, Index, Here, element.start, element.length);
|
|
}
|
|
|
|
void check_boundary(std::size_t const Index)
|
|
{
|
|
auto const &element{m_line.elements[Index]};
|
|
auto const both{profiles(element)};
|
|
if (element.kind != element_kind::arc || both.size() < 2)
|
|
return;
|
|
finding found;
|
|
found.what = parameter::profile_boundary;
|
|
found.level = tier::warn;
|
|
found.profile = both[0];
|
|
found.other = both[1];
|
|
found.chainage = element.start;
|
|
found.length = element.length;
|
|
found.element = Index;
|
|
found.speed = speed(element);
|
|
m_found.push_back(found);
|
|
}
|
|
|
|
// an abrupt change of the curvature or the cant at a chainage
|
|
struct jump
|
|
{
|
|
double chainage{0.0};
|
|
std::size_t element{0}; // the one after it
|
|
double curvature_before{0.0};
|
|
double curvature_after{0.0};
|
|
double cant_before{0.0};
|
|
double cant_after{0.0};
|
|
double speed{0.0};
|
|
unsigned features{0};
|
|
};
|
|
|
|
// the jump at a joint of two elements or at a step of the cant, none where the curvature and the cant go on there
|
|
std::optional<jump> jump_at(double const Chainage) const
|
|
{
|
|
auto const index{element_at(Chainage)};
|
|
auto const &after{m_line.elements[index]};
|
|
jump step;
|
|
step.chainage = Chainage;
|
|
step.element = index;
|
|
step.curvature_after = curvature_at(after, Chainage);
|
|
step.curvature_before = step.curvature_after;
|
|
step.speed = speed(after);
|
|
step.features = after.features;
|
|
if (index > 0 && std::abs(after.start - Chainage) < kSame)
|
|
{
|
|
// a train passes the joint no faster than either of the limits there
|
|
auto const &before{m_line.elements[index - 1]};
|
|
step.curvature_before = before.curvature_end;
|
|
step.speed = std::min(step.speed, speed(before));
|
|
step.features |= before.features & feature::switch_track;
|
|
}
|
|
step.cant_before = cant_at(m_line.cant, Chainage, false);
|
|
step.cant_after = cant_at(m_line.cant, Chainage, true);
|
|
if (std::abs(step.curvature_after - step.curvature_before) <= kJumpCurvature && std::abs(step.cant_after - step.cant_before) <= kStep)
|
|
return std::nullopt;
|
|
return step;
|
|
}
|
|
|
|
std::vector<jump> jumps() const
|
|
{
|
|
std::vector<double> places;
|
|
for (std::size_t i = 1; i < m_line.elements.size(); ++i)
|
|
places.push_back(m_line.elements[i].start);
|
|
for (std::size_t i = 1; i < m_line.cant.size(); ++i)
|
|
if (m_line.cant[i].chainage - m_line.cant[i - 1].chainage < kSame)
|
|
places.push_back(m_line.cant[i].chainage);
|
|
std::ranges::sort(places);
|
|
auto const repeated{std::ranges::unique(places, [](double const A, double const B) { return B - A < kSame; })};
|
|
places.erase(repeated.begin(), repeated.end());
|
|
std::vector<jump> result;
|
|
for (auto const place : places)
|
|
if (auto const step{jump_at(place)})
|
|
result.push_back(*step);
|
|
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
|
|
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;
|
|
}
|
|
|
|
// ST-T1-A6 9.11 pkt 8 - 13: the jumps closer than the intermediate length, changing the cant deficiency the same way, are taken
|
|
// together, from the deficiency before the first to the one after the last; otherwise one by one
|
|
void check_jumps()
|
|
{
|
|
auto const all{jumps()};
|
|
std::size_t first{0};
|
|
while (first < all.size())
|
|
{
|
|
auto last{first};
|
|
auto fast{all[first].speed};
|
|
auto features{all[first].features};
|
|
auto const way{sign(lateral(fast, all[first].curvature_after, all[first].cant_after) - lateral(fast, all[first].curvature_before, all[first].cant_before))};
|
|
while (last + 1 < all.size())
|
|
{
|
|
auto const &next{all[last + 1]};
|
|
auto const speed_there{std::max(fast, next.speed)};
|
|
auto const gap{next.chainage - all[last].chainage};
|
|
auto const step{lateral(speed_there, next.curvature_after, next.cant_after) - lateral(speed_there, next.curvature_before, next.cant_before)};
|
|
auto const between{lateral(speed_there, next.curvature_before, next.cant_before) - lateral(speed_there, all[last].curvature_after, all[last].cant_after)};
|
|
auto const along{sign(between) == 0.0 || sign(between) == way};
|
|
if (gap >= intermediate(element_at(all[last].chainage + gap * 0.5), speed_there) || sign(step) != way || false == along)
|
|
break;
|
|
fast = speed_there;
|
|
features |= next.features;
|
|
++last;
|
|
}
|
|
auto const before{lateral(fast, all[first].curvature_before, all[first].cant_before)};
|
|
auto const after{lateral(fast, all[last].curvature_after, all[last].cant_after)};
|
|
auto const extra{std::abs(before) <= 75.0 && std::abs(after) <= 75.0 ? feature::low_deficiency : 0u};
|
|
auto const &element{m_line.elements[all[first].element]};
|
|
query here{where(element, fast, 0.0, extra)};
|
|
here.features = (here.features & ~feature::switch_track) | (features & feature::switch_track);
|
|
check(parameter::deficiency_jump, std::abs(after - before), all[first].element, here, all[first].chainage, all[last].chainage - all[first].chainage);
|
|
first = last + 1;
|
|
}
|
|
}
|
|
|
|
// the speed of the fastest element over the stretch, and the element its middle lies on
|
|
std::pair<double, std::size_t> over(double const From, double const To) const
|
|
{
|
|
double fastest{0.0};
|
|
for (auto const &element : m_line.elements)
|
|
if (element.end() > From + kSame && element.start < To - kSame)
|
|
fastest = std::max(fastest, speed(element));
|
|
auto const index{element_at((From + To) * 0.5)};
|
|
if (fastest <= 0.0)
|
|
fastest = speed(m_line.elements[index]);
|
|
return {fastest, index};
|
|
}
|
|
|
|
// the ramps: between two points of the cant the gradient and the rate of change (ST-T1-A6 9.16, 9.18); a step of the cant as the
|
|
// twist it makes over the base of 5 m
|
|
void check_ramps()
|
|
{
|
|
if (m_line.elements.empty())
|
|
return;
|
|
for (std::size_t i = 1; i < m_line.cant.size(); ++i)
|
|
{
|
|
auto const &from{m_line.cant[i - 1]};
|
|
auto const &to{m_line.cant[i]};
|
|
auto const change{std::abs(to.cant - from.cant)};
|
|
auto const run{to.chainage - from.chainage};
|
|
if (change <= 1e-6)
|
|
continue;
|
|
auto const [fast, index]{over(from.chainage, std::max(to.chainage, from.chainage + kTwistBase))};
|
|
auto const here{where(m_line.elements[index], fast, 0.0)};
|
|
if (run < kSame)
|
|
{
|
|
if (change > kStep)
|
|
check(parameter::cant_gradient, change / kTwistBase, index, here, from.chainage);
|
|
continue;
|
|
}
|
|
auto const gradient{change / run};
|
|
check(parameter::cant_gradient, gradient, index, here, from.chainage, run);
|
|
check(parameter::cant_rate, gradient * fast / 3.6, index, here, from.chainage, run);
|
|
}
|
|
}
|
|
|
|
// the grade line: the vertical curves, the breaks of the grade over 2 per mille with no curve, the grades
|
|
void check_grades()
|
|
{
|
|
if (m_line.elements.empty())
|
|
return;
|
|
auto const &grades{m_line.grades};
|
|
std::size_t i{0};
|
|
while (i < grades.size())
|
|
{
|
|
auto const &piece{grades[i]};
|
|
auto const [fast, index]{over(piece.start, piece.start + std::max(piece.length, kSame))};
|
|
auto const held{piece.grade_start == piece.grade_end};
|
|
// the grades held; a vertical curve goes between the ones on its sides
|
|
if (held && piece.grade_start != 0.0)
|
|
check(parameter::grade, std::abs(piece.grade_start) * 1000.0, index, where(m_line.elements[index], fast, 0.0, piece.length < 500.0 ? feature::short_stretch : 0u), piece.start, piece.length);
|
|
if (i > 0)
|
|
{
|
|
auto const &previous{grades[i - 1]};
|
|
auto const change{piece.grade_start - previous.grade_end};
|
|
if (std::abs(change) > kBreak)
|
|
{
|
|
auto const at{element_at(piece.start)};
|
|
check(parameter::vertical_radius, 0.0, at, where(m_line.elements[at], fast, 0.0, change < 0.0 ? feature::crest : feature::sag), piece.start);
|
|
}
|
|
}
|
|
if (held)
|
|
{
|
|
++i;
|
|
continue;
|
|
}
|
|
// a vertical curve, of the pieces in a row bending the same way with no break between them
|
|
auto last{i};
|
|
auto const way{sign(piece.grade_end - piece.grade_start)};
|
|
auto sharpest{piece.length / std::abs(piece.grade_end - piece.grade_start)};
|
|
while (last + 1 < grades.size())
|
|
{
|
|
auto const &next{grades[last + 1]};
|
|
if (next.grade_start == next.grade_end || sign(next.grade_end - next.grade_start) != way || std::abs(next.grade_start - grades[last].grade_end) > 1e-9)
|
|
break;
|
|
sharpest = std::min(sharpest, next.length / std::abs(next.grade_end - next.grade_start));
|
|
++last;
|
|
}
|
|
auto const total{grades[last].grade_end - piece.grade_start};
|
|
auto const end{grades[last].start + grades[last].length};
|
|
if (std::abs(total) > kBreak)
|
|
{
|
|
auto const [curve_speed, curve_index]{over(piece.start, end)};
|
|
check(parameter::vertical_radius, sharpest, curve_index, where(m_line.elements[curve_index], curve_speed, 0.0, way < 0.0 ? feature::crest : feature::sag), piece.start, end - piece.start);
|
|
}
|
|
i = last + 1;
|
|
}
|
|
}
|
|
|
|
// in the order of the line; each element has one finding of a parameter checked over it, the jumps, the ramps and the breaks of the
|
|
// grade one each
|
|
std::vector<finding> ordered() const
|
|
{
|
|
auto result{m_found};
|
|
std::ranges::stable_sort(result, [](finding const &A, finding const &B) { return std::tie(A.chainage, A.what) < std::tie(B.chainage, B.what); });
|
|
return result;
|
|
}
|
|
};
|
|
|
|
// the point within the outline: a ray from it crosses its sides an odd number of times
|
|
bool inside(std::vector<plan_point> const &Outline, plan_point const &Point)
|
|
{
|
|
bool result{false};
|
|
auto previous{Outline.size() - 1};
|
|
for (std::size_t i = 0; i < Outline.size(); ++i)
|
|
{
|
|
auto const &a{Outline[i]};
|
|
auto const &b{Outline[previous]};
|
|
if ((a.z > Point.z) != (b.z > Point.z) && Point.x < (b.x - a.x) * (Point.z - a.z) / (b.z - a.z) + a.x)
|
|
result = !result;
|
|
previous = i;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
profile_id area_map::at(plan_point const &Point, std::string_view const Line) const
|
|
{
|
|
if (false == Line.empty())
|
|
for (auto const &[name, profile] : lines)
|
|
if (name == Line)
|
|
return profile;
|
|
for (auto const &area : areas)
|
|
if (area.outline.size() >= 3 && inside(area.outline, Point))
|
|
return area.profile;
|
|
return scenery;
|
|
}
|
|
|
|
std::vector<finding> evaluate(line const &Line, line_class const &Class, area_map const &Areas)
|
|
{
|
|
if (Line.elements.empty())
|
|
return {};
|
|
return checker{Line, Class, Areas}.run();
|
|
}
|
|
|
|
} // namespace norms
|