-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGeoPoint.cs
More file actions
41 lines (36 loc) · 1.51 KB
/
GeoPoint.cs
File metadata and controls
41 lines (36 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace SL3Reader;
public readonly struct GeoPoint(double longitude, double latitude, double heading, double altitude, double distance)
{
public readonly double Longitude { get; } = longitude;
public readonly double Latitude { get; } = latitude;
public readonly double Altitude { get; } = altitude;
public readonly double Heading { get; } = heading;
public readonly double Distance { get; } = distance;
public readonly double X => double.DegreesToRadians(Longitude) * 6356752.3142d;
public readonly double Y => double.Asinh(double.Tan(double.DegreesToRadians(Latitude))) * 6356752.3142d;
public override readonly string ToString()
{
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
return X.ToString("0.###", invariantCulture) + ',' +
Y.ToString("0.###", invariantCulture);
}
[SkipLocalsInit]
public readonly ReadOnlySpan<byte> Format(Span<byte> buffer, bool addNewLine = true)
{
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
ReadOnlySpan<char> format = "0.###";
X.TryFormat(buffer, out int pos, format, invariantCulture);
buffer[pos++] = 44; // ','u8;
Y.TryFormat(buffer[pos..], out int charWritten, format, invariantCulture);
pos += charWritten;
if (addNewLine)
{
"\r\n"u8.CopyTo(buffer[pos..]);
pos += 2;
}
return buffer[..pos];
}
}