mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-31 18:09:04 +01:00
Checkpoint of the editor branch so work isn't carried loose across a branch switch. Builds. - maj0sted turnout geometry moved into the domain: domain::lay_turnout lays the diverging path (pre-blade lead, blade at beta, arc of alfa-beta, frog rail) and solve_junction is a thin adapter onto it. - the maj0sted web/ tree renamed to editor/ (namespace and paths) - there is no WASM here, it's plain native C++ the editor calls. - click places the switch at its start (początek rozjazdu); the branch's leaving straight is locked tangent to the frog; switches can be slid along the through track and flipped L/P. - Polish turnout templates carry catalogue length (Id-1-consistent lengths), plus blade-angle and pre-blade fields (left 0 until the catalogue figures are in). - TURNOUT_SPEC.md: the Bezier-based runtime/model contract. - also folds in other pending branch changes (scenery, tests) to leave a clean tree.
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
#include "maj0sted/editor/ribbon.hpp"
|
|
|
|
#include <cmath>
|
|
|
|
#include "maj0sted/domain/geometry/segment_layout.hpp"
|
|
|
|
namespace maj0sted::editor {
|
|
|
|
using maj0sted::domain::geometry::layout_segment;
|
|
using maj0sted::domain::geometry::Pose;
|
|
using maj0sted::domain::geometry::XY;
|
|
|
|
std::vector<PlanPolyline> solve_ribbon(const RibbonRequest& request) {
|
|
std::vector<PlanPolyline> result;
|
|
result.reserve(request.elements.size());
|
|
|
|
Pose pose{request.x0, request.y0, std::sin(request.az0), std::cos(request.az0)};
|
|
|
|
for (const auto& element : request.elements) {
|
|
double k0 = 0.0;
|
|
double k1 = 0.0;
|
|
double length = 0.0;
|
|
int kind = element.kind;
|
|
|
|
if (element.kind == 1) { // arc
|
|
const double sign = element.dir >= 0 ? 1.0 : -1.0;
|
|
const double k = element.radius > 0.0 ? sign / element.radius : 0.0;
|
|
k0 = k;
|
|
k1 = k;
|
|
length = element.radius * element.angle;
|
|
} else if (element.kind == 2) { // spiral (clothoid)
|
|
const double sign = element.dir >= 0 ? 1.0 : -1.0;
|
|
k0 = element.radius_start > 0.0 ? sign / element.radius_start : 0.0;
|
|
k1 = element.radius > 0.0 ? sign / element.radius : 0.0;
|
|
length = element.length;
|
|
} else { // line
|
|
kind = 0;
|
|
length = element.length;
|
|
}
|
|
|
|
std::vector<XY> points;
|
|
pose = layout_segment(k0, k1, length, pose, &points);
|
|
|
|
PlanPolyline polyline;
|
|
polyline.kind = kind;
|
|
polyline.points.reserve(points.size());
|
|
for (const auto& p : points) {
|
|
polyline.points.push_back(PlanPoint{p.x, p.y});
|
|
}
|
|
result.push_back(std::move(polyline));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} // namespace maj0sted::editor
|