From 1340017be3558194327c19a551deddf92a9d8dc4 Mon Sep 17 00:00:00 2001 From: maj00r Date: Tue, 27 Oct 2026 19:23:31 +0100 Subject: [PATCH] feat(editor): a slip keeps in the scenery the radius of the main track it's bent with, as a switch does, the lists of the switches telling it as Rg: switch_store::main_radius_of gives it from the first path of a switch, classify takes it from there too; a slip laid on straights keeps 0 --- application/editormoderecords.cpp | 2 ++ editor/editorSwitchStore.cpp | 16 ++++++++++------ editor/editorSwitchStore.hpp | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/application/editormoderecords.cpp b/application/editormoderecords.cpp index 711dba03..c57d2f43 100644 --- a/application/editormoderecords.cpp +++ b/application/editormoderecords.cpp @@ -369,6 +369,8 @@ void editor_mode::record_slip(std::vector const &Parts, std::string co if (first == nullptr || first->m_paths.empty()) return; switch_store::place(entry, *first); + // a slip bent into a curve, as a switch is + entry.main_radius = switch_store::main_radius_of(*first); switch_store::put(entry, alignment_store::layer_of(*first)); } diff --git a/editor/editorSwitchStore.cpp b/editor/editorSwitchStore.cpp index f8a2cedb..a509f051 100644 --- a/editor/editorSwitchStore.cpp +++ b/editor/editorSwitchStore.cpp @@ -451,17 +451,21 @@ void place(record &Entry, TTrack const &First) Entry.km = alignment_store::chainage_at(Entry.start); } -void classify(record &Entry, TTrack const &Switch) +double main_radius_of(TTrack const &Switch) { geometry::bezier const main{Switch.m_paths[0]}; - auto const &diverging{Switch.m_paths[1]}; - Entry.hand = geometry::cross(Entry.direction, geometry::plan_of(diverging.points[segment_data::point::end] - Entry.start)) > 0.0 ? 'R' : 'L'; auto const first{geometry::plan_of(main.first(0.0))}; auto const last{geometry::plan_of(main.first(1.0))}; auto const turn{glm::length(first) > 1e-12 && glm::length(last) > 1e-12 ? geometry::signed_angle(glm::normalize(first), glm::normalize(last)) : 0.0}; - Entry.main_radius = std::abs(turn) > 1e-6 ? main.plan_length() / turn : 0.0; - if (std::abs(Entry.main_radius) > 20000.0) - Entry.main_radius = 0.0; + auto const radius{std::abs(turn) > 1e-6 ? main.plan_length() / turn : 0.0}; + return std::abs(radius) > 20000.0 ? 0.0 : radius; +} + +void classify(record &Entry, TTrack const &Switch) +{ + auto const &diverging{Switch.m_paths[1]}; + Entry.hand = geometry::cross(Entry.direction, geometry::plan_of(diverging.points[segment_data::point::end] - Entry.start)) > 0.0 ? 'R' : 'L'; + Entry.main_radius = main_radius_of(Switch); if (Entry.type == "Rz" || Entry.type == "Rlj" || Entry.type == "Rld") Entry.type = Entry.main_radius == 0.0 ? "Rz" : (Entry.main_radius > 0.0) == (Entry.hand == 'R') ? "Rlj" : "Rld"; } diff --git a/editor/editorSwitchStore.hpp b/editor/editorSwitchStore.hpp index 69e90c14..15e4f144 100644 --- a/editor/editorSwitchStore.hpp +++ b/editor/editorSwitchStore.hpp @@ -72,6 +72,8 @@ double branch_radius(record const &Record); void put(record Entry, scene::layer_handle const Layer); void place(record &Entry, TTrack const &First); void classify(record &Entry, TTrack const &Switch); +// of the first path of the switch, signed as record::main_radius: + to the right, - to the left, 0 straight +double main_radius_of(TTrack const &Switch); void forget(std::string const &Name); // the records follow renamed switches: their parts and the records named after them; Bases renames the records of slips and // crossings, whose names aren't the names of their parts