18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 18:35:00 +01:00

Merge remote-tracking branch 'origin/master' into fix/et42-fans-compressor-lamps-et22-louvre

Conflict in McZapkie/Mover.cpp, MotorBlowersCheck(): the blower's power source stays in
MotorBlowerPowerIsAvailable(), which for a blower on the main circuit now asks
MainCircuitPowered() instead of Mains (PantRequiresMain, #272), so the line contactors
interlock sees it too. MotorConnectorsCheck() merged by itself: master's undervoltage
relay in connectorsoff, and LineContactorsInterlockReleased() on the return.
This commit is contained in:
jerrrrycho
2026-11-11 22:53:50 +01:00
250 changed files with 107775 additions and 12886 deletions

View File

@@ -21,6 +21,17 @@ add_executable(${UNIT_TESTS_NAME}
invariants.cpp
figures.cpp
engine_stubs.cpp
editor_stubs.cpp
# the geometry of the lines the track editor designs, standing on its own
"${CMAKE_SOURCE_DIR}/editor/editorAlignment.cpp"
# and the heights of the tracks laid
"${CMAKE_SOURCE_DIR}/editor/editorGroundFollow.cpp"
"${CMAKE_SOURCE_DIR}/editor/editorProfile.cpp"
# and the switches laid into the curves
"${CMAKE_SOURCE_DIR}/editor/editorSwitchCurve.cpp"
# and the fouling points of the switches, widened in the curves as the gauge is
"${CMAKE_SOURCE_DIR}/editor/editorGauge.cpp"
"${CMAKE_SOURCE_DIR}/editor/editorFouling.cpp"
${UNIT_TEST_CASES})
# the core library brings the game's build settings along

View File

@@ -21,6 +21,8 @@ Coverage was measured on Windows with MSVC's SanitizerCoverage (`/fsanitize-cove
The aim is branch coverage with the rest explained below, not 100%.
The numbers above are from 2026-11-01. Since then the **Coverage** workflow (`.github/workflows/coverage.yml`) measures every pull request and every push to master: a GCC build of the unit tests with gcov, lines, functions and branches per source file of the core library. The totals and the per-file table are in the summary of the workflow run, and the HTML report with the lines marked is in its `unit-test-coverage` artifact. Its counts are source lines and gcov's branches, so they differ somewhat from the blocks in the table. The report isn't sent to SonarQube Cloud: the project's quality gate would then require 80% coverage of the new code of every pull request.
## Code nothing in the game runs
Nothing creates these objects or calls these functions anywhere in the game, which was checked against the whole source tree. A refactor can delete them, or leave them untested.

View File

@@ -0,0 +1,420 @@
# the last stretch of the ground of a line as the fit onto the terrain model has it: chainage, height, tolerance, reach (all m).
# A viaduct at 80..120 with no model on it, the line held over the track below at 89..100; a level field past it up to the loose end
0.13 80.0098 0.15 0.15
1.11 80.0015 0.15 0.15
2.08 80.0439 0.15 0.15
3.05 80.0147 0.15 0.15
4.03 80.0276 0.15 0.15
5 80.0198 0.15 0.15
5.98 80.0325 0.15 0.15
6.95 80.0354 0.15 0.15
7.93 80.037 0.15 0.15
8.78 80.0731 0.15 0.15
9.63 80.0286 0.15 0.15
10.24 80.0603 0.15 0.15
10.85 80.0809 0.15 0.15
11.72 80.058 0.15 0.15
12.59 80.0617 0.15 0.15
13.46 80.0658 0.15 0.15
14.37 80.0807 0.15 0.15
15.28 80.106 0.15 0.15
16.19 80.0841 0.15 0.15
17.11 80.1022 0.15 0.15
18.02 80.0831 0.15 0.15
18.93 80.1051 0.15 0.15
19.84 80.1197 0.15 0.15
20.76 80.1041 0.15 0.15
21.68 80.1111 0.15 0.15
22.6 80.1129 0.15 0.15
23.52 80.1422 0.15 0.15
24.44 80.109 0.15 0.15
25.36 80.0932 0.15 0.15
26.28 80.1164 0.15 0.15
27.2 80.1181 0.15 0.15
28.12 80.135 0.15 0.15
29.03 80.1202 0.15 0.15
29.95 80.1463 0.15 0.15
30.87 80.1427 0.15 0.15
31.87 80.168 0.15 0.15
32.87 80.1317 0.15 0.15
33.87 80.1506 0.15 0.15
34.87 80.142 0.15 0.15
35.87 80.1834 0.15 0.15
36.87 80.1599 0.15 0.15
37.87 80.1599 0.15 0.15
38.87 80.1644 0.15 0.15
39.87 80.1772 0.15 0.15
40.87 80.1904 0.15 0.15
41.86 80.1682 0.15 0.15
42.85 80.1858 0.15 0.15
43.84 80.158 0.15 0.15
44.83 80.1605 0.15 0.15
45.82 80.1783 0.15 0.15
46.81 80.2093 0.15 0.15
47.8 80.1863 0.15 0.15
48.78 80.2119 0.15 0.15
49.77 80.1858 0.15 0.15
50.76 80.2059 0.15 0.15
51.75 80.2138 0.15 0.15
52.74 80.2015 0.15 0.15
53.73 80.2047 0.15 0.15
54.72 80.2141 0.15 0.15
55.71 80.1827 0.15 0.15
56.7 80.2171 0.15 0.15
57.69 80.1903 0.15 0.15
58.67 80.2235 0.15 0.15
59.66 80.1961 0.15 0.15
60.65 80.1834 0.15 0.15
61.64 80.1877 0.15 0.15
62.63 80.212 0.15 0.15
63.62 80.2247 0.15 0.15
64.61 80.2446 0.15 0.15
65.6 80.195 0.15 0.15
66.59 80.2567 0.15 0.15
67.58 80.2717 0.15 0.15
68.56 80.258 0.15 0.15
69.55 80.271 0.15 0.15
70.54 80.2573 0.15 0.15
71.53 80.2506 0.15 0.15
72.52 80.2993 0.15 0.15
73.51 80.2726 0.15 0.15
74.5 80.2649 0.15 0.15
75.49 80.2581 0.15 0.15
76.48 80.2659 0.15 0.15
77.47 80.2806 0.15 0.15
78.45 79.8139 0.15 0.15
79.44 79.2243 0.15 0.15
80.43 nan 0.15 0.15
81.41 nan 0.15 0.15
82.4 nan 0.15 0.15
83.39 nan 0.15 0.15
84.37 nan 0.15 0.15
85.36 nan 0.15 0.15
86.34 nan 0.15 0.15
87.33 nan 0.15 0.15
88.33 nan 0.15 0.15
89.32 nan 0.15 0.15
89.32 79.1589 0.02 30
90.31 nan 0.15 0.15
90.31 79.16 0.02 30
91.3 nan 0.15 0.15
91.3 79.1611 0.02 30
92.3 nan 0.15 0.15
92.3 79.1622 0.02 30
93.29 nan 0.15 0.15
93.29 79.1634 0.02 30
94.28 nan 0.15 0.15
94.28 79.1645 0.02 30
95.27 nan 0.15 0.15
95.27 79.1656 0.02 30
96.27 nan 0.15 0.15
96.27 79.1667 0.02 30
97.26 nan 0.15 0.15
97.26 79.1678 0.02 30
98.25 nan 0.15 0.15
98.25 79.1689 0.02 30
99.24 nan 0.15 0.15
99.24 79.17 0.02 30
100.23 nan 0.15 0.15
100.23 79.1711 0.02 30
101.23 nan 0.15 0.15
102.22 nan 0.15 0.15
103.21 nan 0.15 0.15
104.2 nan 0.15 0.15
105.19 nan 0.15 0.15
106.19 nan 0.15 0.15
107.11 nan 0.15 0.15
108.03 nan 0.15 0.15
108.95 nan 0.15 0.15
109.87 nan 0.15 0.15
110.79 nan 0.15 0.15
111.05 nan 0.15 0.15
111.32 nan 0.15 0.15
111.48 nan 0.15 0.15
111.63 nan 0.15 0.15
112.19 nan 0.15 0.15
112.74 nan 0.15 0.15
113.2 nan 0.15 0.15
113.66 nan 0.15 0.15
114.5 nan 0.15 0.15
115.35 nan 0.15 0.15
115.97 nan 0.15 0.15
116.59 nan 0.15 0.15
116.72 nan 0.15 0.15
116.86 nan 0.15 0.15
117.17 nan 0.15 0.15
117.48 nan 0.15 0.15
118.16 nan 0.15 0.15
118.85 nan 0.15 0.15
119.54 nan 0.15 0.15
120.11 79.5999 0.15 0.15
120.67 79.8142 0.15 0.15
120.97 79.9073 0.15 0.15
121.26 80.0019 0.15 0.15
121.43 80.0558 0.15 0.15
121.59 80.1101 0.15 0.15
122.55 80.2962 0.15 0.15
123.5 80.3937 0.15 0.15
124.46 80.3862 0.15 0.15
125.42 80.4118 0.15 0.15
126.38 80.409 0.15 0.15
127.33 80.3708 0.15 0.15
128.29 80.3634 0.15 0.15
129.22 80.3619 0.15 0.15
130.15 80.345 0.15 0.15
131.09 80.355 0.15 0.15
132.02 80.3542 0.15 0.15
132.95 80.3499 0.15 0.15
133.45 80.345 0.15 0.15
133.96 80.3526 0.15 0.15
134.75 80.2781 0.15 0.15
135.55 80.2671 0.15 0.15
136.35 80.2619 0.15 0.15
137.29 80.3038 0.15 0.15
138.24 80.3516 0.15 0.15
139.18 80.3255 0.15 0.15
140.13 80.3078 0.15 0.15
141.07 80.3296 0.15 0.15
142.01 80.3411 0.15 0.15
142.96 80.3127 0.15 0.15
143.9 80.3474 0.15 0.15
144.85 80.335 0.15 0.15
145.79 80.3042 0.15 0.15
146.76 80.2855 0.15 0.15
147.73 80.3033 0.15 0.15
148.71 80.3381 0.15 0.15
149.68 80.3272 0.15 0.15
150.65 80.3059 0.15 0.15
151.62 80.2809 0.15 0.15
152.59 80.2728 0.15 0.15
153.57 80.2876 0.15 0.15
154.54 80.1599 0.15 0.15
155.51 78.8547 0.15 0.15
156.48 nan 0.15 0.15
157.46 nan 0.15 0.15
158.43 nan 0.15 0.15
159.4 nan 0.15 0.15
160.37 nan 0.15 0.15
161.34 nan 0.15 0.15
161.56 79.2239 0.15 0.15
161.78 79.5581 0.15 0.15
162.54 80.1315 0.15 0.15
163.29 80.2649 0.15 0.15
164.29 80.2722 0.15 0.15
165.28 80.2736 0.15 0.15
166.28 80.2655 0.15 0.15
167.28 80.2369 0.15 0.15
168.28 80.2283 0.15 0.15
169.27 80.2201 0.15 0.15
170.27 80.2191 0.15 0.15
171.27 80.2315 0.15 0.15
172.27 80.2518 0.15 0.15
173.27 80.2673 0.15 0.15
174.26 80.2422 0.15 0.15
175.21 80.2376 0.15 0.15
176.16 80.236 0.15 0.15
177.11 80.2071 0.15 0.15
178.05 80.2064 0.15 0.15
179 80.2092 0.15 0.15
179.95 80.2443 0.15 0.15
180.89 80.2233 0.15 0.15
181.84 80.2156 0.15 0.15
182.79 80.2071 0.15 0.15
183.74 80.1883 0.15 0.15
184.65 80.2062 0.15 0.15
185.56 80.2256 0.15 0.15
186.47 80.2001 0.15 0.15
187.38 80.1912 0.15 0.15
188.29 80.1444 0.15 0.15
189.2 80.1761 0.15 0.15
190.11 80.1691 0.15 0.15
191.02 80.1941 0.15 0.15
191.99 80.1732 0.15 0.15
192.96 80.1946 0.15 0.15
193.93 80.2007 0.15 0.15
194.9 80.1481 0.15 0.15
195.87 80.1769 0.15 0.15
196.85 80.1768 0.15 0.15
197.82 80.1736 0.15 0.15
198.79 80.1739 0.15 0.15
199.76 80.1801 0.15 0.15
200.73 80.1761 0.15 0.15
201.7 80.1857 0.15 0.15
202.54 80.1641 0.15 0.15
203.37 80.1818 0.15 0.15
204.21 80.1742 0.15 0.15
205.05 80.1618 0.15 0.15
205.81 80.1514 0.15 0.15
206.58 80.17 0.15 0.15
207.35 80.191 0.15 0.15
208.11 80.1837 0.15 0.15
209.08 80.152 0.15 0.15
210.05 80.1375 0.15 0.15
211.02 80.1722 0.15 0.15
211.74 80.1588 0.15 0.15
212.45 80.1509 0.15 0.15
213.17 80.14 0.15 0.15
213.55 80.1407 0.15 0.15
213.93 80.1426 0.15 0.15
214.89 80.1492 0.15 0.15
215.85 80.1584 0.15 0.15
216.8 80.1439 0.15 0.15
217.76 80.1628 0.15 0.15
218.72 80.1517 0.15 0.15
219.68 80.1559 0.15 0.15
220.64 80.1394 0.15 0.15
221.6 80.1287 0.15 0.15
222.44 80.1592 0.15 0.15
223.27 80.1546 0.15 0.15
224.11 80.1672 0.15 0.15
224.94 80.1622 0.15 0.15
225.77 80.1195 0.15 0.15
226.61 80.1597 0.15 0.15
227.59 80.1549 0.15 0.15
228.58 80.1613 0.15 0.15
229.56 80.1691 0.15 0.15
230.55 80.1578 0.15 0.15
231.53 80.1294 0.15 0.15
232.52 80.1273 0.15 0.15
233.5 80.127 0.15 0.15
234.49 80.1099 0.15 0.15
235.19 80.1399 0.15 0.15
235.9 80.108 0.15 0.15
236.6 80.1275 0.15 0.15
237.17 80.1106 0.15 0.15
237.74 80.1461 0.15 0.15
238.69 80.1346 0.15 0.15
239.64 80.1183 0.15 0.15
240.58 80.1181 0.15 0.15
241.53 80.1248 0.15 0.15
242.48 80.15 0.15 0.15
243.43 80.1453 0.15 0.15
244.37 80.101 0.15 0.15
245.31 80.1168 0.15 0.15
246.25 80.1505 0.15 0.15
247.2 80.1199 0.15 0.15
248.14 80.147 0.15 0.15
249.08 80.1376 0.15 0.15
249.29 80.145 0.15 0.15
249.49 80.1453 0.15 0.15
250.42 80.1298 0.15 0.15
251.36 80.1248 0.15 0.15
252.29 80.1278 0.15 0.15
253.23 80.1393 0.15 0.15
254.16 80.1187 0.15 0.15
255.09 80.1332 0.15 0.15
256.03 80.1087 0.15 0.15
256.96 80.1142 0.15 0.15
257.89 80.1294 0.15 0.15
258.83 80.1382 0.15 0.15
259.76 80.1507 0.15 0.15
260.71 80.132 0.15 0.15
261.65 80.1527 0.15 0.15
262.6 80.1261 0.15 0.15
263.54 80.1385 0.15 0.15
264.49 80.1426 0.15 0.15
265.49 80.1432 0.15 0.15
266.49 80.1116 0.15 0.15
267.49 80.1318 0.15 0.15
268.49 80.1014 0.15 0.15
269.49 80.0957 0.15 0.15
270.49 80.117 0.15 0.15
271.49 80.138 0.15 0.15
272.49 80.1022 0.15 0.15
273.49 80.1407 0.15 0.15
274.49 80.1295 0.15 0.15
275.49 80.0953 0.15 0.15
276.49 80.0998 0.15 0.15
277.49 80.121 0.15 0.15
278.49 80.1027 0.15 0.15
279.49 80.1303 0.15 0.15
280.48 80.1142 0.15 0.15
281.48 80.122 0.15 0.15
282.47 80.1135 0.15 0.15
283.46 80.1005 0.15 0.15
284.45 80.0902 0.15 0.15
285.45 80.0823 0.15 0.15
286.44 80.0986 0.15 0.15
287.43 80.0902 0.15 0.15
288.43 80.0673 0.15 0.15
289.42 80.098 0.15 0.15
290.41 80.1072 0.15 0.15
291.41 80.0789 0.15 0.15
292.4 80.0933 0.15 0.15
293.39 80.0876 0.15 0.15
294.39 80.0735 0.15 0.15
295.38 80.0595 0.15 0.15
296.37 80.0521 0.15 0.15
297.37 80.0726 0.15 0.15
298.36 80.0685 0.15 0.15
299.35 80.093 0.15 0.15
300.35 80.0585 0.15 0.15
301.34 80.0404 0.15 0.15
302.33 80.059 0.15 0.15
303.33 80.0668 0.15 0.15
304.32 80.0617 0.15 0.15
305.31 80.0651 0.15 0.15
306.31 80.0445 0.15 0.15
307.3 80.0336 0.15 0.15
308.3 80.0458 0.15 0.15
309.29 80.0393 0.15 0.15
310.28 80.0142 0.15 0.15
311.28 80.0282 0.15 0.15
312.27 80.0181 0.15 0.15
313.26 79.995 0.15 0.15
314.25 80.0225 0.15 0.15
315.25 79.996 0.15 0.15
316.24 79.9981 0.15 0.15
317.23 80.0058 0.15 0.15
318.23 80.0087 0.15 0.15
319.22 79.9911 0.15 0.15
320.21 79.9839 0.15 0.15
321.21 80.0101 0.15 0.15
322.21 79.9765 0.15 0.15
323.21 79.9878 0.15 0.15
324.2 79.9784 0.15 0.15
325.2 80 0.15 0.15
326.2 79.9763 0.15 0.15
327.19 79.9631 0.15 0.15
328.19 79.98 0.15 0.15
329.19 79.9492 0.15 0.15
330.19 79.926 0.15 0.15
331.18 79.9357 0.15 0.15
332.18 79.9425 0.15 0.15
333.18 79.9195 0.15 0.15
334.17 79.9519 0.15 0.15
335.17 79.9423 0.15 0.15
336.17 79.9189 0.15 0.15
337.16 79.9041 0.15 0.15
338.16 79.9282 0.15 0.15
339.16 79.9244 0.15 0.15
340.16 79.9136 0.15 0.15
341.15 79.9174 0.15 0.15
342.15 79.9046 0.15 0.15
343.15 79.9095 0.15 0.15
344.14 79.8998 0.15 0.15
345.14 79.9607 0.15 0.15
346.14 79.9022 0.15 0.15
347.14 79.9167 0.15 0.15
348.13 79.904 0.15 0.15
349.13 79.9172 0.15 0.15
350.13 79.8972 0.15 0.15
351.12 79.9275 0.15 0.15
352.12 79.931 0.15 0.15
353.12 79.8963 0.15 0.15
354.12 79.8947 0.15 0.15
355.11 79.9034 0.15 0.15
356.11 79.9246 0.15 0.15
357.11 79.8982 0.15 0.15
358.1 79.9215 0.15 0.15
359.1 79.9138 0.15 0.15
360.1 79.9222 0.15 0.15
361.1 79.9026 0.15 0.15
362.09 79.9095 0.15 0.15
363.09 79.9326 0.15 0.15
364.09 79.8904 0.15 0.15
365.08 79.9064 0.15 0.15
366.08 79.9456 0.15 0.15
367.08 79.9383 0.15 0.15
368.08 79.935 0.15 0.15
369.07 79.9335 0.15 0.15

View File

@@ -0,0 +1,358 @@
# the tracks of z93_1 .. editor_track_321 on lk357 after the grade lines were shared, as profiledump writes them: S chainage height grade track model, P the design laid anew, C the ends joined, Z the switches, L the speed and the norms
S 0.0000 62.7964 -0.0026
S 0.9007 62.7940 -0.0026
S 1.8014 62.7917 -0.0026
S 2.7021 62.7893 -0.0026
S 3.6028 62.7869 -0.0026
S 4.5035 62.7846 -0.0026
S 5.0832 62.7831 -0.0026
S 5.6629 62.7816 -0.0026
S 6.5509 62.7793 -0.0026
S 7.4388 62.7770 -0.0026
S 8.3461 62.7745 -0.0028
S 9.2534 62.7720 -0.0028
S 10.1607 62.7695 -0.0028
S 11.0680 62.7670 -0.0028
S 11.9752 62.7645 -0.0028
S 12.8825 62.7620 -0.0028
S 13.7898 62.7595 -0.0028
S 14.7590 62.7567 -0.0028
S 15.7282 62.7540 -0.0028
S 16.6974 62.7512 -0.0028
S 17.6666 62.7485 -0.0028
S 18.6359 62.7458 -0.0028
S 19.6051 62.7430 -0.0028
S 20.5743 62.7403 -0.0028
S 21.5435 62.7375 -0.0028
S 22.5127 62.7348 -0.0028
S 23.4819 62.7320 -0.0028
S 24.4511 62.7293 -0.0028
S 25.4204 62.7266 -0.0028
S 26.3896 62.7238 -0.0028
S 27.3588 62.7211 -0.0028
S 28.3280 62.7183 -0.0028
S 29.2972 62.7156 -0.0028
S 30.2664 62.7128 -0.0028
S 31.2356 62.7101 -0.0028
S 32.2049 62.7074 -0.0028
S 33.1741 62.7046 -0.0028
S 34.1433 62.7019 -0.0028
S 35.1125 62.6991 -0.0028
S 36.0817 62.6964 -0.0028
S 37.0509 62.6936 -0.0028
S 38.0201 62.6909 -0.0028
S 38.9894 62.6882 -0.0028
S 39.9586 62.6854 -0.0028
S 40.9278 62.6827 -0.0028
S 41.7994 62.6799 -0.0032
S 42.6711 62.6771 -0.0032
S 43.5428 62.6744 -0.0032
S 44.4144 62.6716 -0.0032
S 44.8026 62.6703 -0.0035
S 45.1908 62.6689 -0.0035
S 46.1327 62.6654 -0.0037
S 47.0747 62.6618 -0.0037
S 48.0166 62.6583 -0.0037
S 48.9586 62.6548 -0.0037
S 49.3364 62.6533 -0.0040
S 49.7142 62.6518 -0.0040
S 50.0199 62.6505 -0.0042
S 50.3256 62.6492 -0.0042
S 50.8050 62.6471 -0.0044
S 51.2844 62.6450 -0.0044
S 51.4381 62.6442 -0.0049
S 51.5919 62.6435 -0.0049
S 52.5462 62.6382 -0.0056
S 53.5005 62.6328 -0.0058
S 54.4548 62.6271 -0.0061
S 55.4092 62.6212 -0.0063
S 56.3635 62.6151 -0.0065
S 57.3179 62.6088 -0.0068
S 58.2722 62.6022 -0.0070
S 59.2265 62.5954 -0.0072
S 60.1809 62.5884 -0.0075
S 60.5880 62.5853 -0.0077
S 60.9952 62.5821 -0.0078
S 61.1243 62.5811 -0.0080
S 61.2533 62.5801 -0.0080
S 61.7266 62.5762 -0.0083
S 62.1999 62.5722 -0.0084
S 62.4313 62.5703 -0.0085
S 62.6628 62.5683 -0.0085
S 63.5741 62.5605 -0.0086
S 64.4854 62.5526 -0.0086
S 65.3966 62.5448 -0.0086
S 66.3079 62.5369 -0.0086
S 67.2192 62.5291 -0.0086
S 68.1304 62.5212 -0.0086
S 69.0416 62.5133 -0.0086
S 69.9528 62.5055 -0.0086
S 70.8640 62.4976 -0.0086
S 71.7751 62.4897 -0.0086
S 72.6862 62.4819 -0.0086
S 73.6718 62.4735 -0.0085
S 74.6573 62.4651 -0.0085
S 75.6429 62.4567 -0.0085
S 76.6285 62.4484 -0.0085
S 77.6141 62.4400 -0.0085
S 78.5998 62.4316 -0.0085
S 79.5854 62.4233 -0.0085
S 80.5711 62.4149 -0.0085
S 81.5568 62.4065 -0.0085
S 82.5425 62.3981 -0.0085
S 83.5283 62.3898 -0.0085
S 84.5140 62.3814 -0.0085
S 85.4997 62.3730 -0.0085
S 86.4855 62.3646 -0.0085
S 87.4712 62.3563 -0.0085
S 88.4570 62.3479 -0.0085
S 89.4427 62.3395 -0.0085
S 90.4285 62.3311 -0.0085
S 91.4143 62.3228 -0.0085
S 92.4000 62.3144 -0.0085
S 93.3857 62.3060 -0.0085
S 94.3715 62.2976 -0.0085
S 95.3572 62.2893 -0.0085
S 96.3429 62.2809 -0.0085
S 97.3286 62.2725 -0.0085
S 98.3142 62.2641 -0.0085
S 99.2999 62.2558 -0.0085
S 100.2855 62.2474 -0.0085
S 101.2711 62.2390 -0.0085
S 102.2567 62.2306 -0.0085
S 103.2423 62.2223 -0.0085
S 104.2278 62.2139 -0.0085
S 104.9860 62.2079 -0.0079
S 105.7443 62.2019 -0.0079
S 106.5025 62.1959 -0.0079
S 107.4717 62.1885 -0.0076
S 108.4410 62.1811 -0.0076
S 109.4102 62.1737 -0.0076
S 110.3794 62.1663 -0.0076
S 111.3486 62.1589 -0.0076
S 112.3178 62.1515 -0.0076
S 113.2870 62.1441 -0.0076
S 114.2562 62.1367 -0.0076
S 115.2255 62.1293 -0.0076
S 116.1947 62.1219 -0.0076
S 117.1639 62.1145 -0.0076
S 118.1331 62.1071 -0.0076
S 119.1023 62.0997 -0.0076
S 120.0715 62.0923 -0.0076
S 121.0407 62.0849 -0.0076
S 122.0100 62.0775 -0.0076
S 122.9792 62.0701 -0.0076
S 123.9484 62.0627 -0.0076
S 124.9176 62.0553 -0.0076
S 125.8868 62.0479 -0.0076
S 126.8560 62.0405 -0.0076
S 127.8252 62.0331 -0.0076
S 128.7945 62.0257 -0.0076
S 129.7637 62.0183 -0.0076
S 130.7329 62.0109 -0.0076
S 131.7021 62.0035 -0.0076
S 132.6713 61.9961 -0.0076
S 133.6405 61.9887 -0.0076
S 133.9514 61.9866 -0.0067
S 134.2622 61.9845 -0.0067
S 135.2318 61.9783 -0.0064
S 136.2013 61.9721 -0.0064
S 137.1709 61.9659 -0.0064
S 138.1404 61.9597 -0.0064
S 139.1100 61.9534 -0.0064
S 140.0796 61.9472 -0.0064
S 141.0491 61.9410 -0.0064
S 142.0187 61.9348 -0.0064
S 142.9882 61.9286 -0.0064
S 143.9578 61.9223 -0.0064
S 144.9274 61.9161 -0.0064
S 145.8969 61.9099 -0.0064
S 146.8665 61.9037 -0.0064
S 147.8360 61.8975 -0.0064
S 148.8056 61.8913 -0.0064
S 149.7752 61.8850 -0.0064
S 150.7531 61.8790 -0.0062
S 151.7310 61.8730 -0.0062
S 152.7089 61.8670 -0.0062
S 153.6868 61.8610 -0.0062
S 154.6647 61.8549 -0.0062
S 155.6426 61.8489 -0.0062
S 156.6205 61.8429 -0.0062
S 157.5984 61.8369 -0.0062
S 158.5763 61.8309 -0.0062
S 159.5542 61.8249 -0.0062
S 160.5322 61.8188 -0.0062
S 161.5101 61.8128 -0.0062
S 162.4880 61.8068 -0.0062
S 163.4659 61.8008 -0.0062
S 164.4438 61.7948 -0.0062
S 165.4217 61.7888 -0.0062
S 166.3996 61.7827 -0.0062
S 167.3775 61.7767 -0.0062
S 168.3554 61.7707 -0.0062
S 169.3333 61.7647 -0.0062
S 170.3112 61.7587 -0.0062
S 171.2892 61.7526 -0.0062
S 172.2671 61.7466 -0.0062
S 173.2450 61.7406 -0.0062
S 174.2229 61.7346 -0.0062
S 175.2008 61.7286 -0.0062
S 176.1787 61.7226 -0.0062
S 177.1566 61.7165 -0.0062
S 178.1345 61.7105 -0.0062
S 179.1124 61.7045 -0.0062
S 180.0903 61.6985 -0.0062
S 181.0541 61.6927 -0.0060
S 182.0179 61.6870 -0.0060
S 182.9817 61.6812 -0.0060
S 183.9455 61.6754 -0.0060
S 184.9093 61.6697 -0.0060
S 185.8731 61.6639 -0.0060
S 186.7574 61.6588 -0.0058
S 187.6417 61.6536 -0.0058
S 188.5259 61.6485 -0.0058
S 189.4102 61.6433 -0.0058
S 190.2944 61.6382 -0.0058
S 190.4833 61.6371 -0.0056
S 190.6723 61.6361 -0.0056
S 190.8468 61.6351 -0.0053
S 191.0213 61.6342 -0.0053
S 191.9427 61.6297 -0.0047
S 192.8640 61.6255 -0.0045
S 193.7853 61.6214 -0.0043
S 194.7066 61.6176 -0.0041
S 195.6669 61.6140 -0.0037
S 196.6271 61.6105 -0.0034
S 197.5873 61.6074 -0.0032
S 198.5475 61.6044 -0.0030
S 199.5077 61.6017 -0.0027
S 200.4679 61.5992 -0.0025
S 201.4281 61.5969 -0.0022
S 202.3883 61.5949 -0.0020
S 203.3485 61.5931 -0.0018
S 204.3086 61.5915 -0.0015
S 205.2688 61.5902 -0.0013
S 206.2580 61.5892 -0.0009
S 207.2471 61.5884 -0.0007
S 208.2363 61.5879 -0.0004
S 209.2255 61.5876 -0.0002
S 210.2147 61.5876 0.0001
S 211.2038 61.5878 0.0003
S 212.1930 61.5882 0.0006
S 213.1822 61.5889 0.0008
S 214.1714 61.5898 0.0011
S 215.1606 61.5910 0.0013
S 216.1499 61.5924 0.0016
S 217.1391 61.5941 0.0018
S 218.1283 61.5960 0.0021
S 219.1176 61.5982 0.0023
S 220.1069 61.6006 0.0026
S 221.0962 61.6033 0.0028
S 222.0855 61.6061 0.0030
S 223.0748 61.6093 0.0033
S 224.0641 61.6127 0.0035
S 225.0535 61.6163 0.0038
S 225.2278 61.6170 0.0040
S 225.4020 61.6177 0.0040
S 225.6376 61.6187 0.0043
S 225.8731 61.6197 0.0043
S 226.7710 61.6238 0.0047
S 227.6689 61.6281 0.0049
S 228.5668 61.6325 0.0051
S 229.4647 61.6372 0.0053
S 230.3626 61.6421 0.0056
S 231.0092 61.6458 0.0056
S 231.6559 61.6494 0.0056
S 232.6438 61.6550 0.0057
S 233.6318 61.6607 0.0057
S 234.6198 61.6663 0.0057
S 235.6078 61.6720 0.0057
S 236.5958 61.6776 0.0057
S 237.5838 61.6832 0.0057
S 238.5718 61.6889 0.0057
S 239.5598 61.6945 0.0057
S 240.5477 61.7002 0.0057
S 241.5357 61.7058 0.0057
S 242.5237 61.7114 0.0057
S 243.5105 61.7171 0.0058
S 244.4973 61.7228 0.0058
S 245.4842 61.7285 0.0058
S 246.4710 61.7342 0.0058
S 247.4578 61.7399 0.0058
S 248.4446 61.7456 0.0058
S 249.4314 61.7513 0.0058
S 250.4182 61.7570 0.0058
S 251.4050 61.7627 0.0058
S 252.3918 61.7684 0.0058
S 253.3786 61.7741 0.0058
S 254.3655 61.7798 0.0058
S 255.3523 61.7855 0.0058
S 256.3391 61.7911 0.0058
S 257.3259 61.7968 0.0058
S 258.3127 61.8025 0.0058
S 259.2995 61.8082 0.0058
S 260.2863 61.8139 0.0058
S 261.2731 61.8196 0.0058
S 262.2599 61.8253 0.0058
S 263.2468 61.8310 0.0058
S 264.2336 61.8367 0.0058
S 265.2204 61.8424 0.0058
S 266.2072 61.8481 0.0058
S 267.1940 61.8538 0.0058
S 268.1808 61.8595 0.0058
S 269.1676 61.8652 0.0058
S 270.1544 61.8709 0.0058
S 271.1412 61.8766 0.0058
S 272.1281 61.8822 0.0058
S 273.1149 61.8879 0.0058
S 274.1017 61.8936 0.0058
S 275.0885 61.8993 0.0058
S 276.0753 61.9050 0.0058
S 277.0621 61.9107 0.0058
S 278.0489 61.9164 0.0058
S 279.0357 61.9221 0.0058
S 280.0226 61.9278 0.0058
S 281.0094 61.9335 0.0058
S 281.9962 61.9392 0.0058
S 282.9830 61.9449 0.0058
S 283.9698 61.9506 0.0058
S 284.9566 61.9563 0.0058
S 285.9434 61.9620 0.0058
S 286.9302 61.9677 0.0058
S 287.9170 61.9734 0.0058
S 288.9039 61.9790 0.0058
S 289.8907 61.9847 0.0058
S 290.8775 61.9904 0.0058
S 291.8643 61.9961 0.0058
S 292.8511 62.0018 0.0058
S 293.8379 62.0075 0.0058
S 294.8247 62.0132 0.0058
S 295.8115 62.0189 0.0058
S 296.7983 62.0246 0.0058
S 297.7852 62.0303 0.0058
S 298.7720 62.0360 0.0058
S 299.7588 62.0417 0.0058
S 300.7456 62.0474 0.0058
S 301.7324 62.0531 0.0058
S 302.7192 62.0588 0.0058
S 303.7060 62.0645 0.0058
S 304.6928 62.0701 0.0058
S 305.6796 62.0758 0.0058
S 306.6665 62.0815 0.0058
P 0.0000 62.7964 0.0000
P 4.9462 62.7826 4000.0000
P 53.0757 62.6501 4000.0000
P 195.3333 61.4371 4000.0000
P 306.6665 62.0817 0.0000
C 306.6665 1 62.7964 -0.0028 0 62.0815 0.0000
Z 0.0000 4.5035
Z 4.5035 5.6629
Z 5.6629 7.4388
Z 13.7898 40.9278
Z 40.9278 44.4144
Z 44.4144 45.1908
Z 45.1908 48.8505
Z 106.5025 133.6405
Z 133.6405 134.2622
Z 134.2622 141.0804
L 100.0000 6.0000 0.0000 0.4000 2000.0000 2.0000 0.0000 0.0050 1 1

View File

@@ -169,6 +169,13 @@ bool start_up(driven Driven, track const &Track, double Seconds, trace *Trace) {
if (diesel) {
prepare_diesel(Driven);
}
if (controlling.PantographsRequireMains && false == controlling.Mains) {
// the pantographs rise only through the closed line breaker, which closes without their voltage
for (int i = 0; i < 3 && cab.DirActive <= 0; ++i) {
cab.DirectionForward();
}
close_line_breaker(Driven);
}
if (collector) {
raise_pantographs(Driven);
}

View File

@@ -0,0 +1,13 @@
// stand-ins for the parts of the engine which the code of the editor under test reaches for: the translations give the English
// messages back as they are
#include "stdafx.h"
#include "utilities/translation.h"
locale Translations;
const char *locale::lookup_c(const char *msg, bool) { return msg; }
const std::string &locale::lookup_s(const std::string &msg, bool) { return msg; }
const char *locale::lookup_n(const char *singular, const char *plural, long long n) { return n == 1 ? singular : plural; }

View File

@@ -74,7 +74,7 @@ void node_layers::instance_begin(std::string const &, source_span const &) { //
// basic_node has no key function for the Itanium C++ ABI (tooltip() is declared plain but defined inline), so
// GCC and Clang emit its vtable wherever scenenode.h is used, here too, and the vtable wants radius_().
// the same as the game's, in scene/scenenode.cpp
float basic_node::radius_() {
float basic_node::radius_() const {
return 0.f;
}

File diff suppressed because it is too large Load Diff

88
tests/unit/test_area.cpp Normal file
View File

@@ -0,0 +1,88 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorGeometry.hpp"
#include <algorithm>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
namespace {
std::set<std::pair<int, int>> squares(std::vector<glm::dvec2> const &Polygon, double const Size) {
auto const found{geometry::squares_in(Polygon, Size)};
return {found.begin(), found.end()};
}
} // namespace
TEST_CASE("download area: the tiles a triangle touches") {
// x + y < 1000: the squares of 256 m whose corner nearest the origin lies inside
auto const found{squares({{0.0, 0.0}, {1000.0, 0.0}, {0.0, 1000.0}}, 256.0)};
std::set<std::pair<int, int>> expected;
for (int x = 0; x < 4; ++x)
for (int y = 0; x + y < 4; ++y)
expected.emplace(x, y);
CHECK(found == expected);
}
TEST_CASE("download area: the tiles of a concave polygon leave out the ones in its notch") {
// an L, 300 m wide, its arms 1000 m long
auto const found{squares({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 300.0}, {300.0, 300.0}, {300.0, 1000.0}, {0.0, 1000.0}}, 256.0)};
std::set<std::pair<int, int>> expected;
for (int x = 0; x < 4; ++x)
expected.insert({{x, 0}, {x, 1}});
for (int y = 2; y < 4; ++y)
expected.insert({{0, y}, {1, y}});
CHECK(found == expected);
CHECK(found.count({2, 2}) == 0);
}
TEST_CASE("download area: a thin band along a line touches the tiles it crosses, none further") {
// 4 m wide along the diagonal, from (10, 10) to (2000, 2000)
auto const found{squares({{10.0, 8.0}, {2000.0, 1998.0}, {2000.0, 2002.0}, {10.0, 12.0}}, 256.0)};
for (int i = 0; i < 8; ++i)
CHECK(found.count({i, i}) == 1);
CHECK(std::none_of(found.begin(), found.end(), [](std::pair<int, int> const &Key) { return std::abs(Key.first - Key.second) > 1; }));
}
TEST_CASE("download area: a polygon inside one tile, or around a corner of four") {
CHECK(squares({{10.0, 10.0}, {20.0, 10.0}, {20.0, 20.0}, {10.0, 20.0}}, 256.0) == std::set<std::pair<int, int>>{{0, 0}});
CHECK(squares({{250.0, 250.0}, {262.0, 250.0}, {262.0, 262.0}, {250.0, 262.0}}, 256.0) == std::set<std::pair<int, int>>{{0, 0}, {1, 0}, {0, 1}, {1, 1}});
// in the grid of the coordinates of Poland, about 500 km from its origin
auto const distant{squares({{500100.0, 600100.0}, {500200.0, 600100.0}, {500200.0, 600200.0}}, 256.0)};
CHECK(distant == std::set<std::pair<int, int>>{{1953, 2344}});
}
TEST_CASE("download area: a point inside or outside, a square of no size") {
std::vector<glm::dvec2> const triangle{{0.0, 0.0}, {100.0, 0.0}, {0.0, 100.0}};
CHECK(geometry::square_touches(triangle, 10.0, 10.0, 0.0));
CHECK_FALSE(geometry::square_touches(triangle, 80.0, 80.0, 0.0));
// a square holding the whole polygon touches it, with no corner of its inside
CHECK(geometry::square_touches(triangle, -50.0, -50.0, 300.0));
// fewer than three points: no area
CHECK(geometry::squares_in({{0.0, 0.0}, {100.0, 100.0}}, 256.0).empty());
}
TEST_CASE("download area: its size, whichever way round it's drawn") {
std::vector<glm::dvec2> square{{0.0, 0.0}, {2000.0, 0.0}, {2000.0, 2000.0}, {0.0, 2000.0}};
CHECK(geometry::polygon_area(square) == doctest::Approx(4.0e6));
std::reverse(square.begin(), square.end());
CHECK(geometry::polygon_area(square) == doctest::Approx(4.0e6));
// the L of 300 m, its arms 1000 m long
CHECK(geometry::polygon_area({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 300.0}, {300.0, 300.0}, {300.0, 1000.0}, {0.0, 1000.0}}) == doctest::Approx(510000.0));
CHECK(geometry::polygon_area({{0.0, 0.0}, {100.0, 100.0}}) == 0.0);
}
TEST_CASE("download area: edges crossing each other, as when the corners are clicked out of order") {
// the corners of a square clicked across: a bow tie
CHECK(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 1000.0}, {1000.0, 0.0}, {0.0, 1000.0}}));
CHECK_FALSE(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 1000.0}, {0.0, 1000.0}}));
// a concave polygon isn't a crossing one
CHECK_FALSE(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 300.0}, {300.0, 300.0}, {300.0, 1000.0}, {0.0, 1000.0}}));
// a triangle can't cross itself
CHECK_FALSE(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {0.0, 1000.0}}));
// the last edge, back to the first point, across the first one
CHECK(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 1000.0}, {500.0, -500.0}}));
}

115
tests/unit/test_fouling.cpp Normal file
View File

@@ -0,0 +1,115 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorFouling.hpp"
#include "editor/editorGauge.hpp"
#include <cmath>
#include <vector>
namespace {
// the axis from the origin along z, a point each metre; Radius 0 straight, else a curve towards +x (Radius > 0) or -x
std::vector<glm::dvec3> axis(double const Radius, double const Slope = 0.0, double const Length = 150.0) {
std::vector<glm::dvec3> points;
auto const metres{static_cast<int>(std::floor(Length + 1e-9))};
for (int metre = 0; metre <= metres; ++metre) {
auto const s{static_cast<double>(metre)};
if (Radius == 0.0) {
auto const along{s / std::sqrt(1.0 + Slope * Slope)};
points.emplace_back(along * Slope, 0.0, along);
}
else {
auto const r{std::abs(Radius)};
auto const side{Radius > 0.0 ? 1.0 : -1.0};
points.emplace_back(side * r * (1.0 - std::cos(s / r)), 0.0, r * std::sin(s / r));
}
}
return points;
}
} // namespace
TEST_CASE("the widening of the gauge from the radius is that of table 1 of the standard, none from 250 m up") {
CHECK(gauge::curve_widening(200.0, true) == doctest::Approx(50.0 / 200.0 - 0.185));
CHECK(gauge::curve_widening(200.0, false) == doctest::Approx(60.0 / 200.0 - 0.225));
CHECK(gauge::curve_widening(180.0, false) == doctest::Approx(60.0 / 180.0 - 0.225));
CHECK(gauge::curve_widening(250.0, true) == 0.0);
CHECK(gauge::curve_widening(300.0, false) == 0.0);
CHECK(gauge::curve_widening(0.0, false) == 0.0);
// the table ends at 150 m: the sharper curves get its value there
CHECK(gauge::curve_widening(40.0, true) == doctest::Approx(50.0 / 150.0 - 0.185));
CHECK(gauge::curve_widening(100.0, false) == doctest::Approx(60.0 / 150.0 - 0.225));
}
TEST_CASE("a straight branch at 1:9 off a straight track fouls it where the axes are 3.50 m apart") {
fouling::place place;
REQUIRE(fouling::find(axis(0.0), axis(0.0, 1.0 / 9.0), fouling::kNominal, place));
CHECK(place.spacing == doctest::Approx(3.5));
CHECK(place.main.z == doctest::Approx(31.5).epsilon(0.002));
CHECK(place.branch.x == doctest::Approx(3.5).epsilon(0.002));
}
TEST_CASE("a branch in a curve of 300 m fouls at 3.50 m, the gauge including the curve") {
fouling::place place;
REQUIRE(fouling::find(axis(0.0), axis(300.0), fouling::kNominal, place));
CHECK(place.spacing == doctest::Approx(3.5));
CHECK(place.main.z == doctest::Approx(std::sqrt(300.0 * 300.0 - 296.5 * 296.5)).epsilon(0.002));
}
TEST_CASE("a branch in a curve under 250 m fouls farther: the widening on the outer side of its curve is added") {
// the straight track lies on the outer side of the curve of the branch
fouling::place place;
REQUIRE(fouling::find(axis(0.0), axis(200.0), fouling::kNominal, place));
auto const wanted{3.5 + 60.0 / 200.0 - 0.225};
CHECK(place.spacing == doctest::Approx(wanted).epsilon(0.001));
CHECK(place.branch.x == doctest::Approx(wanted).epsilon(0.002));
CHECK(place.main.z == doctest::Approx(std::sqrt(200.0 * 200.0 - (200.0 - wanted) * (200.0 - wanted))).epsilon(0.002));
}
TEST_CASE("both tracks in curves under 250 m: the widenings of both are summed, each on the side of the other track") {
// the branch curves sharper, inside the curve of the main track: on the inner side of the main track, which lies on the outer
// side of the branch
fouling::place place;
REQUIRE(fouling::find(axis(200.0), axis(180.0), fouling::kNominal, place));
auto const wanted{3.5 + (50.0 / 200.0 - 0.185) + (60.0 / 180.0 - 0.225)};
CHECK(place.spacing == doctest::Approx(wanted).epsilon(0.001));
// the branch there that far from the axis of the main track, the circle about (200, 0)
auto const off{200.0 - std::hypot(place.branch.x - 200.0, place.branch.z)};
CHECK(off == doctest::Approx(wanted).epsilon(0.003));
}
TEST_CASE("the cars of a track on a cant lean towards the other track when its lower rail is on that side, at any radius") {
// the curves of axis() turn to the right of the way they run, towards +x: the cant of a curve lowers its right rail,
// negative as widening_at takes it; positive the other way round
std::vector<double> const cant(200, -0.1);
std::vector<double> const against(200, 0.1);
auto const lean{0.1 * fouling::kLeanHeight / 1.5};
CHECK(fouling::kLeanHeight == doctest::Approx(3.25));
CHECK(gauge::cant_widening(-0.1, fouling::kLeanHeight) == doctest::Approx(lean));
fouling::place place;
// the branch inside the curve of the main track, on its inner side: the main track on the cant leans towards it
REQUIRE(fouling::find(axis(200.0), axis(180.0), fouling::kNominal, place, cant, {}));
CHECK(place.spacing == doctest::Approx(3.5 + (50.0 / 200.0 - 0.185) + lean + (60.0 / 180.0 - 0.225)).epsilon(0.001));
CHECK(place.cant == doctest::Approx(lean).epsilon(0.001));
// the branch on the cant leans away from the main track, on the outer side of its curve: nothing for it
REQUIRE(fouling::find(axis(0.0), axis(200.0), fouling::kNominal, place, {}, cant));
CHECK(place.spacing == doctest::Approx(3.5 + 60.0 / 200.0 - 0.225).epsilon(0.001));
CHECK(place.cant == doctest::Approx(0.0));
// a branch on a cant against its curve leans towards the main track on the outer side of the curve: the lean counts
REQUIRE(fouling::find(axis(0.0), axis(200.0), fouling::kNominal, place, {}, against));
CHECK(place.spacing == doctest::Approx(3.5 + 60.0 / 200.0 - 0.225 + lean).epsilon(0.001));
CHECK(place.cant == doctest::Approx(lean).epsilon(0.001));
// from 250 m up no widening from the radius, but the cars lean on the cant all the same
REQUIRE(fouling::find(axis(300.0), axis(260.0), fouling::kNominal, place, cant, {}));
CHECK(place.spacing == doctest::Approx(3.5 + lean).epsilon(0.001));
// and on the straight: a straight track on a cant leaning towards a straight branch
std::vector<double> const left(200, 0.1);
REQUIRE(fouling::find(axis(0.0), axis(0.0, -1.0 / 9.0), fouling::kNominal, place, left, {}));
CHECK(place.spacing == doctest::Approx(3.5 + lean).epsilon(0.001));
}
TEST_CASE("a straight branch off a track curving away from it: the widening on the outer side of the curve of the main track") {
fouling::place place;
REQUIRE(fouling::find(axis(-200.0), axis(0.0, 1.0 / 9.0), fouling::kNominal, place));
CHECK(place.spacing == doctest::Approx(3.5 + 60.0 / 200.0 - 0.225).epsilon(0.001));
}

129
tests/unit/test_geotiff.cpp Normal file
View File

@@ -0,0 +1,129 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorGeoTiff.hpp"
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <vector>
namespace {
struct raster {
int width{0};
int height{0};
std::vector<float> heights;
double pixel{0.0};
double east{0.0};
double north{0.0};
};
float constexpr missing{-1001.f};
// a GeoTIFF like the one of the terrain model service: little-endian, one band of floats, Rows rows a strip, Strips of them
// listed, the pixel of 1 m, the north-west corner at 1000, 2000. The height of a pixel is its row * 10 + its column
std::vector<std::uint8_t> geotiff(int const Width, int const Height, std::uint32_t const Rows, std::uint32_t const Strips) {
std::vector<std::uint8_t> out;
auto const put16 = [&](std::uint32_t const Value) {
for (int i = 0; i < 2; ++i)
out.push_back(static_cast<std::uint8_t>(Value >> (8 * i)));
};
auto const put32 = [&](std::uint32_t const Value) {
for (int i = 0; i < 4; ++i)
out.push_back(static_cast<std::uint8_t>(Value >> (8 * i)));
};
auto const put64 = [&](double const Value) {
std::uint64_t bits;
std::memcpy(&bits, &Value, sizeof(bits));
for (int i = 0; i < 8; ++i)
out.push_back(static_cast<std::uint8_t>(bits >> (8 * i)));
};
std::uint32_t constexpr count{9};
std::uint32_t constexpr ifd{8};
std::uint32_t const offsets{ifd + 2 + count * 12 + 4};
std::uint32_t const scale{offsets + 4 * Strips};
std::uint32_t const tie{scale + 3 * 8};
std::uint32_t const pixels{tie + 6 * 8};
auto const rows{std::min<std::uint32_t>(Rows, Height)};
out.push_back('I');
out.push_back('I');
put16(42);
put32(ifd);
put16(count);
auto const entry = [&](std::uint32_t const Tag, std::uint32_t const Type, std::uint32_t const Count, std::uint32_t const Value) {
put16(Tag);
put16(Type);
put32(Count);
put32(Value);
};
entry(256, 4, 1, Width);
entry(257, 4, 1, Height);
entry(258, 3, 1, 32);
entry(259, 3, 1, 1);
entry(273, 4, Strips, Strips == 1 ? pixels : offsets);
entry(278, 4, 1, Rows);
entry(339, 3, 1, 3);
entry(33550, 12, 3, scale);
entry(33922, 12, 6, tie);
put32(0);
for (std::uint32_t strip = 0; strip < Strips; ++strip)
put32(pixels + strip * rows * Width * 4);
for (double const value : {1.0, 1.0, 0.0})
put64(value);
for (double const value : {0.0, 0.0, 0.0, 1000.0, 2000.0, 0.0})
put64(value);
for (int row = 0; row < Height; ++row)
for (int column = 0; column < Width; ++column) {
float const height{static_cast<float>(row * 10 + column)};
std::uint32_t bits;
std::memcpy(&bits, &height, sizeof(bits));
put32(bits);
}
return out;
}
} // namespace
TEST_CASE("terrain model: a GeoTIFF of the service read whole") {
auto const data{geotiff(5, 7, 2, 4)};
raster square;
REQUIRE(editor_geotiff::read(data, square, missing));
CHECK(square.width == 5);
CHECK(square.height == 7);
REQUIRE(square.heights.size() == 35);
CHECK(square.heights[0] == 0.f);
CHECK(square.heights[2 * 5 + 3] == 23.f);
CHECK(square.heights[6 * 5 + 4] == 64.f); // in the last strip, of one row
CHECK(square.pixel == 1.0);
CHECK(square.east == 1000.0);
CHECK(square.north == 2000.0);
}
TEST_CASE("terrain model: the rows all in one strip") {
raster square;
REQUIRE(editor_geotiff::read(geotiff(5, 7, 0xffffffffu, 1), square, missing));
CHECK(square.heights[6 * 5 + 4] == 64.f);
}
TEST_CASE("terrain model: a GeoTIFF cut short isn't read, its missing pixels would be heights of 0 m") {
auto data{geotiff(5, 7, 2, 4)};
raster square;
SUBCASE("by a byte") {
data.pop_back();
CHECK_FALSE(editor_geotiff::read(data, square, missing));
}
SUBCASE("by its last strip") {
data.resize(data.size() - 5 * 4);
CHECK_FALSE(editor_geotiff::read(data, square, missing));
}
SUBCASE("to the half of its pixels") {
data.resize(data.size() - 5 * 7 * 2);
CHECK_FALSE(editor_geotiff::read(data, square, missing));
}
CHECK(square.heights.empty());
}
TEST_CASE("terrain model: a GeoTIFF listing fewer strips than its rows need isn't read") {
raster square;
CHECK_FALSE(editor_geotiff::read(geotiff(5, 7, 2, 3), square, missing));
}

View File

@@ -0,0 +1,163 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorProfile.hpp"
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <limits>
#include <sstream>
#include <string>
namespace {
struct ground_of_line {
std::vector<double> chainages, heights, tolerances, reaches;
};
ground_of_line read_ground(std::string const &Name) {
ground_of_line result;
std::ifstream file{std::string{EU07_UNIT_TESTS_DATA} + "/" + Name};
for (std::string row; std::getline(file, row);) {
if (row.empty() || row.front() == '#')
continue;
std::istringstream values{row};
std::string chainage, height, tolerance, reach;
values >> chainage >> height >> tolerance >> reach;
result.chainages.push_back(std::strtod(chainage.c_str(), nullptr));
result.heights.push_back(std::strtod(height.c_str(), nullptr));
result.tolerances.push_back(std::strtod(tolerance.c_str(), nullptr));
result.reaches.push_back(std::strtod(reach.c_str(), nullptr));
}
return result;
}
// the real ground of a line, which the fit took under a field past a viaduct
ground_of_line past_viaduct() {
return read_ground("fit_past_viaduct.txt");
}
// a route of the editor as the selftest profiledump writes it: the tracks sampled, the ends joined, the switches, the norms
struct route_dump {
ground_of_line ground;
profile::context context;
profile::line settings;
};
route_dump read_route(std::string const &Name) {
route_dump result;
std::ifstream file{std::string{EU07_UNIT_TESTS_DATA} + "/" + Name};
for (std::string row; std::getline(file, row);) {
std::istringstream values{row};
std::string kind;
values >> kind;
auto &context{result.context};
if (kind == "S") {
double chainage{0.0}, height{0.0};
values >> chainage >> height;
result.ground.chainages.push_back(chainage);
result.ground.heights.push_back(height);
}
else if (kind == "C")
values >> context.length >> context.start_joined >> context.start_elevation >> context.start_grade >> context.end_joined >> context.end_elevation >> context.end_grade;
else if (kind == "Z") {
profile::context::zone zone;
values >> zone.from >> zone.to;
context.switches.push_back(zone);
}
else if (kind == "H") {
profile::context::zone zone;
values >> zone.from >> zone.to;
context.humps.push_back(zone);
}
else if (kind == "F") {
std::pair<double, double> fixed;
values >> fixed.first >> fixed.second;
context.fixed.push_back(fixed);
}
else if (kind == "L") {
auto &line{result.settings};
values >> line.speed >> line.norms.grade_max >> line.norms.grade_switch_max >> line.norms.radius_factor >> line.norms.radius_min >> line.norms.curve_threshold >> line.norms.element_min >> line.norms.fixed_tolerance >> line.join_start >> line.join_end;
}
}
return result;
}
// the tracks of a line moved by the grade lines shared: a design laid anew onto them, as profile_refit_stored lays it
profile::line refit(ground_of_line const &Ground, profile::context const &Context = {}, profile::line const &Settings = {}) {
auto context{Context};
if (context.length <= 0.0)
context.length = Ground.chainages.back();
std::vector<double> const tolerances(Ground.chainages.size(), 0.005);
std::vector<double> const reaches(Ground.chainages.size(), 100.0);
profile::ground_fit options;
options.tolerance = 0.01;
options.grade_max = 50.0;
options.humps = profile::humps(Ground.chainages, Ground.heights, context, options.tolerance);
options.hump_radius = 300.0;
return profile::fit_ground(Ground.chainages, Ground.heights, context, Settings, options, tolerances, reaches);
}
double worst_departure(profile::line const &Line, ground_of_line const &Ground) {
double worst{0.0};
for (std::size_t i = 0; i < Ground.chainages.size(); ++i)
worst = std::max(worst, std::abs(profile::elevation(Line, Ground.chainages[i]) - Ground.heights[i]));
return worst;
}
profile::line fit(ground_of_line const &Ground) {
profile::context context;
context.length = Ground.chainages.back();
profile::ground_fit options;
options.tolerance = 0.15;
options.grade_max = std::numeric_limits<double>::max();
options.follow_length = 60.0;
options.follow_height = 4.0;
options.follow_steepest = 100.0;
options.follow_tolerance = 0.05;
return profile::fit_ground(Ground.chainages, Ground.heights, context, profile::line{}, options, Ground.tolerances, Ground.reaches);
}
} // namespace
TEST_CASE("ground fit: a line held down on a viaduct comes back to the field before its loose end") {
auto const ground{past_viaduct()};
REQUIRE(ground.chainages.size() > 300);
auto const line{fit(ground)};
REQUIRE(line.points.size() >= 2);
auto const end{ground.chainages.back()};
// the field lies at 79.9 to 80.2: no going on under it at the grade the line took on the viaduct
CHECK(profile::elevation(line, end) > 79.5);
CHECK(profile::elevation(line, end - 100.0) > 79.5);
}
TEST_CASE("ground fit: the same off a loose start") {
auto ground{past_viaduct()};
REQUIRE(ground.chainages.size() > 300);
auto const end{ground.chainages.back()};
for (auto &chainage : ground.chainages)
chainage = end - chainage;
std::reverse(ground.chainages.begin(), ground.chainages.end());
std::reverse(ground.heights.begin(), ground.heights.end());
std::reverse(ground.tolerances.begin(), ground.tolerances.end());
std::reverse(ground.reaches.begin(), ground.reaches.end());
auto const line{fit(ground)};
REQUIRE(line.points.size() >= 2);
CHECK(profile::elevation(line, 0.0) > 79.5);
CHECK(profile::elevation(line, 100.0) > 79.5);
}
TEST_CASE("ground fit: a design laid anew onto tracks bending gently into a sag keeps to them") {
// the tracks go from -6.6 to +5.8 per mille over some 100 m, as a curve of about 8 km: curves of the 4 km the norms ask for
// follow it only two or more of them, a straight between
auto const route{read_route("refit_sag.txt")};
auto const &ground{route.ground};
REQUIRE(ground.chainages.size() > 300);
REQUIRE(false == route.context.switches.empty());
auto const line{refit(ground, route.context, route.settings)};
REQUIRE(line.points.size() >= 2);
CHECK(worst_departure(line, ground) < 0.015);
// with nothing told of the route as well
CHECK(worst_departure(refit(ground), ground) < 0.015);
}

View File

@@ -0,0 +1,42 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorGroundFollow.hpp"
#include <cmath>
#include <limits>
namespace {
segment_data straight(double const From, double const To) {
segment_data piece;
piece.points[segment_data::point::start] = {From, 0.0, 0.0};
piece.points[segment_data::point::end] = {To, 0.0, 0.0};
return piece;
}
} // namespace
TEST_CASE("heights: from point to point the tracks meet at one height where a point is clicked just past a joint") {
// three tracks of 40 m, the grade breaking 3 m past the first joint and 2 m short of the second one, steeply
std::vector<segment_data> pieces{straight(0.0, 40.0), straight(40.0, 80.0), straight(80.0, 120.0)};
auto const unknown{std::numeric_limits<double>::quiet_NaN()};
ground_follow::follow_points(pieces, {{43.0, -5.0, 0.0}, {78.0, 3.0, 0.0}}, {0.0, unknown, 0.0, unknown});
REQUIRE(pieces.size() >= 3);
for (std::size_t i = 0; i + 1 < pieces.size(); ++i)
CHECK(pieces[i].points[segment_data::point::end].y == doctest::Approx(pieces[i + 1].points[segment_data::point::start].y).epsilon(1e-9));
CHECK(pieces.front().points[segment_data::point::start].y == doctest::Approx(0.0));
CHECK(pieces.back().points[segment_data::point::end].y == doctest::Approx(0.0));
}
TEST_CASE("heights: with no point between the ends the grade is even from one end to the other") {
std::vector<segment_data> pieces{straight(0.0, 50.0), straight(50.0, 100.0)};
auto const unknown{std::numeric_limits<double>::quiet_NaN()};
ground_follow::follow_points(pieces, {}, {10.0, unknown, 12.0, unknown});
REQUIRE(pieces.size() == 2);
CHECK(pieces[0].points[segment_data::point::end].y == doctest::Approx(11.0));
CHECK(pieces[1].points[segment_data::point::start].y == doctest::Approx(11.0));
}

View File

@@ -0,0 +1,351 @@
#include "stdafx.h"
#include "doctest.h"
#include "drive.h"
// the order of the line breaker and the pantographs (eu07/maszyna#68): on Polish locomotives the pantographs
// come first and the line breaker closes on their voltage; on Czech ones (Cntrl.PantRequiresMain) the line
// breaker closes first, without voltage, and the pantographs rise and stay up only while it's closed. what the
// main circuit feeds still needs the voltage there: the converter and the rest don't run behind a line breaker
// closed on the battery alone, and the traction motors get cut off when the voltage goes
namespace {
constexpr test::track line{0.15, 0.0, test::catenary_3kv};
// a catenary without voltage, and one below the voltage the locomotive works on (Power: MinV, 1900 V)
constexpr test::track dead{0.15, 0.0, 0.0};
constexpr test::track weak{0.15, 0.0, 1000.0};
test::definition ep05(bool const Mainsfirst) {
auto definition{test::definition::fiz("ep05_v2/ep05")};
if (Mainsfirst) {
definition.set("Cntrl", "PantRequiresMain", "Yes");
}
return definition;
}
// battery and cab on, direction set and the relays reset, the pantographs on the main reservoir's air
void prepare(test::vehicle &Loco) {
Loco.hold_main_reservoir(6.0);
Loco->bPantKurek3 = true;
Loco->BatterySwitch(true);
Loco->CabActivisation();
for (int i = 0; i < 3 && Loco->DirActive <= 0; ++i) {
Loco->DirectionForward();
}
Loco.run(2.0, line);
Loco->RelayReset(relay_t::maincircuitground | relay_t::tractionnmotoroverload | relay_t::primaryconverteroverload);
Loco.run(2.0, line);
}
void raise_pantograph(test::vehicle &Loco, test::track const &Track = line) {
Loco->OperatePantographsValve(operation_t::enable);
Loco->OperatePantographValve(end::rear, operation_t::enable);
Loco.run(5.0, Track);
}
void close_line_breaker(test::vehicle &Loco) {
Loco->MainSwitch(true);
Loco.run(2.0, line);
}
// the converter and the compressor switched on, the main reservoir left to the compressor from now on
void switch_auxiliaries_on(test::vehicle &Loco) {
Loco->ConverterSwitch(true);
Loco->CompressorSwitch(true);
Loco.hold_main_reservoir(-1.0);
}
// what the main reservoir gains over the given time [bar]; the compressor of the locomotive adds some 0.07 bar a second
double reservoir_gain(test::vehicle &Loco, double const Seconds, test::track const &Track) {
auto const before{Loco->CompressedVolume};
Loco.run(Seconds, Track);
return (Loco->CompressedVolume - before) / Loco->VeselVolume;
}
// the locomotive started up the way the driver does it, the brakes released, then the master controller taken to the
// given position a notch a second, the camshaft following it
void get_under_power(test::vehicle &Loco, test::driven const &Driven, int const Position) {
REQUIRE(test::start_up(Driven, line));
test::release_brakes(Driven.cab);
test::drive(Driven, line, 20.0);
// until the pressure switch lets the line contactors close
for (int i = 0; i < 120 && Loco->ControlPressureSwitch; ++i) {
test::drive(Driven, line, 1.0);
}
for (int i = 0; i < Position; ++i) {
Loco->IncMainCtrl(1);
test::drive(Driven, line, 1.0);
}
test::drive(Driven, line, 2.0);
REQUIRE(Loco->MainCtrlPos == Position);
REQUIRE(Loco->MainCtrlActualPos == Position);
REQUIRE(Loco->RList[Position].R > 0.0); // a resistance position
REQUIRE(Loco->StLinFlag);
REQUIRE(std::abs(Loco->Im) > 10.0);
}
} // namespace
TEST_CASE("mains before pantographs: without the flag the line breaker needs the pantographs' voltage, as before") {
test::vehicle loco{ep05(false), 0.0, "test", 1};
REQUIRE_FALSE(loco->PantographsRequireMains);
prepare(loco);
close_line_breaker(loco);
CHECK_FALSE(loco->Mains);
raise_pantograph(loco);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
close_line_breaker(loco);
CHECK(loco->Mains);
// the pantographs stay up with the line breaker open, and the line breaker opens without voltage
loco->MainSwitch(false);
loco.run(2.0, line);
CHECK(loco->Pantographs[end::rear].is_active);
close_line_breaker(loco);
REQUIRE(loco->Mains);
loco->OperatePantographValve(end::rear, operation_t::disable);
loco.run(2.0, line);
CHECK_FALSE(loco->Mains);
}
TEST_CASE("mains before pantographs: with the flag the pantographs rise only through the closed line breaker") {
test::vehicle loco{ep05(true), 0.0, "test", 1};
REQUIRE(loco->PantographsRequireMains);
prepare(loco);
// the pantographs stay down while the line breaker is open
raise_pantograph(loco);
CHECK_FALSE(loco->Pantographs[end::rear].is_active);
CHECK(loco->PantographVoltage == 0.0);
// the line breaker closes without voltage, and the pantograph rises through it
close_line_breaker(loco);
CHECK(loco->Mains);
raise_pantograph(loco);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK(loco->Mains);
// opening the line breaker drops the pantograph, which stays down until the line breaker closes again
loco->MainSwitch(false);
loco.run(2.0, line);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->Pantographs[end::rear].is_active);
CHECK(loco->PantographVoltage == 0.0);
// a pantograph lowered under the closed line breaker leaves it closed
close_line_breaker(loco);
raise_pantograph(loco);
REQUIRE(loco->Pantographs[end::rear].is_active);
loco->OperatePantographValve(end::rear, operation_t::disable);
loco.run(5.0, line);
CHECK_FALSE(loco->Pantographs[end::rear].is_active);
CHECK(loco->Mains);
}
TEST_CASE("mains before pantographs: with the flag the line breaker still needs the battery") {
test::vehicle loco{ep05(true), 0.0, "test", 1};
loco.hold_main_reservoir(6.0);
loco.run(2.0, line);
close_line_breaker(loco);
CHECK_FALSE(loco->Mains);
}
TEST_CASE("mains before pantographs: with the flag the driver's start-up gets the locomotive ready") {
// test::start_up() takes the AI's steps of TController::PrepareEngine(), the line breaker first here
test::vehicle loco{ep05(true), 0.0, "test", 1};
auto driven{test::driving(loco)};
REQUIRE(test::start_up(driven, line));
CHECK(loco->Mains);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK(test::is_ready(driven));
}
// the closed line breaker used to tell there's traction voltage, the undervoltage trip opening it without one. closed
// ahead of the pantographs it tells nothing of the kind, so what the main circuit feeds checks the voltage itself
TEST_CASE("mains before pantographs: with the flag the converter and the compressor wait for the traction voltage") {
test::vehicle loco{ep05(true), 0.0, "test", 1};
prepare(loco);
close_line_breaker(loco);
REQUIRE(loco->Mains);
REQUIRE(loco->PantographVoltage == 0.0);
switch_auxiliaries_on(loco);
REQUIRE(loco->ConverterAllow);
REQUIRE(loco->CompressorAllow);
// the line breaker closed on the battery, the pantographs down: there's nothing to run them on
CHECK(reservoir_gain(loco, 20.0, line) < 0.01);
CHECK(loco->Mains);
CHECK_FALSE(loco->MainCircuitPowered());
CHECK_FALSE(loco->ConverterFlag);
CHECK_FALSE(loco->Power110vIsAvailable);
CHECK_FALSE(loco->CompressorFlag);
// the pantograph up: the converter starts, and the compressor on its 110 V
raise_pantograph(loco);
REQUIRE(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK(reservoir_gain(loco, 10.0, line) > 0.1);
CHECK(loco->MainCircuitPowered());
CHECK(loco->ConverterFlag);
CHECK(loco->Power110vIsAvailable);
CHECK(loco->CompressorFlag);
// the voltage gone they stop, behind the line breaker which stays closed
auto const *track{&line};
SUBCASE("the pantograph lowered again") {
loco->OperatePantographValve(end::rear, operation_t::disable);
loco.run(5.0, line);
REQUIRE_FALSE(loco->Pantographs[end::rear].is_active);
}
SUBCASE("no voltage in the catenary") {
track = &dead;
loco.run(5.0, dead);
REQUIRE(loco->Pantographs[end::rear].is_active);
}
SUBCASE("the voltage in the catenary below the one the locomotive works on") {
track = &weak;
loco.run(5.0, weak);
REQUIRE(loco->PantographVoltage == doctest::Approx(weak.voltage));
}
CHECK(reservoir_gain(loco, 10.0, *track) < 0.01);
CHECK(loco->Mains);
CHECK_FALSE(loco->MainCircuitPowered());
CHECK_FALSE(loco->ConverterFlag);
CHECK_FALSE(loco->Power110vIsAvailable);
CHECK_FALSE(loco->CompressorFlag);
}
TEST_CASE("mains before pantographs: with the flag whatever else the main circuit feeds waits for the traction voltage too") {
// a compressor on the main circuit rather than the converter's 110 V, the motor blowers, the blowers of the starting
// resistors, the heating
test::vehicle loco{ep05(true).set("Brake", "CompressorPower", "Main"), 0.0, "test", 1};
REQUIRE(loco->CompressorPower == 0);
REQUIRE(loco->HeatingPowerSource.SourceType == TPowerSource::Main);
prepare(loco);
close_line_breaker(loco);
REQUIRE(loco->Mains);
loco->CompressorSwitch(true);
loco->MotorBlowersSwitch(true, end::front);
loco->RVentForceOn = true;
loco->HeatingSwitch(true);
loco.hold_main_reservoir(-1.0);
CHECK(reservoir_gain(loco, 10.0, line) < 0.01);
CHECK_FALSE(loco->CompressorFlag);
CHECK_FALSE(loco->MotorBlowers[end::front].is_active);
CHECK(loco->RventRot == 0.0);
CHECK_FALSE(loco->Heating);
SUBCASE("nor do they run on a voltage below the one the locomotive works on") {
raise_pantograph(loco, weak);
REQUIRE(loco->PantographVoltage == doctest::Approx(weak.voltage));
CHECK(reservoir_gain(loco, 10.0, weak) < 0.01);
CHECK(loco->Mains);
CHECK_FALSE(loco->CompressorFlag);
CHECK_FALSE(loco->MotorBlowers[end::front].is_active);
CHECK(loco->RventRot == 0.0);
CHECK_FALSE(loco->Heating);
}
SUBCASE("with the voltage they do") {
raise_pantograph(loco);
REQUIRE(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK(reservoir_gain(loco, 10.0, line) > 0.1);
CHECK(loco->CompressorFlag);
CHECK(loco->MotorBlowers[end::front].is_active);
CHECK(loco->RventRot > 0.0);
CHECK(loco->Heating);
}
}
TEST_CASE("mains before pantographs: without the flag the converter and the compressor run behind the closed line breaker, as before") {
test::vehicle loco{ep05(false), 0.0, "test", 1};
prepare(loco);
raise_pantograph(loco);
close_line_breaker(loco);
REQUIRE(loco->Mains);
switch_auxiliaries_on(loco);
CHECK(reservoir_gain(loco, 10.0, line) > 0.1);
CHECK(loco->MainCircuitPowered());
CHECK(loco->ConverterFlag);
CHECK(loco->Power110vIsAvailable);
CHECK(loco->CompressorFlag);
// too low a voltage opens the line breaker, and they stop with it
loco.run(5.0, weak);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->MainCircuitPowered());
CHECK_FALSE(loco->ConverterFlag);
CHECK_FALSE(loco->Power110vIsAvailable);
CHECK_FALSE(loco->CompressorFlag);
}
// the undervoltage trip was also what cut the traction motors off when the voltage went: the line contactors open
// with the line breaker, which then doesn't close on a running position. where the line breaker holds without
// voltage, its undervoltage relay opens the line contactors itself, until the master controller is back where a
// start begins
TEST_CASE("mains before pantographs: with the flag the line contactors open when the traction voltage goes, and the start begins anew") {
test::vehicle loco{ep05(true), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
// the voltage goes: the line breaker holds, the pantograph stays up, the motors are cut off
test::drive(driven, dead, 3.0);
CHECK(loco->Mains);
CHECK(loco->Pantographs[end::rear].is_active);
CHECK_FALSE(loco->NoVoltRelay);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
// the voltage back, with the master controller still where it was: the camshaft went down to zero and stays
// there, the motors still cut off; the converter is back on its own
test::drive(driven, line, 10.0);
REQUIRE(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
REQUIRE(loco->MainCtrlPos == 5);
CHECK(loco->Mains);
CHECK(loco->ConverterFlag);
CHECK_FALSE(loco->NoVoltRelay);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->MainCtrlActualPos == 0);
CHECK(loco->Im == 0.0);
SUBCASE("the master controller back at zero: the start goes as usual") {
while (loco->MainCtrlPos > 0 && loco->DecMainCtrl(1)) {
// down to zero
}
REQUIRE(loco->MainCtrlPos == 0);
test::drive(driven, line, 1.0);
CHECK(loco->NoVoltRelay);
CHECK_FALSE(loco->StLinFlag);
for (int i = 0; i < 3; ++i) {
loco->IncMainCtrl(1);
test::drive(driven, line, 2.0);
}
CHECK(loco->StLinFlag);
CHECK(loco->MainCtrlActualPos == 3);
CHECK(std::abs(loco->Im) > 10.0);
}
SUBCASE("the master controller back at the first position, where the line contactors close on a start") {
while (loco->MainCtrlPos > 1 && loco->DecMainCtrl(1)) {
// down to the first position
}
REQUIRE(loco->MainCtrlPos == 1);
test::drive(driven, line, 2.0);
CHECK(loco->NoVoltRelay);
CHECK(loco->StLinFlag);
CHECK(loco->MainCtrlActualPos == 1);
}
}
TEST_CASE("mains before pantographs: without the flag the line breaker opens when the traction voltage goes, as before") {
test::vehicle loco{ep05(false), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
test::drive(driven, dead, 3.0);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
// and stays open with the voltage back
test::drive(driven, line, 10.0);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->MainCtrlActualPos == 0);
CHECK(loco->Im == 0.0);
}

View File

@@ -0,0 +1,246 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorSwitchCurve.hpp"
#include <algorithm>
#include <cmath>
#include <string>
namespace {
// a line every half metre: a straight, a transition curve from it to the arc of the radius, with a straight cant ramp along it, and
// the arc, each of the lengths given
std::vector<switch_curve::track_point> line(double const Straight, double const Transition, double const Arc, double const Radius, double const Cant) {
std::vector<switch_curve::track_point> points;
double heading{0.0};
auto const curvature = [&](double const S) { return S <= Straight ? 0.0 : S <= Straight + Transition ? (S - Straight) / Transition / Radius : 1.0 / Radius; };
auto const cant = [&](double const S) { return S <= Straight ? 0.0 : S <= Straight + Transition ? Cant * (S - Straight) / Transition : Cant; };
for (int k = 0; k * 0.5 <= Straight + Transition + Arc + 1e-9; ++k) {
auto const s{k * 0.5};
if (s > 0.0)
heading += 0.5 * (curvature(s - 0.5) + curvature(s)) * 0.5;
points.push_back({s, heading, cant(s)});
}
return points;
}
// the tracks of a switch Length long laid into the line from the station: the main one along it, the diverging one turning off it
// to the side by the curvature of the basic switch
std::pair<std::vector<switch_curve::track_point>, std::vector<switch_curve::track_point>> laid(std::vector<switch_curve::track_point> const &Line, double const From, double const Length, double const Radius, int const Side) {
std::vector<switch_curve::track_point> main;
std::vector<switch_curve::track_point> branch;
auto const first{std::lower_bound(Line.begin(), Line.end(), From, [](auto const &Point, double const Value) { return Point.station < Value; })};
for (auto point{first}; point != Line.end() && point->station <= From + Length + 1e-9; ++point) {
auto const s{point->station - From};
main.push_back({s, point->heading - first->heading, 0.0});
branch.push_back({s, point->heading - first->heading + Side * s / Radius, 0.0});
}
return {main, branch};
}
bool says(std::vector<std::string> const &Lines, char const *Text) {
return std::any_of(Lines.begin(), Lines.end(), [&](std::string const &Line) { return Line.find(Text) != std::string::npos; });
}
} // namespace
TEST_CASE("switch on a curve: the curvatures of its tracks on a transition curve, read the way the line turns") {
auto const track{line(100.0, 120.0, 200.0, 1000.0, 60.0)};
auto const [main, branch] {laid(track, 150.0, 30.0, 500.0, -1)};
auto const report{switch_curve::check(main, branch, track, 150.0, 180.0, 500.0, 12.0)};
CHECK(report.curved);
CHECK(report.transition);
CHECK(report.main_start == doctest::Approx(51.0 / 120.0 / 1000.0).epsilon(0.02));
CHECK(report.main_end == doctest::Approx(79.0 / 120.0 / 1000.0).epsilon(0.02));
// turning off to the outside of the curve: against it all along, the case KZW I
CHECK(report.branch_start < 0.0);
CHECK(report.branch_end < 0.0);
CHECK(false == says(report.warnings, "KZW II"));
// laid on the ramp, the cant changing under it
CHECK(report.cant_start == doctest::Approx(25.0).epsilon(0.02));
CHECK(report.cant_end == doctest::Approx(40.0).epsilon(0.02));
CHECK(says(report.warnings, "The cant changes within the switch"));
}
TEST_CASE("switch on a curve: the diverging track turning from one side to the other is the case KZW II") {
// a transition growing past the curvature of the basic switch along the switch
auto const track{line(100.0, 60.0, 100.0, 300.0, 0.0)};
auto const [main, branch] {laid(track, 125.0, 30.0, 500.0, -1)};
auto const report{switch_curve::check(main, branch, track, 125.0, 155.0, 500.0, 12.0)};
CHECK(report.branch_start < 0.0);
CHECK(report.branch_end > 0.0);
CHECK(says(report.warnings, "KZW II"));
}
TEST_CASE("switch on a curve: the ends of a cant ramp at the ends of the switch or 6 m off it") {
auto const track{line(100.0, 120.0, 200.0, 1000.0, 60.0)};
auto const ramps{switch_curve::ramp_ends(track)};
REQUIRE(ramps.size() == 2);
CHECK(ramps[0] == doctest::Approx(100.0).epsilon(0.01));
CHECK(ramps[1] == doctest::Approx(220.0).epsilon(0.01));
auto const at = [&](double const From) {
auto const [main, branch] {laid(track, From, 30.0, 500.0, 1)};
return switch_curve::check(main, branch, track, From, From + 30.0, 500.0, 12.0);
};
CHECK(says(at(210.0).warnings, "within the switch"));
CHECK(says(at(222.0).warnings, "6 m at least"));
CHECK(false == says(at(220.0).warnings, "within the switch"));
CHECK(says(at(220.0).notes, "at an end of the switch"));
CHECK(false == says(at(230.0).warnings, "cant ramp"));
// the start pressed near those places drawn to them
std::string what;
CHECK(switch_curve::snapped_start(ramps, 218.5, 30.0, 1, 3.0, &what) == doctest::Approx(220.0));
CHECK(what.find("starts at an end") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 228.0, 30.0, 1, 3.0, &what) == doctest::Approx(226.0));
CHECK(what.find("6 m off") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 72.0, 30.0, 1, 3.0, &what) == doctest::Approx(70.0));
CHECK(what.find("ends at an end") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 160.0, 30.0, 1, 3.0, &what) == doctest::Approx(160.0));
CHECK(what.empty());
}
TEST_CASE("switch on a curve: one with a straight frog bent up to the frog, both tracks straight over it") {
auto const track{line(0.0, 1.0, 400.0, 1500.0, 0.0)};
for (auto const side : {1, -1}) {
CAPTURE(side);
auto [main, branch] {laid(track, 150.0, 27.0, 190.0, side)};
// the last 6 m of both straight, the diverging one with no curve of its own there either: the frog of the switch
auto const frog{21.0};
auto const straighten = [&](std::vector<switch_curve::track_point> &Track) {
auto const at{std::find_if(Track.begin(), Track.end(), [&](auto const &Point) { return Point.station >= frog; })};
for (auto point{at}; point != Track.end(); ++point)
point->heading = at->heading;
};
straighten(main);
straighten(branch);
auto const report{switch_curve::check(main, branch, track, 150.0, 177.0, 190.0, 9.0, 27.0 - frog)};
CHECK(report.curved);
// the curvature of the bent part only: no transition curve under it, the diverging track turning one way all along
CHECK_FALSE(report.transition);
CHECK(false == says(report.warnings, "KZW II"));
CHECK(says(report.warnings, "Bent up to the frog"));
}
}
TEST_CASE("switch on a curve: none of 1:9.403 nor steeper than 1:9 bent in the running and the main tracks, 1:9 itself is") {
auto const track{line(0.0, 1.0, 400.0, 1500.0, 0.0)};
auto const [main, branch] {laid(track, 150.0, 33.0, 300.0, 1)};
auto const banned = [&](double const Ratio) {
CAPTURE(Ratio);
auto const report{switch_curve::check(main, branch, track, 150.0, 183.0, 300.0, Ratio)};
REQUIRE(report.curved);
return says(report.warnings, "(11.4 pkt 4)");
};
// 1:9 of the catalogue and as read off the angle of the tracks
CHECK_FALSE(banned(9.0));
CHECK_FALSE(banned(8.998));
CHECK_FALSE(banned(9.002));
CHECK(banned(9.403));
CHECK(banned(9.41));
CHECK_FALSE(banned(9.51));
CHECK_FALSE(banned(10.0));
CHECK_FALSE(banned(12.0));
CHECK(banned(7.5));
CHECK(banned(6.6));
CHECK(banned(4.8));
}
namespace {
// a track of one curvature from its start, heading as given there, a point every half metre
std::vector<switch_curve::track_point> arc(double const Length, double const Heading, double const Curvature) {
std::vector<switch_curve::track_point> points;
for (int k = 0; k * 0.5 <= Length + 1e-9; ++k)
points.push_back({k * 0.5, Heading + Curvature * (k * 0.5), 0.0});
return points;
}
// a slip of 1:9 with the slip curves of R 190 m bent onto the line from the station on: the tracks through it with the curvature of the
// line, the slip curves with theirs plus the one of the line, one turning as the line does, the other against it
switch_curve::slip_report bent_slip(std::vector<switch_curve::track_point> const &Line, double const From, double const Curvature) {
auto const angle{std::atan(1.0 / 9.0)};
auto const half{16.6};
auto const tracks{std::vector{arc(2.0 * half, 0.0, Curvature), arc(2.0 * half, angle, Curvature * std::cos(angle))}};
auto const curves{std::vector{arc(190.0 * angle, 0.0, 1.0 / 190.0 + Curvature), arc(190.0 * angle, angle, -1.0 / 190.0 + Curvature)}};
return switch_curve::check_slip(tracks, curves, Line, From, From + 2.0 * half);
}
} // namespace
TEST_CASE("slip bent into a curve: in a side track only, its slip curve bent the way of the curve no sharper than a side track takes") {
auto const sharp{bent_slip(line(0.0, 0.0, 400.0, 800.0, 0.0), 150.0, 1.0 / 800.0)};
CHECK(sharp.curved);
CHECK(says(sharp.warnings, "11.4 pkt 4b"));
CHECK(sharp.first == doctest::Approx(1.0 / 800.0).epsilon(0.02));
CHECK(sharp.second == doctest::Approx(std::cos(std::atan(1.0 / 9.0)) / 800.0).epsilon(0.02));
REQUIRE(sharp.curves.size() == 2);
// 1/190 + 1/800: R 153.5 m, 1/190 - 1/800: R 249.2 m
CHECK(1.0 / sharp.curves[0] == doctest::Approx(153.5).epsilon(0.01));
CHECK(1.0 / sharp.curves[1] == doctest::Approx(249.2).epsilon(0.01));
CHECK(says(sharp.warnings, "R 154 m, below the least 180 m"));
CHECK(false == says(sharp.warnings, "R 249 m"));
CHECK(false == says(sharp.warnings, "9.7 pkt 12"));
// R 4000 m: the slip curve of 1/190 + 1/4000, R 181.4 m, still within the side tracks
auto const gentle{bent_slip(line(0.0, 0.0, 400.0, 4000.0, 0.0), 150.0, 1.0 / 4000.0)};
CHECK(gentle.curved);
CHECK(says(gentle.warnings, "11.4 pkt 4b"));
CHECK(false == says(gentle.warnings, "table 9.2"));
CHECK(gentle.notes.empty());
// one on a straight is no bent one
auto const straight{bent_slip(line(400.0, 0.0, 0.0, 1000.0, 0.0), 150.0, 0.0)};
CHECK_FALSE(straight.curved);
CHECK(straight.warnings.empty());
}
TEST_CASE("slip bent into a curve: the cant of the side track, a track through it turning from one side to the other") {
// the cant the same over it, none recommended in a side track though
auto const canted{bent_slip(line(0.0, 0.0, 400.0, 1000.0, 30.0), 150.0, 1.0 / 1000.0)};
CHECK(canted.cant_start == doctest::Approx(30.0));
CHECK(canted.cant_end == doctest::Approx(30.0));
CHECK(false == says(canted.warnings, "The cant changes"));
CHECK(says(canted.notes, "9.3 pkt 5"));
// a reverse curve under it
auto const curve{line(0.0, 0.0, 400.0, 1000.0, 0.0)};
auto first{arc(33.2, 0.0, 1.0 / 1000.0)};
for (auto &point : first)
if (point.station > 16.6)
point.heading = 16.6 / 1000.0 - (point.station - 16.6) / 1000.0;
auto const angle{std::atan(1.0 / 9.0)};
auto const report{switch_curve::check_slip({first, arc(33.2, angle, 1.0 / 1000.0)}, {arc(21.0, 0.0, 1.0 / 190.0)}, curve, 150.0, 183.2)};
CHECK(says(report.warnings, "9.7 pkt 12"));
}
TEST_CASE("switch exit: a curve right behind a straight frog, its sudden changes of the cant deficiency apart or together") {
double const sw{1.0 / 190.0};
// R 190 on behind a frog straight for 6.09 m, at 40 km/h: apart, 99 mm at the end, within the 130 mm of table 9.15
auto const same{switch_curve::check_exit(sw, 6.092, {{40.0, sw, sw}}, 40.0)};
CHECK(same.apart == doctest::Approx(6.092));
CHECK(same.element == doctest::Approx(6.0));
CHECK(same.change == doctest::Approx(99.4).epsilon(0.01));
CHECK(same.warnings.empty());
// the other way behind a frog straight of 1.66 m only: together, 199 mm, over the 130 mm
auto const reverse{switch_curve::check_exit(sw, 1.662, {{40.0, -sw, -sw}}, 40.0)};
CHECK(reverse.apart == doctest::Approx(1.662));
CHECK(reverse.change == doctest::Approx(198.8).epsilon(0.01));
REQUIRE(reverse.warnings.size() == 1);
CHECK(says(reverse.warnings, "tables 9.15, 9.16"));
// the same way behind it: together the curvature hardly changes
CHECK(switch_curve::check_exit(sw, 1.662, {{40.0, sw, sw}}, 40.0).warnings.empty());
// a straight of 5 m laid on first: 6.66 m apart, the curve the other way alone, 99 mm
auto const later{switch_curve::check_exit(sw, 1.662, {{5.0, 0.0, 0.0}, {40.0, -sw, -sw}}, 40.0)};
CHECK(later.apart == doctest::Approx(6.662));
CHECK(later.warnings.empty());
// a sharp curve of R 100 alone: 189 mm
CHECK(says(switch_curve::check_exit(sw, 6.092, {{30.0, 0.01, 0.01}}, 40.0).warnings, "table 9.15"));
// a transition out of the frog straight: no sudden change behind it
CHECK(switch_curve::check_exit(sw, 1.662, {{20.0, 0.0, -sw}, {20.0, -sw, -sw}}, 40.0).warnings.empty());
// the curve of a switch with a curved frog going on: nothing of the switch to judge
auto const on{switch_curve::check_exit(1.0 / 300.0, 0.0, {{30.0, 1.0 / 300.0, 1.0 / 300.0}}, 50.0)};
CHECK(on.apart < 0.0);
CHECK(on.warnings.empty());
}

View File

@@ -24,3 +24,11 @@ TEST_CASE("win1250: what win1250_to_utf8 gives is valid utf-8") {
CHECK(decoded.size() == kWin1250.size());
CHECK(decoded[12] == U'\x0142');
}
TEST_CASE("win1250: utf-8 written back the way a scenery file has it") {
CHECK(utf8_to_win1250("Bia\xC5\x82" "a Podlaska") == "Bia\xB3" "a Podlaska");
CHECK(utf8_to_win1250(kUtf8) == kWin1250);
CHECK(win1250_to_utf8(utf8_to_win1250(kUtf8)) == kUtf8);
// the letters other than the polish ones turn into question marks
CHECK(utf8_to_win1250("\xC3\xA9t\xC3\xA9") == "?t?");
}