mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 12:57:06 +01:00
f2627db8f0
* fix(editor): track edits keep the joints, the norms, the records and the saved speed together
- The cant typed in the inspector goes on into the track joined at that end, as the gizmo and the
joints tool do it; the neighbours go into the same undo step. The joint stepped before.
- A track laid on from a canted joint takes the cant off along the ramp the norms ask for at the
speed (`alignment::cant_ramp_length`), not at a fixed 1.5 mm a metre whatever the speed and the
norms: 120 mm at 100 km/h over 120 m, not 80 m.
- Deleting a track of the line under the route tool keeps the laying norms. They went back to the
defaults, and every later lay, extend and join used those.
- The gauge is a paste group of its own, off by default: pasting how a track rides or sounds no
longer changes its gauge.
- The speed of a turntable set in the editor is the one saved. The editor changed the speed the
turntable runs at, while the file keeps the limit it was loaded with.
- Deleting a set of tracks does what Del does with each: a double switch, a slip and a crossover go
whole, the records of the switches go with them, and the model and events of a turntable too. The
records stayed behind and on saving were given to another switch, which then showed a wrong type.
- Deleting a switch of a crossover takes the crossover out whole, as the connection tools do: the
outer track of a crossover on a curve comes down by its lift and the record of the connection
goes. Alone, the switch left the outer track up for good, and the connection to the next switch
given its name. A switch bent out of the shape of its record is found by its name.
Tests: a unit test of the norm ramp. The other changes are in the editor's UI, which the unit tests
don't reach.
* test(editor): self-test scripts that fail, a runner, and a case for each fix of the track editing
The editor's self-test scripts only logged: nothing made a run fail. Now:
- `expect` commands check the state and log `SELFTEST PASS` or `SELFTEST FAIL ... got X, expected Y`:
the cant at a track end, the joint at an end (gap, angle, cant step), the records of a switch and
the connections naming it, speed, gauge, a track present or removed, the laying norms' gauge,
heights and lifts against a mark, whether a track is in the line under the route tool, and the
includes of a turntable. A command no group takes counts as a failure, so a mistyped one can't
make the checks after it pass.
- At `quit` the result is logged, and a script whose expectations failed ends the editor with exit
code 2 (a failed start stays 1; the simulator's test mode is unchanged).
- The commit of the inspector's cant field is `track_cant_commit`, which the inspector and the
`trackcant` command both call; `routegauge` sets the laying norms as the route tool does, and
`tracksetdelete` deletes a set of tracks by name.
- `tests/editor/run.py` runs each script of `tests/editor/cases` on a copy of the fixture scenery
in the game folder, with a wall-time limit and a memory cap, reads the exit code and the
`SELFTEST` lines, and deletes the copy. A `#> reopen` line restarts the editor on the saved
scenery. See `tests/editor/README.md`.
- One case per fix of the track editing quick fixes (inspector cant, norms after deleting, the
gauge paste group, turntable speed saved, deleting a set, a set with a double switch, a slip
and a crossover, deleting a switch of a crossover, a bent switch). All pass; with the fixes
reverted all fail.
* feat(editor): the track tool panels keep their fields, results and buttons within the panel
- The card of the tool: after a long gesture the action goes under it, at its indent, when what is
left of the row is narrower than 8 font sizes or the longest word of the action. It was squeezed
into a sliver and broken in the middle of its words.
- A click on the title row of the card folds it to that row (icon, name, family, key, and a small
triangle marker) and opens it again. One flag for all the tools, kept with the editor settings
(`track_card_folded` in eu07_editor.ini), open by default: the card took 250-300 px at the top
of every tool and repeats the hint bar of the view.
- The grade labels of the vertical profile, on the graph and in the view, write the per mille as
the panel does (the translated "per mille", the per mille sign in Polish), not "o/oo".
- The track analysis window: the thresholds of the speed check and of the joints keep to their
widest name and a field of 10 font sizes where the window is wider than that, as docked across
the bottom (`begin_fields_fitted`). The results are tables with each column as wide as what is in
it: the speed check with its column names kept at the top as the list scrolls, the joints with
the kind, the value and the two tracks next to each other. A click on a row shows it as before.
- `same_line_if_fits` puts the next button beside the one before only when it fits in what is left
of the line, at the start of the next line otherwise. Used where the route design puts buttons
side by side, for "Forget the design" in the profile panel, which was cut off at the edge, and for
the buttons of a switch in the inspector.
- The laying options: the speed, the curve radius and the longest path are fields with the name on
the left in two columns (`begin_fields`/`field_row`), as in the inspector, the route and the
profile, the chips of the quick values under them. The segmented choices give the short names
less of the room when a long one doesn't fit in its even share, and go on in a second bar when
they don't fit side by side: "Through the clicked points" overflowed its third of the bar.
* fix(editor): a switch laid gets the speed of its diverging track, one breaking a hard rule of ST-T1-A6 isn't laid
- Every switch laid writes the speed of its diverging track (`velocity`): the switch tool on a
straight, into a curve, from a free end and linked, a double switch, the switches of a slip, a
switch given another template of the catalogue, and a switch moved along the curve it's bent
into. A switch of the catalogue had no limit before, one copied from a switch of the scenery kept
that one's, one laid without a track had the laying speed on both its tracks. The limit is for the
diverging track alone (`velocity -V`); the own limit of the track it goes into stays for both
where it's the lower. The switch tool says the speed and what gives it.
- The speed is formula 9.9 of PKP PLK ST-T1-A6 the other way round, V = sqrt((I + D) r / 11.8), with
the normal cant deficiency of the frog of table 9.7 (110 mm a fixed frog, 130 mm a movable nose),
rounded down to the steps of the speed limits and no more than table 11.2 gives the basic switch.
For the fixed frogs the formula gives table 11.2 itself (190 40, 300 50, 500 60, 760 80, 1200
100 km/h); the 2500-1:26.5 with a movable nose stays 130. A switch bent into a curve takes the
radius of its diverging track from table 11.8 (one-sided r" = (Rr - t^2)/(R + r), two-sided
(Rr + t^2)/(R - r)) and the cant of the line with its sign: leaning against the diverging track it
takes speed away, where the speed check counted it as helping. Rz 60E1-190-1:9 bent out of the
curve R 600 m with 60 mm: 30 km/h, not 40; the 60E1-500-1:12 of the review, out of R 1200 m with
60 mm: 60 km/h at its fixed frog (54 at I = 100 mm, the 0.65 m/s2 the editor took), not 107.
- A switch breaking a hard rule isn't laid, the tracks left as they were, and the switch tool says
why, with the value, the limit and the paragraph: the cant changing within it (11.4 pkt 7), a cant
ramp ending within it or nearer than 6 m (9.6 pkt 16-17; one ending right at an end of the switch
is let be, as the snapping of the start offers it), a double switch, a slip or a crossing bent
(11.4 pkt 4), the curvature of its diverging or its main track turning from one side to the other
(9.7 pkt 12, KZW II). They were warnings shown after the switch was laid, and on a straight the
cant wasn't looked at at all. The line is looked at 10 m past the ends of the curve or the
straight too, so the ramp on the straight before a curve counts. The previews show the refusals.
- A switch moved along its straight or the curve it's bent into, a double switch moved along its
straight, and a switch given another template go through the same checks; one breaking a rule
stays as it is.
- Warnings still: 1:9.403 and steeper than 1:9 bent (11.4 pkt 4c-d), a rule of the running and the
main tracks, which the editor doesn't tell from the side ones, as the warning now says; the limits
of table 11.9 and a cant over 100 mm in a bent switch (table 9.6), as before.
Tests: unit tests of tables 11.8 and 11.9 (the least main radius bends the diverging track to the
least radius the table gives), table 9.7, the speeds of table 11.2 by formula 9.9, the speed of a
bent switch with the cant with its sign (the example of the review), the cant over a switch on a
straight and a double switch bent. Editor cases `q2_1_switch_speed`, `q2_2_switch_refusals` and
`q2_3_switch_move`, with `expect status` (the status of the switch tool) and `expect steps` (the
undo steps), the fixture with a straight taking a cant on and a compound curve without cant. All
pass; with the changes of the editor reverted all three fail.
* test(editor): golden round trips of the tracks and of the //$ lines, the cant at the joints
The safety net of the track editor before its domain model changes (E0 of
editor-tracks-tests.md): what the editor reads from the scenery files and
writes back is read, written and read again in tests/unit, with no game data.
Tracks (test_track_text.cpp, data/tracks/). Entries written the way the game
writes them, read by TTrack::Load() and written by export_as_text(), come out
byte for byte the same, and read again give the same track field by field:
plain tracks with all their attributes (events, speed, isolated, overhead,
vradius, rail profile, friction cell), a curve with cant, radius, uneven,
buckle, cwr and sleeper models, a bridge, switches with trackbed, frogs,
movable nose, blades, uneven of both paths and timbers, a turntable, paths of
pieces, the speeds +40, -40, 0.5, 0 and none of tracks, switches and
turntables, a river, a tributary, a road and a crossing. What the game writes
otherwise than given is checked as it is (table as turn, mountain as
mountains, the length of the path, a switch heard from 10 m, the events in
order, names in lower case, model paths with forward slashes, the texture
length, rolls as floats, no overhead and no vradius left out).
The seam: TTrack built from text with no scene. The engine stubs of the tests
had none of it, so the tests link the few sources reading and writing a track
takes (world/Track.cpp, Segment.cpp, TrackUneven.cpp, MemCell.cpp,
scene/scenenode.cpp, utilities/Timer.cpp, rendering/geometrybank.cpp) and
track_stubs.cpp stands in for the rest: a renderer keeping the materials by
their names, and the scene, events, vehicles and the geometry of the rails,
which reading and writing never reach and which stop the test with their name
if one does. It tests the game's own Load() and export, where a parser of its
own would have meant rewriting Load(), and changes no code of the game. The
stub of basic_node::radius_() goes, scenenode.cpp brings the real one. The
rails don't buckle in the tests (TrackBuckle.cpp needs the environment), the
buckle declared is read and written either way; material names go through a
stand-in, the game's material manager isn't tested here.
The //$ lines (test_editor_records.cpp, data/records/). Their readers and
writers were members of editor_mode, srk_tool and the stores, with the scene
around them; they move as they were into editor/editorRecords.cpp, the one
place each kind is read and written, which the stores call (and which the
migration to the project file of E3 will need apart anyway). The methods of
scene::layer_context move into scene/scenelayercontext.cpp so it links alone.
Each kind, h r k p t w b s c o z, read from golden lines and written back comes
out the same, in the coordinates of the file and of a file placed at an
origin; //$e, the descriptions of the templates, read and saved by
editor_includes in a template in a scratch folder, leaves the file as it was.
Cant (test_cant.cpp). The paths an alignment lays roll by asin(cant/gauge),
signed with the turn, back to the cant of the line at every end; a curve the
other way rolls the other way. At a joint editor_track::match_rolls() gives
the joined track the roll for the travel across it, turned where the paths
face or stand back to back, and the track written keeps it. The inspector's
own conversion on 1500 mm stays in its lambdas here; named, as
editor_mode::cant_of_roll()/roll_of_cant(), it comes with the quick fixes.
Known bugs found, tests of the change each (doctest::should_fail, passing
until fixed, then reported to drop the decorator), data/tracks/known_lost.scn:
- angle1/angle2 are read and dropped: not written back.
- fouling1/fouling2 are read and dropped: not written back.
- name@circuit: the circuit is taken out of the name with the letter before
the @ ("tor1@iso1" becomes track "tor"; substr(0, i - 1)).
- the attributes of the entry (gauge, friction, texture sizes, speed...) are
written to 6 significant digits, a float has 9: more digits are lost on the
first save.
None in the //$ lines.
Unit tests: 957 cases before, 974 after, all passing.
* feat(editor): the norms of the track geometry, a module of their own: the profiles as tables, one engine
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().
* feat(editor): the norms checked on the tracks laid, read only: a Norms tab of the track analysis and its report
The second half of E1: what the tracks of a scenery are against a profile of the norms, listed. Nothing of the tracks is changed.
- editor/editorNormsReport: a line of paths sampled a metre apart, two samples at each joint, into what the norms read a line
from: the plan, the curvature signed by the turn, the cant on the base of 1500 mm (as the simulator takes the rolls) signed by
the side it leans to as the line runs, the grade, the speed of each path (a switch's for its diverging track alone too), and
what the path is a part of (a switch, its diverging track, a curved switch, a movable frog, a crossing). The line described,
checked, and each finding set back on its path with a point of it; its message, "cant ramp 3.00 mm/m, PLK allows at most 2.50 mm/m
(tab. 9.12)", "break of the grade with no vertical curve, PLK asks for a radius of at least 2500 m (tab. 10.2)", through STR_C;
the text of the report: the class, the elements, the cant, the grade line and the findings of each line.
- The Norms tab of the track window, under More beside Speed and Joints, no key; its window is ###trackanalysis, as theirs. The
line through the selected path (run_route, as the speed check walks it) or the whole scenery: the lines through the plain tracks,
then each path of a switch none of them ran along, checked with the line it lies in and its own findings kept, a place two lines
run through listed once. The profile (PLK by default) and the class of the line folded under a line saying it: the line speed for
the tracks with none of their own (on by default: the speed of each track), the slow trains (tab. 8.1 by default), the traffic,
main track or siding, the load, at a platform. The results in the table of the speed check and the joints, the worst first,
coloured by the tier, the values above the recommended ones on a tick; a click on a row shows the place, the hard limits and the
warnings are marked in the view. The icon is drawn into its own cell of editor_icons.png only (the generator has it): the sheet
drawn again with this Pillow differs in other cells.
- Self-test: normsreport <file> [scope] [plk|tsi|en|ch] [km/h] writes the report to the file; expect findings <tier> <least> <most>;
the case e1_norms_report checks the curves k0..k3 of the fixture at 60 km/h against PLK and the whole scenery against the TSI.
- Golden: data/norms/line.scn, a line of 14 tracks written by make_line.py there (curves with and without transitions, cant on and
off a curve and along a straight, reverse curves 10 m apart, short straights, a grade with breaks), and its report against the
four profiles in data/norms/line_report.txt; EU07_UNIT_TESTS_UPDATE_GOLDEN=1 writes it anew. A test lays a canted corner with the
alignment of the editor and finds the samples leaning into it, both turns and run both ways, I = Deq - D.
alignment::limits stays as the laying tools use it. Where its values differ from PLK P0:
- unbalanced 0.6 m/s2 is I 92 mm on the 1500 mm base; P0 110 mm (P1 130) on the running lines, 80 on the sidings;
- ramp_factor 10, a ramp of 1:(10 V), 1 mm/m at 100 km/h and 2.5 mm/m at 40 km/h, has no counterpart: P0 1.6 mm/m at any speed;
- jerk 0.3 m/s3 is dI/dt 46 mm/s; P0 55 mm/s;
- vertical_factor 0.4 V^2 and vertical_min 2000 m; P0 max(0.77 V^2, 5000 m) (P1 max(0.35 V^2, 5000), P2 max(0.25 V^2, 2000));
- arc_min 20 m and arc_min_factor 0.4 V; P0 max(0.35 V, 30 m) up to 120 km/h, 0.40 V up to 200 km/h, also for the straights, where
tangent_min_time is 0;
- the same: cant_max 150 mm (P0 = P1 = P2 on ballast), cant_rate 35 mm/s (P0 of tab. 9.13), the base of 1500 mm.
* feat(editor): the elements and the line of the track geometry, a module of their own
The first part of E2 (editor-tracks-domain.md §2 - §4): the geometry of a line computed in one place, editor/layout, standing on its
own with no scene, no tracks and no user interface. Nothing of the editor uses it yet; the route design keeps its own solver.
- layoutElements: the elements of a line, the straight, the arc, the clothoid (the curvature changing evenly, from any curvature to
any other), the Bloss curve (3t^2 - 2t^3) and the cubic parabola (y = x^3 / 6RL by the abscissa, the length along it its own):
the length, the curvature along, the point and the heading at a distance, a point offset from the axis, the shift of the arc. The
local forms of the clothoid and the cubic parabola and the blossom of a Bezier curve are the ones of editorAlignment.cpp, moved
here word for word; the alignment calls them, so the two agree to the bit and its tests run as before.
- layoutLine: the line as a tangent polygon between the points of its two end nodes (it has no coordinates of its own there), its
vertices with the radius, the transitions in and out and the cant, a grade line of breaks with their vertical curves, the shape of
the transitions and of the cant ramps (linear or Bloss). solve() lays it: each curve fitted in the frame of its tangent point
from its deflection (the arc what the transitions leave of it), the straights what the tangents leave of the sides, every element
placed from the polygon so nothing drifts; the cant held along the arcs, ramped along the transitions, a step refused; the heights
and the grades by the breaks. An end can go on from the curvature and the cant its node holds (a line split inside a curve):
its curve begins right at the node. What can't be laid is an error with the vertex and the metres: curves overlapping, a curve
starting before the start, transitions turning more than the tangents, a cant step, a vertical curve past the end.
- described(): the line as the norms module reads it (elements, cant points, grade elements), a Bloss ramp seen by eight points
so its steeper middle counts. preferred_curve(): the cant and the transition length the profile prefers for a radius at the line
class, the deficiency, the excess and the greatest cant of PREFER, else of WARN, the transitions long enough for dD/ds, dD/dt
and dI/dt.
- norms::line_class compares by its values (operator==), the line keeping it compares whole.
Tests (U): the clothoid, the cubic parabola, the Bloss curve and the arc against the series of the textbooks (the end point, the
length of the parabola, the shift: L^2/24R and L^2/40R), the point as the integral of the heading, the circles alongside an arc, the
curve of a vertex by its tangent length (R + p) tan(a/2) + x_m.
* feat(editor): the nodes of the track geometry and the commands editing the lines, kept whole or refused, one step to undo
Continues E2 (editor-tracks-domain.md §4 "Edycja = polecenie", §8): the lines meet at nodes, and every edit is a command which
proposes a new state, has what depends on it laid again, is checked and kept, or refused with its reasons and nothing changed.
- layoutNetwork: the node, its place (the only coordinates of the ends of the lines), the heading, the curvature, the cant and the
grade, and the ends of the lines meeting there, each with its sense along the heading; the network of the nodes and the lines
with the profiles of the norms by place and the identifiers handed out once, never again (an undone line made again is a new one).
A transaction keeps each line and node the first time it touches it, so a change is rolled back whole or recorded.
- settle(): the lines touched laid again; the nodes take the values of their ends (a free end follows its line, a node keeps the
curvature and the cant a line going on from it reads), a line going on from a node whose curve changed is laid again.
- check(): the invariants of the touched lines and nodes: laid, at their nodes, two ends at most on the two sides of a node (more
is a turnout, E5), the heading the same within 1e-9 rad, the cant within 0.5 mm, the grade within the 2 per mille that needs no
rounding; and the norms along the chains through the touched lines (the lines running on through the nodes as one line, the
elements running on alike across a node as one, a jump of the curvature at a node a step of the deficiency the profile judges):
BLOCK refuses, WARN and PREFER are told as notices.
- layoutCommands: create a line between two new nodes; move a vertex; set its radius, transitions or cant; split a line at a
chainage (the track kept as it was: on a straight, in an arc, in a clothoid with a straight ramp, the parts going on from the new
node at its curvature and cant; refused inside a vertical curve and inside a Bloss or cubic parabola transition); join two free
ends with a line solved between them (a straight, a curve where the tangents meet, or two curves, the largest radius which fits
with the cant and the transitions the norms prefer, a grade line meeting the grades of the ends); delete a line (a node left with
no end goes). The model keeps the network and the steps: undo and redo restore the snapshots of the lines and nodes a command
touched, one step a command.
Tests: the cases of each command, a refusal (a radius under the least, a cant over the greatest, curves overlapping, transitions
too long) leaving the state as it was, a WARN radius kept with its notice, undo and redo, the track the same along a line split on a
straight, in an arc and in a clothoid, a middle part deleted and joined again both ways round, a straight joining two ends on one
straight. P: 300 random edits each with the seeds 20261123, 7 and 450 (moved vertices, new radii, transitions and cants, splits,
joins, deletions, undo, redo): after each the invariants checked on their own (each element running on from the last, the cant
running on, the ends of the lines at their nodes to the bit, the heading, the cant and the grade running on through the nodes) and
no BLOCK along any chain; a refused command leaves the state as it was, an undo gives the state before the command.
* feat(editor): the tracks of the simulator made of the lines of the track geometry, within half a millimetre
The last part of E2a (editor-tracks-domain.md §3 and §5): the generator, the layer between the domain and the simulator. A line is
cut into cubic Bezier pieces, each one a track entry of the text TTrack::Load reads. Nothing of the editor writes them yet.
- The pieces end at the elements, at the ends of the vertical curves and of the cant ramps; each one halved until the curve as the
simulator draws it lies within 0.5 mm of the line, in the plan and in the height, and its cant within 2 mm of the line where the
simulator turns the roll evenly; none longer than a track may be (400 m), none shorter than 10 cm. The handles of an arc are its
own, 4/3 tan(turn / 4) R; a transition takes the handles which give the curve the curvatures of the line at its ends (G2 Hermite,
by Newton's method, those of an arc where it finds none near them); a cubic parabola is the cubic Bezier curve it is, cut by its
blossom; a straight of an even grade has no control vectors, as the simulator draws it. A piece TTrack would take for a straight
(its 2 cm check of the control vector) is one, close enough or halved.
- The rolls and the heights come from the functions of the line, the radius from the element: an arc's own, the sharpest over a
transition, 0 on a straight. A piece ends at a node with the numbers of the node, its place, its heading and its cant, so the
tracks on both sides of it have the same numbers to the bit; the numbers are written in the shortest form which reads back to the
same double.
- The names come from the identifiers: <prefix><line>_<element><piece>, the element the straight leading to a vertex (s7, se to
the end) or the transition in, the arc or the transition out of a vertex (v7i, v7a, v7o); a change of a curve leaves the names of
the pieces of the others.
- The joints of old tracks as hard points of the pieces, keeping their names and events, are E6 (§10): generator_options has their
place, a line given any is refused rather than made without them.
Tests: the pieces of lines of clothoids, Bloss curves and cubic parabolas, of R 190 m and of 5 km with vertical curves, each
measured both ways (the points of the curve set square onto the line, and the points of the line against the nearest of the curve,
searched on its own): within 1 mm, the farthest 0.35 mm (0.45 mm with Bloss curves). G: a line split on a straight and in an arc,
its tracks written and read back by TTrack::Load (the E0 seam): the ends at the nodes and between the pieces the same to the bit on
both sides, the rolls and the headings of the control vectors too, the curve within 1 mm of the line, the radius of the element;
a line laid the other way through its nodes; the names unique and kept by a change of another curve; the E6 hook refusing.
* test(editor): a mistyped track fails the self-test, indented comments are skipped, case 7b checks the switch got bent
- A blank line or an indented `#` comment in a script is no longer a command no group takes.
- `trackcant`, `routegauge` and `tracksetdelete` with a track that isn't there count as a failed expectation.
- `expect shaped <switch> <yes|no>`: 7b checks that the gizmo drag bent the switch out of its record before deleting it.
- The ramp-length loop of test_alignment counts in an integer (Sonar S2193).
* test(editor): the entries known to be lost are checked apart from should_fail, the cant test says where the inspector conversion is tested
- A normal test checks that known_lost.scn and each of its entries are there and read, so the should_fail tests can't pass for
data gone missing.
- The comment of test_cant.cpp said the tests of cant_of_roll()/roll_of_cant() are here; they are the self-test case
1_inspector_cant.txt, as the unit tests don't link the editor.
* fix(editor): TSI and EN take close jumps of the cant deficiency together, the norms queue keeps its own span after a delete
- TSI INF and EN 13803 limit an abrupt change of the cant deficiency but give no intermediate length, so two jumps a few metres
apart were each checked alone: at km 478 of the golden line CH reported 191 mm over the TSI limit, TSI itself nothing. With
no intermediate length in the profiles of the element, the longest any profile asks for is taken. The golden report changes
that way: TSI gets the 191 mm hard limit at km 478, EN reports it instead of 106 and 85 mm one by one.
- forget() moves the span whose findings alone are kept (a diverging track) down by the spans removed before it, and drops a
queued line whose own span was removed, instead of leaving the index on another span.
- The report test of R 400 / 80 mm runs at 90 km/h and requires the finding: at 80 km/h there was none and the check never ran.
* fix(editor): the norms see a Bloss transition as it is, a line splits at the tangent point of an arc with no transitions
- A Bloss transition went to the norms as an even one: 60 m into R 600 m at 100 km/h showed 63 mm/s of deficiency change,
where its middle reaches 109 mm/s, past the hard limit of 80 mm/s, so the edit wasn't blocked. norms::element::bloss makes the
engine follow 3t^2 - 2t^3 of the curvature, look at the transition in eight pieces, and take the shift as L^2 / 40R instead
of L^2 / 24R. Two Bloss halves no longer run on into one element of the chain.
- split_line right at the tangent point of an arc without transitions was refused ("the tangent there doesn't cross the
tangents of the curve"): the curvature there is already the arc's, so it now takes the start or the end of the curve.
- Sonar: the chain walk, describe_chain and check_norms check the lines they look up (S2259), join_ends returns when an end
isn't found rather than when a reason was given (S836), the test loops count in integers (S2193), the seeded generator
of the random edits is marked (S2245).
570 lines
19 KiB
C++
570 lines
19 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/layoutNetwork.hpp"
|
|
#include "editor/editorGeometry.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <format>
|
|
|
|
namespace layout
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
double constexpr kHeading{1e-9}; // rad: the ends of a node head the same way within this
|
|
double constexpr kCurvature{1e-9}; // 1/m: a smaller difference of the curvature isn't a step
|
|
double constexpr kCantStep{0.5}; // mm, as the norms engine takes a step of the cant
|
|
double constexpr kGradeBreak{0.002}; // a change of the grade up to 2 per mille needn't be rounded (ST-T1-A6 10.2 pkt 2)
|
|
|
|
std::string line_name(line_id const Id)
|
|
{
|
|
return std::format("line {}", number(Id));
|
|
}
|
|
|
|
std::string node_name(node_id const Id)
|
|
{
|
|
return std::format("node {}", number(Id));
|
|
}
|
|
|
|
// the values of the end of the line as the node sees them, along its heading
|
|
struct seen_end
|
|
{
|
|
glm::dvec2 heading;
|
|
double curvature;
|
|
double cant;
|
|
double grade;
|
|
};
|
|
|
|
seen_end seen(line const &Line, end_ref const &End)
|
|
{
|
|
auto const &values{End.end == line_end::start ? Line.solved.start : Line.solved.end};
|
|
auto const sense{static_cast<double>(End.sense)};
|
|
return {values.heading * sense, values.curvature * sense, values.cant * sense, values.grade * sense};
|
|
}
|
|
|
|
// the node takes what the ends it holds tell: the heading of the only one, the curvature and the cant of the first one which doesn't go
|
|
// on from it (one going on reads them), the grade of the first; true where the curvature or the cant changed
|
|
bool derive(network const &Network, node &Node)
|
|
{
|
|
auto const before{std::make_pair(Node.curvature, Node.cant)};
|
|
bool graded{false};
|
|
bool curved{false};
|
|
for (auto const &end : Node.ends)
|
|
{
|
|
auto const *owner{Network.find(end.line)};
|
|
if (owner == nullptr || false == owner->solved.valid())
|
|
continue;
|
|
auto const values{seen(*owner, end)};
|
|
if (Node.ends.size() == 1)
|
|
Node.heading = values.heading;
|
|
if (false == graded)
|
|
{
|
|
Node.grade = values.grade;
|
|
graded = true;
|
|
}
|
|
if (false == curved && false == owner->continues(end.end))
|
|
{
|
|
Node.curvature = values.curvature;
|
|
Node.cant = values.cant;
|
|
curved = true;
|
|
}
|
|
}
|
|
return before != std::make_pair(Node.curvature, Node.cant);
|
|
}
|
|
|
|
norms::element reversed(norms::element Element, double const Length)
|
|
{
|
|
auto const start{Element.start};
|
|
Element.start = Length - (start + Element.length);
|
|
auto const curvature{Element.curvature_start};
|
|
Element.curvature_start = -Element.curvature_end;
|
|
Element.curvature_end = -curvature;
|
|
std::swap(Element.from, Element.to);
|
|
std::swap(Element.open_start, Element.open_end);
|
|
return Element;
|
|
}
|
|
|
|
// the elements run on alike: the same kind, the curvature going on as it did
|
|
bool runs_on(norms::element const &A, norms::element const &B)
|
|
{
|
|
// two halves of Bloss curves make no Bloss curve
|
|
if (A.kind != B.kind || A.bloss || B.bloss || std::abs(A.curvature_end - B.curvature_start) > kCurvature || A.speed != B.speed || A.features != B.features)
|
|
return false;
|
|
if (A.kind != norms::element_kind::transition)
|
|
return std::abs(A.curvature_start - B.curvature_end) <= kCurvature;
|
|
auto const rate_a{(A.curvature_end - A.curvature_start) / std::max(A.length, 1e-9)};
|
|
auto const rate_b{(B.curvature_end - B.curvature_start) / std::max(B.length, 1e-9)};
|
|
return std::abs(rate_a - rate_b) <= 1e-6 * std::max(std::abs(rate_a), std::abs(rate_b)) + 1e-12;
|
|
}
|
|
|
|
char const *parameter_name(norms::parameter const What)
|
|
{
|
|
switch (What)
|
|
{
|
|
case norms::parameter::cant_deficiency: return "cant deficiency";
|
|
case norms::parameter::cant_excess: return "cant excess";
|
|
case norms::parameter::deficiency_jump: return "step of the cant deficiency";
|
|
case norms::parameter::cant_gradient: return "cant ramp";
|
|
case norms::parameter::cant_rate: return "rate of the cant change";
|
|
case norms::parameter::deficiency_rate: return "rate of the cant deficiency change";
|
|
case norms::parameter::element_length: return "element length";
|
|
case norms::parameter::transition_length: return "transition length";
|
|
case norms::parameter::transition_shift: return "transition shift";
|
|
case norms::parameter::radius: return "radius";
|
|
case norms::parameter::cant: return "cant";
|
|
case norms::parameter::cant_min: return "least cant";
|
|
case norms::parameter::vertical_radius: return "vertical radius";
|
|
case norms::parameter::grade: return "grade";
|
|
case norms::parameter::intermediate_length: return "element between steps";
|
|
case norms::parameter::profile_boundary: return "arc across a profile boundary";
|
|
default: return "value";
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
node const *network::find(node_id const Id) const
|
|
{
|
|
auto const found{m_nodes.find(Id)};
|
|
return found != m_nodes.end() ? &found->second : nullptr;
|
|
}
|
|
|
|
line const *network::find(line_id const Id) const
|
|
{
|
|
auto const found{m_lines.find(Id)};
|
|
return found != m_lines.end() ? &found->second : nullptr;
|
|
}
|
|
|
|
end_ref const *network::end_of(line_id const Line, line_end const End) const
|
|
{
|
|
auto const *owner{find(Line)};
|
|
if (owner == nullptr)
|
|
return nullptr;
|
|
auto const *at{find(owner->node_at(End))};
|
|
if (at == nullptr)
|
|
return nullptr;
|
|
auto const found{std::ranges::find_if(at->ends, [&](end_ref const &Ref) { return Ref.line == Line && Ref.end == End; })};
|
|
return found != at->ends.end() ? &*found : nullptr;
|
|
}
|
|
|
|
end_condition network::condition(line const &Line, line_end const End) const
|
|
{
|
|
end_condition result;
|
|
auto const *at{find(Line.node_at(End))};
|
|
if (at == nullptr)
|
|
return result;
|
|
result.position = at->position;
|
|
result.continues = Line.continues(End);
|
|
if (auto const *ref{end_of(Line.id, End)}; ref != nullptr && result.continues)
|
|
{
|
|
result.curvature = at->curvature * ref->sense;
|
|
result.cant = at->cant * ref->sense;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
line &transaction::change(line_id const Id)
|
|
{
|
|
auto &kept{m_before.lines};
|
|
if (false == kept.contains(Id))
|
|
{
|
|
auto const found{m_network.m_lines.find(Id)};
|
|
kept[Id] = found != m_network.m_lines.end() ? std::optional<line>{found->second} : std::nullopt;
|
|
}
|
|
return m_network.m_lines.at(Id);
|
|
}
|
|
|
|
node &transaction::change(node_id const Id)
|
|
{
|
|
auto &kept{m_before.nodes};
|
|
if (false == kept.contains(Id))
|
|
{
|
|
auto const found{m_network.m_nodes.find(Id)};
|
|
kept[Id] = found != m_network.m_nodes.end() ? std::optional<node>{found->second} : std::nullopt;
|
|
}
|
|
return m_network.m_nodes.at(Id);
|
|
}
|
|
|
|
line &transaction::add(line Line)
|
|
{
|
|
auto const id{Line.id};
|
|
if (false == m_before.lines.contains(id))
|
|
m_before.lines[id] = m_network.find(id) != nullptr ? std::optional<line>{*m_network.find(id)} : std::nullopt;
|
|
return m_network.m_lines[id] = std::move(Line);
|
|
}
|
|
|
|
node &transaction::add(node Node)
|
|
{
|
|
auto const id{Node.id};
|
|
if (false == m_before.nodes.contains(id))
|
|
m_before.nodes[id] = m_network.find(id) != nullptr ? std::optional<node>{*m_network.find(id)} : std::nullopt;
|
|
return m_network.m_nodes[id] = std::move(Node);
|
|
}
|
|
|
|
void transaction::erase(line_id const Id)
|
|
{
|
|
if (m_network.find(Id) == nullptr)
|
|
return;
|
|
change(Id);
|
|
m_network.m_lines.erase(Id);
|
|
}
|
|
|
|
void transaction::erase(node_id const Id)
|
|
{
|
|
if (m_network.find(Id) == nullptr)
|
|
return;
|
|
change(Id);
|
|
m_network.m_nodes.erase(Id);
|
|
}
|
|
|
|
std::set<line_id> transaction::touched_lines() const
|
|
{
|
|
std::set<line_id> result;
|
|
for (auto const &[id, before] : m_before.lines)
|
|
result.insert(id);
|
|
return result;
|
|
}
|
|
|
|
std::set<node_id> transaction::touched_nodes() const
|
|
{
|
|
std::set<node_id> result;
|
|
for (auto const &[id, before] : m_before.nodes)
|
|
result.insert(id);
|
|
return result;
|
|
}
|
|
|
|
snapshot transaction::after() const
|
|
{
|
|
snapshot result;
|
|
for (auto const &[id, before] : m_before.lines)
|
|
result.lines[id] = m_network.find(id) != nullptr ? std::optional<line>{*m_network.find(id)} : std::nullopt;
|
|
for (auto const &[id, before] : m_before.nodes)
|
|
result.nodes[id] = m_network.find(id) != nullptr ? std::optional<node>{*m_network.find(id)} : std::nullopt;
|
|
return result;
|
|
}
|
|
|
|
void transaction::roll_back()
|
|
{
|
|
restore(m_network, m_before);
|
|
m_before = {};
|
|
}
|
|
|
|
void restore(network &Network, snapshot const &State)
|
|
{
|
|
// through a transaction of its own, which is the friend of the network
|
|
transaction change{Network};
|
|
for (auto const &[id, kept] : State.lines)
|
|
{
|
|
if (kept.has_value())
|
|
change.add(*kept);
|
|
else
|
|
change.erase(id);
|
|
}
|
|
for (auto const &[id, kept] : State.nodes)
|
|
{
|
|
if (kept.has_value())
|
|
change.add(*kept);
|
|
else
|
|
change.erase(id);
|
|
}
|
|
}
|
|
|
|
void settle(transaction &Change)
|
|
{
|
|
std::set<line_id> pending;
|
|
for (auto const id : Change.touched_lines())
|
|
if (Change.view().find(id) != nullptr)
|
|
pending.insert(id);
|
|
// the nodes touched take the values of their ends too, the lines going on from them laid again where those changed; a few rounds
|
|
// settle it, each line going on from a curve depending on one node at each end
|
|
std::set<node_id> nodes{Change.touched_nodes()};
|
|
for (int round = 0; round < 8 && (false == pending.empty() || false == nodes.empty()); ++round)
|
|
{
|
|
for (auto const id : pending)
|
|
{
|
|
auto &laid{Change.change(id)};
|
|
auto const &view{Change.view()};
|
|
laid.solved = solve(laid.shape, view.condition(laid, line_end::start), view.condition(laid, line_end::end));
|
|
nodes.insert(laid.start);
|
|
nodes.insert(laid.end);
|
|
}
|
|
std::set<line_id> next;
|
|
for (auto const id : nodes)
|
|
{
|
|
auto const *existing{Change.view().find(id)};
|
|
if (existing == nullptr)
|
|
continue;
|
|
auto updated{*existing};
|
|
auto const curved{derive(Change.view(), updated)};
|
|
if (updated != *existing)
|
|
Change.change(id) = updated;
|
|
if (false == curved)
|
|
continue;
|
|
for (auto const &end : updated.ends)
|
|
if (auto const *owner{Change.view().find(end.line)}; owner != nullptr && owner->continues(end.end))
|
|
next.insert(end.line);
|
|
}
|
|
nodes.clear();
|
|
pending = std::move(next);
|
|
}
|
|
}
|
|
|
|
std::vector<chain_part> chain_of(network const &Network, line_id const Line)
|
|
{
|
|
std::vector<chain_part> result;
|
|
auto const *first{Network.find(Line)};
|
|
if (first == nullptr)
|
|
return result;
|
|
result.push_back({Line, true});
|
|
auto const contains = [&](line_id const Id) { return std::ranges::any_of(result, [&](chain_part const &Part) { return Part.line == Id; }); };
|
|
// the other end at the node, where it holds two
|
|
auto const across = [&](node_id const At, line_id const From, line_end const End) -> end_ref const * {
|
|
auto const *at{Network.find(At)};
|
|
if (at == nullptr || at->ends.size() != 2)
|
|
return nullptr;
|
|
for (auto const &end : at->ends)
|
|
if (end.line != From || end.end != End)
|
|
return &end;
|
|
return nullptr;
|
|
};
|
|
// on beyond the end of the last part
|
|
while (true)
|
|
{
|
|
auto const &last{result.back()};
|
|
auto const *owner{Network.find(last.line)};
|
|
if (owner == nullptr)
|
|
break;
|
|
auto const beyond{last.forward ? line_end::end : line_end::start};
|
|
auto const *other{across(owner->node_at(beyond), last.line, beyond)};
|
|
if (other == nullptr || contains(other->line) || Network.find(other->line) == nullptr)
|
|
break;
|
|
result.push_back({other->line, other->end == line_end::start});
|
|
}
|
|
// and back beyond the start of the first one
|
|
while (true)
|
|
{
|
|
auto const &head{result.front()};
|
|
auto const *owner{Network.find(head.line)};
|
|
if (owner == nullptr)
|
|
break;
|
|
auto const behind{head.forward ? line_end::start : line_end::end};
|
|
auto const *other{across(owner->node_at(behind), head.line, behind)};
|
|
if (other == nullptr || contains(other->line) || Network.find(other->line) == nullptr)
|
|
break;
|
|
result.insert(result.begin(), {other->line, other->end == line_end::end});
|
|
}
|
|
return result;
|
|
}
|
|
|
|
described_chain describe_chain(network const &Network, std::vector<chain_part> const &Chain)
|
|
{
|
|
described_chain result;
|
|
double offset{0.0};
|
|
for (auto const &part : Chain)
|
|
{
|
|
// the chain is made of the lines of the network: one gone is a chain out of date, of which the rest is described
|
|
auto const *found{Network.find(part.line)};
|
|
result.starts.push_back(offset);
|
|
if (found == nullptr)
|
|
continue;
|
|
auto const &owner{*found};
|
|
auto own{described(owner.solved, owner.category)};
|
|
auto const length{owner.solved.length};
|
|
if (false == part.forward)
|
|
{
|
|
for (auto &element : own.elements)
|
|
element = reversed(element, length);
|
|
std::ranges::reverse(own.elements);
|
|
for (auto &point : own.cant)
|
|
point = {length - point.chainage, -point.cant};
|
|
std::ranges::reverse(own.cant);
|
|
for (auto &grade : own.grades)
|
|
grade = {length - (grade.start + grade.length), grade.length, -grade.grade_end, -grade.grade_start};
|
|
std::ranges::reverse(own.grades);
|
|
}
|
|
for (auto element : own.elements)
|
|
{
|
|
element.start += offset;
|
|
auto &elements{result.line.elements};
|
|
if (false == elements.empty() && runs_on(elements.back(), element))
|
|
{
|
|
elements.back().length = element.end() - elements.back().start;
|
|
elements.back().curvature_end = element.curvature_end;
|
|
elements.back().to = element.to;
|
|
continue;
|
|
}
|
|
elements.push_back(element);
|
|
}
|
|
for (auto point : own.cant)
|
|
{
|
|
point.chainage += offset;
|
|
auto &cant{result.line.cant};
|
|
if (false == cant.empty() && std::abs(cant.back().chainage - point.chainage) < 1e-9 && std::abs(cant.back().cant - point.cant) < 1e-9)
|
|
continue;
|
|
cant.push_back(point);
|
|
}
|
|
for (auto grade : own.grades)
|
|
{
|
|
grade.start += offset;
|
|
result.line.grades.push_back(grade);
|
|
}
|
|
offset += length;
|
|
}
|
|
if (false == result.line.elements.empty())
|
|
{
|
|
result.line.elements.front().open_start = true;
|
|
result.line.elements.back().open_end = true;
|
|
}
|
|
if (false == Chain.empty())
|
|
result.line.name = std::format("l{}", number(Chain.front().line));
|
|
return result;
|
|
}
|
|
|
|
std::string finding_text(norms::finding const &Finding)
|
|
{
|
|
auto text{std::format("{} {:.4g}, the limit {:.4g}", parameter_name(Finding.what), Finding.value, Finding.limit)};
|
|
if (false == Finding.from.document.empty())
|
|
text += std::format(" ({} {})", Finding.from.document, Finding.from.place);
|
|
return text;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
// the invariants of the line: laid between its nodes, which know its ends
|
|
void check_line(network const &Network, line const &Line, verdict &Result)
|
|
{
|
|
for (auto const &error : Line.solved.errors)
|
|
Result.reasons.push_back(std::format("{}: {}", line_name(Line.id), error));
|
|
if (Line.start == Line.end)
|
|
Result.reasons.push_back(std::format("{} starts and ends at {}", line_name(Line.id), node_name(Line.start)));
|
|
for (auto const end : {line_end::start, line_end::end})
|
|
{
|
|
if (Network.find(Line.node_at(end)) == nullptr)
|
|
Result.reasons.push_back(std::format("{}: no {} at its {}", line_name(Line.id), node_name(Line.node_at(end)), end == line_end::start ? "start" : "end"));
|
|
else if (Network.end_of(Line.id, end) == nullptr)
|
|
Result.reasons.push_back(std::format("{} doesn't hold the {} of {}", node_name(Line.node_at(end)), end == line_end::start ? "start" : "end", line_name(Line.id)));
|
|
}
|
|
}
|
|
|
|
// the invariants of the node: its ends exist, two at most, on its two sides, and run on as one track through it
|
|
void check_node(network const &Network, node const &Node, verdict &Result)
|
|
{
|
|
if (Node.ends.empty())
|
|
Result.reasons.push_back(std::format("{} holds no end of a line", node_name(Node.id)));
|
|
if (Node.ends.size() > 2)
|
|
Result.reasons.push_back(std::format("{} holds {} ends; more than two meet only at a turnout", node_name(Node.id), Node.ends.size()));
|
|
if (Node.ends.size() == 2 && Node.ends[0].side() == Node.ends[1].side())
|
|
Result.reasons.push_back(std::format("{}: both lines lie on the same side of it", node_name(Node.id)));
|
|
for (auto const &end : Node.ends)
|
|
{
|
|
auto const *owner{Network.find(end.line)};
|
|
if (owner == nullptr || owner->node_at(end.end) != Node.id || std::abs(end.sense) != 1)
|
|
{
|
|
Result.reasons.push_back(std::format("{} holds an end of {}, which doesn't end there", node_name(Node.id), line_name(end.line)));
|
|
continue;
|
|
}
|
|
if (false == owner->solved.valid())
|
|
continue;
|
|
auto const &values{end.end == line_end::start ? owner->solved.start : owner->solved.end};
|
|
if (values.position != Node.position)
|
|
Result.reasons.push_back(std::format("{} doesn't end at {}", line_name(end.line), node_name(Node.id)));
|
|
auto const ends{seen(*owner, end)};
|
|
auto const kink{std::abs(geometry::signed_angle(Node.heading, ends.heading))};
|
|
if (kink > kHeading)
|
|
Result.reasons.push_back(std::format("{} meets {} at an angle of {:.6f} deg", line_name(end.line), node_name(Node.id), glm::degrees(kink)));
|
|
if (std::abs(ends.cant - Node.cant) > kCantStep)
|
|
Result.reasons.push_back(std::format("the cant steps by {:.1f} mm at {} where {} meets it", std::abs(ends.cant - Node.cant), node_name(Node.id), line_name(end.line)));
|
|
if (std::abs(ends.grade - Node.grade) > kGradeBreak)
|
|
Result.reasons.push_back(std::format("the grade breaks by {:.1f} per mille at {} with no vertical curve", 1000.0 * std::abs(ends.grade - Node.grade), node_name(Node.id)));
|
|
// a step of the curvature, which the norms judge along the chain (the step of the cant deficiency); one going on from the node
|
|
// has its curvature by construction
|
|
if (owner->continues(end.end) && std::abs(ends.curvature - Node.curvature) > kCurvature)
|
|
Result.reasons.push_back(std::format("{} goes on from the curve of {} at another curvature", line_name(end.line), node_name(Node.id)));
|
|
}
|
|
}
|
|
|
|
void check_norms(network const &Network, std::set<line_id> const &Lines, verdict &Result)
|
|
{
|
|
std::set<line_id> done;
|
|
for (auto const id : Lines)
|
|
{
|
|
if (done.contains(id) || Network.find(id) == nullptr)
|
|
continue;
|
|
auto const chain{chain_of(Network, id)};
|
|
bool laid{true};
|
|
for (auto const &part : chain)
|
|
{
|
|
done.insert(part.line);
|
|
auto const *line{Network.find(part.line)};
|
|
laid = laid && line != nullptr && line->solved.valid();
|
|
}
|
|
if (false == laid)
|
|
continue;
|
|
auto const described{describe_chain(Network, chain)};
|
|
auto const &first{*Network.find(chain.front().line)}; // NOSONAR: every line of the chain was found just above
|
|
for (auto const &finding : norms::evaluate(described.line, first.category, Network.areas))
|
|
{
|
|
if (finding.level == norms::tier::none)
|
|
continue;
|
|
// the line it's on, by the chainage along the chain
|
|
auto part{static_cast<std::size_t>(std::upper_bound(described.starts.begin(), described.starts.end(), finding.chainage + 1e-9) - described.starts.begin())};
|
|
part = part > 0 ? part - 1 : 0;
|
|
auto const &owner{*Network.find(chain[part].line)}; // NOSONAR: every line of the chain was found just above
|
|
auto const along{finding.chainage - described.starts[part]};
|
|
auto const chainage{chain[part].forward ? along : owner.solved.length - along};
|
|
auto const text{finding_text(finding)};
|
|
if (finding.level == norms::tier::block)
|
|
Result.reasons.push_back(std::format("{} at {:.1f} m: {}", line_name(owner.id), chainage, text));
|
|
else if (Lines.contains(owner.id))
|
|
Result.notices.push_back({owner.id, chainage, finding, text});
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
verdict check(network const &Network, std::set<line_id> const &Lines, std::set<node_id> const &Nodes)
|
|
{
|
|
verdict result;
|
|
std::set<node_id> nodes{Nodes};
|
|
for (auto const id : Lines)
|
|
{
|
|
auto const *owner{Network.find(id)};
|
|
if (owner == nullptr)
|
|
continue;
|
|
check_line(Network, *owner, result);
|
|
nodes.insert(owner->start);
|
|
nodes.insert(owner->end);
|
|
}
|
|
for (auto const id : nodes)
|
|
if (auto const *at{Network.find(id)}; at != nullptr)
|
|
check_node(Network, *at, result);
|
|
if (result.fine())
|
|
check_norms(Network, Lines, result);
|
|
return result;
|
|
}
|
|
|
|
verdict check_all(network const &Network)
|
|
{
|
|
std::set<line_id> lines;
|
|
std::set<node_id> nodes;
|
|
for (auto const &[id, owner] : Network.lines())
|
|
lines.insert(id);
|
|
for (auto const &[id, at] : Network.nodes())
|
|
nodes.insert(id);
|
|
return check(Network, lines, nodes);
|
|
}
|
|
|
|
} // namespace layout
|