mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Add WinUI/UWP Rect for double precision
This commit is contained in:
parent
9280743c8a
commit
498a60a2ec
|
|
@ -3,9 +3,7 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
#if WINUI || UWP
|
||||
using Windows.Foundation;
|
||||
#else
|
||||
#if !WINUI && !UWP
|
||||
using System.Windows;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#if WINUI || UWP
|
||||
using Windows.Foundation;
|
||||
#else
|
||||
#if !WINUI && !UWP
|
||||
using System.Windows;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,11 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if WINUI
|
||||
using Windows.Foundation;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
#elif UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
#if WINUI || UWP
|
||||
using Windows.Foundation;
|
||||
#else
|
||||
#if !WINUI && !UWP
|
||||
using System.Windows;
|
||||
#endif
|
||||
|
||||
|
|
@ -50,30 +48,30 @@ namespace MapControl
|
|||
return true;
|
||||
}
|
||||
|
||||
var topLeft = new Point(rect.Left, rect.Top);
|
||||
var topRight = new Point(rect.Right, rect.Top);
|
||||
var bottomLeft = new Point(rect.Left, rect.Bottom);
|
||||
var bottomRight = new Point(rect.Right, rect.Bottom);
|
||||
var topLeft = new Point(rect.X, rect.Y);
|
||||
var topRight = new Point(rect.X + rect.Width, rect.Y);
|
||||
var bottomLeft = new Point(rect.X, rect.Y + rect.Height);
|
||||
var bottomRight = new Point(rect.X + rect.Width, rect.Y + rect.Height);
|
||||
var numIntersections = 0;
|
||||
|
||||
if (GetIntersection(ref p1, ref p2, topLeft, bottomLeft, p => p.X <= rect.Left)) // left edge
|
||||
if (GetIntersection(ref p1, ref p2, topLeft, bottomLeft, p => p.X <= rect.X)) // left edge
|
||||
{
|
||||
numIntersections++;
|
||||
}
|
||||
|
||||
if (GetIntersection(ref p1, ref p2, topLeft, topRight, p => p.Y <= rect.Top)) // top edge
|
||||
if (GetIntersection(ref p1, ref p2, topLeft, topRight, p => p.Y <= rect.Y)) // top edge
|
||||
{
|
||||
numIntersections++;
|
||||
}
|
||||
|
||||
if (numIntersections < 2 &&
|
||||
GetIntersection(ref p1, ref p2, topRight, bottomRight, p => p.X >= rect.Right)) // right edge
|
||||
GetIntersection(ref p1, ref p2, topRight, bottomRight, p => p.X >= rect.X + rect.Width)) // right edge
|
||||
{
|
||||
numIntersections++;
|
||||
}
|
||||
|
||||
if (numIntersections < 2 &&
|
||||
GetIntersection(ref p1, ref p2, bottomLeft, bottomRight, p => p.Y >= rect.Bottom)) // bottom edge
|
||||
GetIntersection(ref p1, ref p2, bottomLeft, bottomRight, p => p.Y >= rect.Y + rect.Height)) // bottom edge
|
||||
{
|
||||
numIntersections++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,10 @@
|
|||
|
||||
using System;
|
||||
#if WINUI
|
||||
using Windows.Foundation;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
#elif UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@ using System.Linq;
|
|||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Windows.Foundation;
|
||||
#elif UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -7,14 +7,12 @@ using System.Diagnostics;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if WINUI
|
||||
using Windows.Foundation;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
||||
#elif UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
|
|
|||
|
|
@ -52,10 +52,7 @@ namespace MapControl
|
|||
/// Gets a Transform for scaling and rotating geometries
|
||||
/// in map coordinates (meters) to view coordinates (pixels).
|
||||
/// </summary>
|
||||
public Transform MapTransform
|
||||
{
|
||||
get => mapTransform ?? (mapTransform = new MatrixTransform());
|
||||
}
|
||||
public Transform MapTransform => mapTransform ?? (mapTransform = new MatrixTransform());
|
||||
|
||||
private MatrixTransform mapTransform;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#if WINUI || UWP
|
||||
using Windows.Foundation;
|
||||
#else
|
||||
#if !WINUI && !UWP
|
||||
using System.Windows;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
using System;
|
||||
#if WINUI
|
||||
using Windows.Foundation;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Windows.Foundation;
|
||||
#elif UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
|
|
|
|||
|
|
@ -9,11 +9,9 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
#if WINUI
|
||||
using Windows.Foundation;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -242,6 +242,9 @@
|
|||
<Compile Include="..\WinUI\PushpinBorder.WinUI.cs">
|
||||
<Link>PushpinBorder.WinUI.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WinUI\Rect.WinUI.cs">
|
||||
<Link>Rect.WinUI.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WinUI\Tile.WinUI.cs">
|
||||
<Link>Tile.WinUI.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Replaces Windows.Foundation.Point to achieve necessary floating point precision.
|
||||
/// Replaces Windows.Foundation.Point for double floating point precision.
|
||||
/// </summary>
|
||||
public struct Point
|
||||
{
|
||||
|
|
@ -63,9 +63,9 @@ namespace MapControl
|
|||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
public override bool Equals(object o)
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return o is Point && this == (Point)o;
|
||||
return obj is Point p && this == p;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
|
|
|||
80
MapControl/WinUI/Rect.WinUI.cs
Normal file
80
MapControl/WinUI/Rect.WinUI.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -70,9 +70,9 @@ namespace MapControl
|
|||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public override bool Equals(object o)
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return o is Vector && this == (Vector)o;
|
||||
return obj is Vector v && this == v;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
|
|
|||
Loading…
Reference in a new issue