Beispiel #1
0
        private float ProcessLineString(List <Segment> segments, JsonElement.ArrayEnumerator coordinates, bool oneway)
        {
            float   maxCoordinate = 0;
            Vector3?lastOrNull    = null;

            foreach (var coordinate in coordinates)
            {
                Trace.Assert(coordinate.GetArrayLength() == 2);
                var(lon, lat) = (coordinate[0].GetDouble(), coordinate[1].GetDouble());  // beware the order!!
                // also see https://macwright.org/lonlat/
                var vec = _coordinateSpace.To(lat, lon);

                maxCoordinate = Math.Max(maxCoordinate, Math.Max(Math.Abs(vec.X), Math.Abs(vec.Y)));

                if (lastOrNull is Vector3 last)
                {
                    var segmentId = 1 + segments.Count;
                    var seg       = new Segment(segmentId, SegmentType.Rail, last, vec, oneway: oneway);
                    segments.Add(seg);
                }

                lastOrNull = vec;
            }

            return(maxCoordinate);
        }
Beispiel #2
0
        public void TestSimulationCoordinateSpaceFromLatLon()
        {
            var space  = new SimulationCoordinateSpace(50.083239, 14.435278);
            var vector = space.To(50.1, 14.5);

            Assert.Equal(4617.97265625, vector.X, 5);
            Assert.Equal(1863.73815918, vector.Y, 5);
        }