Bounds serialization

This commit is contained in:
glax 2023-04-24 20:48:23 +02:00
parent af821a761f
commit 6d59253a0b

View File

@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text.Json.Serialization;
using OSMDatastructure;
using OSMDatastructure.Graph;
using Pathfinding;
@ -19,8 +20,9 @@ public static class Renderer
public class Bounds
{
public readonly float minLat, maxLat, minLon, maxLon;
[JsonInclude]public float minLat, maxLat, minLon, maxLon;
[JsonConstructor]
public Bounds(float minLat, float minLon, float maxLat, float maxLon)
{
this.minLon = minLon;
@ -28,6 +30,21 @@ public static class Renderer
this.maxLon = maxLon;
this.minLat = minLat;
}
public static Bounds FromRandomCoords(float lat1, float lon1, float lat2, float lon2)
{
float minLat = lat1 < lat2 ? lat1 : lat2;
float minLon = lon1 < lon2 ? lon1 : lon2;
float maxLat = lat1 > lat2 ? lat1 : lat2;
float maxLon = lon1 > lon2 ? lon1 : lon2;
return new Bounds(minLat, minLon, maxLat, maxLon);
}
public static Bounds FromRandomCoords(Coordinates c1, Coordinates c2)
{
return FromRandomCoords(c1.latitude, c1.longitude, c2.latitude, c2.longitude);
}
}
[SuppressMessage("Interoperability", "CA1416:Plattformkompatibilität überprüfen")]