Reworked MapProjection

Return nullable Point from LocationToMap. Use MapRect instead of WinUI/UWP Rect replacement. Drop Vector. Add Scale struct.
This commit is contained in:
ClemensFischer 2022-12-02 16:50:10 +01:00
parent bab1788334
commit 218a85316c
28 changed files with 249 additions and 324 deletions

View file

@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Windows.Foundation;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
@ -50,7 +51,10 @@ namespace MapControl
{
if (locations.Count() >= 2)
{
var points = locations.Select(location => LocationToView(location, longitudeOffset));
var points = locations
.Select(location => LocationToView(location, longitudeOffset))
.Where(point => point.HasValue)
.Select(point => point.Value);
if (closed)
{

View file

@ -28,31 +28,6 @@ namespace MapControl
return new Point(p.X, p.Y);
}
public static explicit operator Point(Vector v)
{
return new Point(v.X, v.Y);
}
public static Point operator -(Point p)
{
return new Point(-p.X, -p.Y);
}
public static Point operator +(Point p, Vector v)
{
return new Point(p.X + v.X, p.Y + v.Y);
}
public static Point operator -(Point p, Vector v)
{
return new Point(p.X - v.X, p.Y - v.Y);
}
public static Vector operator -(Point p1, Point p2)
{
return new Vector(p1.X - p2.X, p1.Y - p2.Y);
}
public static bool operator ==(Point p1, Point p2)
{
return p1.X == p2.X && p1.Y == p2.Y;

View file

@ -1,80 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
namespace MapControl
{
/// <summary>
/// Replaces Windows.Foundation.Rect for double floating point precision.
/// </summary>
public struct Rect
{
public Rect(double x, double y, double width, double height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public Rect(Point p, Windows.Foundation.Size s)
{
X = p.X;
Y = p.Y;
Width = s.Width;
Height = s.Height;
}
public Rect(Point p1, Point p2)
{
X = Math.Min(p1.X, p2.X);
Y = Math.Min(p1.Y, p2.Y);
Width = Math.Max(p1.X, p2.X) - X;
Height = Math.Max(p1.Y, p2.Y) - Y;
}
public double X { get; set; }
public double Y { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public bool Contains(Point p)
{
return p.X >= X && p.X <= X + Width
&& p.Y >= Y && p.Y <= Y + Height;
}
public static implicit operator Windows.Foundation.Rect(Rect r)
{
return new Windows.Foundation.Rect(r.X, r.Y, r.Width, r.Height);
}
public static implicit operator Rect(Windows.Foundation.Rect r)
{
return new Rect(r.X, r.Y, r.Width, r.Height);
}
public static bool operator ==(Rect r1, Rect r2)
{
return r1.X == r2.X && r1.Y == r2.Y
&& r1.Width == r2.Width && r1.Height == r2.Height;
}
public static bool operator !=(Rect r1, Rect r2)
{
return !(r1 == r2);
}
public override bool Equals(object obj)
{
return obj is Rect r && this == r;
}
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode() ^ Width.GetHashCode() ^ Height.GetHashCode();
}
}
}

View file

@ -1,83 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
namespace MapControl
{
public struct Vector
{
public Vector(double x, double y)
{
X = x;
Y = y;
}
public double X { get; set; }
public double Y { get; set; }
public static implicit operator Windows.Foundation.Point(Vector v)
{
return new Windows.Foundation.Point(v.X, v.Y);
}
public static implicit operator Vector(Windows.Foundation.Point v)
{
return new Vector(v.X, v.Y);
}
public static explicit operator Vector(Point p)
{
return new Vector(p.X, p.Y);
}
public static Vector operator -(Vector v)
{
return new Vector(-v.X, -v.Y);
}
public static Point operator +(Vector v, Point p)
{
return new Point(v.X + p.X, v.Y + p.Y);
}
public static Vector operator +(Vector v1, Vector v2)
{
return new Vector(v1.X + v2.X, v1.Y + v2.Y);
}
public static Vector operator -(Vector v1, Vector v2)
{
return new Vector(v1.X - v2.X, v1.Y - v2.Y);
}
public static Vector operator *(double f, Vector v)
{
return new Vector(f * v.X, f * v.Y);
}
public static Vector operator *(Vector v, double f)
{
return new Vector(f * v.X, f * v.Y);
}
public static bool operator ==(Vector v1, Vector v2)
{
return v1.X == v2.X && v1.Y == v2.Y;
}
public static bool operator !=(Vector v1, Vector v2)
{
return !(v1 == v2);
}
public override bool Equals(object obj)
{
return obj is Vector v && this == v;
}
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
}
}
}