2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2021-01-13 21:19:27 +01:00
|
|
|
|
// © 2021 Clemens Fischer
|
2017-06-25 23:05:48 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A geographic bounding box with south and north latitude and west and east longitude values in degrees.
|
|
|
|
|
|
/// </summary>
|
2021-11-17 23:17:11 +01:00
|
|
|
|
#if !UWP
|
2018-08-08 23:31:52 +02:00
|
|
|
|
[System.ComponentModel.TypeConverter(typeof(BoundingBoxConverter))]
|
|
|
|
|
|
#endif
|
|
|
|
|
|
public class BoundingBox
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
|
|
|
|
|
private double south;
|
|
|
|
|
|
private double north;
|
|
|
|
|
|
|
|
|
|
|
|
public BoundingBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BoundingBox(double south, double west, double north, double east)
|
|
|
|
|
|
{
|
|
|
|
|
|
South = south;
|
|
|
|
|
|
West = west;
|
|
|
|
|
|
North = north;
|
|
|
|
|
|
East = east;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-02 17:13:55 +01:00
|
|
|
|
public double West { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public double East { get; set; }
|
|
|
|
|
|
|
2017-06-25 23:05:48 +02:00
|
|
|
|
public double South
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return south; }
|
|
|
|
|
|
set { south = Math.Min(Math.Max(value, -90d), 90d); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public double North
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return north; }
|
|
|
|
|
|
set { north = Math.Min(Math.Max(value, -90d), 90d); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual double Width
|
|
|
|
|
|
{
|
2018-12-02 17:13:55 +01:00
|
|
|
|
get { return East - West; }
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual double Height
|
|
|
|
|
|
{
|
2018-12-02 17:13:55 +01:00
|
|
|
|
get { return North - South; }
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual BoundingBox Clone()
|
|
|
|
|
|
{
|
2018-12-02 17:13:55 +01:00
|
|
|
|
return new BoundingBox(South, West, North, East);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static BoundingBox Parse(string s)
|
|
|
|
|
|
{
|
|
|
|
|
|
var values = s.Split(new char[] { ',' });
|
|
|
|
|
|
|
|
|
|
|
|
if (values.Length != 4)
|
|
|
|
|
|
{
|
2021-12-05 17:16:14 +01:00
|
|
|
|
throw new FormatException("BoundingBox string must be a comma-separated list of four floating point numbers.");
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new BoundingBox(
|
|
|
|
|
|
double.Parse(values[0], NumberStyles.Float, CultureInfo.InvariantCulture),
|
|
|
|
|
|
double.Parse(values[1], NumberStyles.Float, CultureInfo.InvariantCulture),
|
|
|
|
|
|
double.Parse(values[2], NumberStyles.Float, CultureInfo.InvariantCulture),
|
|
|
|
|
|
double.Parse(values[3], NumberStyles.Float, CultureInfo.InvariantCulture));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|