From 7d87fef7a05e8c3659b02a91fad656c90e5ca454 Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 4 Oct 2026 00:51:05 +0200 Subject: [PATCH] refactor(editor): anchor on the nearest place of a path --- application/editormodeinfra.cpp | 15 +++------------ editor/editorInfra.cpp | 8 ++++++++ editor/editorInfra.hpp | 2 ++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/application/editormodeinfra.cpp b/application/editormodeinfra.cpp index 2e976d9d..67cf2333 100644 --- a/application/editormodeinfra.cpp +++ b/application/editormodeinfra.cpp @@ -567,10 +567,7 @@ std::optional read_binding(std::string const &Text, scene::layer break; } auto const &point{points[std::min(i, points.size() - 1)]}; - double s; - bool interior; - infra::project((*track)->m_paths[path], point, s, interior); - binding.anchors.push_back(infra::make_anchor({*track, path, s}, point)); + binding.anchors.push_back(infra::make_anchor(*track, path, point)); } if (false == found || binding.anchors.size() != points.size()) return std::nullopt; @@ -938,10 +935,7 @@ void editor_mode::track_captured(TTrack const &Track) auto placed{anchor}; if (glm::distance(infra::place(placed), points[i]) <= 0.01) continue; - double s; - bool interior; - infra::project(path, points[i], s, interior); - anchor = infra::make_anchor({anchor.at.track, anchor.at.path, s}, points[i]); + anchor = infra::make_anchor(anchor.at.track, anchor.at.path, points[i]); } if (binding.turns && yaw.has_value() && binding.anchors.front().at.track == &Track) binding.yaw = turn_of(binding, *yaw); @@ -1189,10 +1183,7 @@ void editor_mode::infra_rebase() binding.lost = true; continue; } - double s; - bool interior; - infra::project(anchor.at.track->m_paths[anchor.at.path], points[i], s, interior); - anchor = infra::make_anchor({anchor.at.track, anchor.at.path, s}, points[i]); + anchor = infra::make_anchor(anchor.at.track, anchor.at.path, points[i]); } if (binding.turns && yaw.has_value()) binding.yaw = turn_of(binding, *yaw); diff --git a/editor/editorInfra.cpp b/editor/editorInfra.cpp index a2fbc9ba..ba38961f 100644 --- a/editor/editorInfra.cpp +++ b/editor/editorInfra.cpp @@ -222,6 +222,14 @@ double heading(glm::dvec2 const &Forward) return glm::degrees(std::atan2(Forward.x, Forward.y)); } +anchor make_anchor(TTrack *Track, int const Path, glm::dvec3 const &Point) +{ + double s; + bool interior; + project(Track->m_paths[Path], Point, s, interior); + return make_anchor({Track, Path, s}, Point); +} + anchor make_anchor(station const &At, glm::dvec3 const &Point) { anchor result; diff --git a/editor/editorInfra.hpp b/editor/editorInfra.hpp index afb76d8e..64d32b25 100644 --- a/editor/editorInfra.hpp +++ b/editor/editorInfra.hpp @@ -83,6 +83,8 @@ struct anchor double length{0.0}; }; anchor make_anchor(station const &At, glm::dvec3 const &Point); +// anchor at the place of the path nearest to the point +anchor make_anchor(TTrack *Track, int const Path, glm::dvec3 const &Point); // location for the current geometry of the path glm::dvec3 place(anchor &Anchor);