-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathRangeSelector.Helpers.UVCoord.cs
More file actions
130 lines (114 loc) · 3.51 KB
/
RangeSelector.Helpers.UVCoord.cs
File metadata and controls
130 lines (114 loc) · 3.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace CommunityToolkit.WinUI.Controls;
/// <summary>
/// A struct representing a coordinate in UV adjusted space.
/// </summary>
[DebuggerDisplay("({U}u,{V}v)")]
public struct UVCoord
{
/// <summary>
/// Initializes a new instance of the <see cref="UVCoord"/> struct.
/// </summary>
public UVCoord(Orientation orientation)
{
Orientation = orientation;
}
/// <summary>
/// Initializes a new instance of the <see cref="UVCoord"/> struct.
/// </summary>
public UVCoord(double x, double y, Orientation orientation)
{
X = x;
Y = y;
Orientation = orientation;
}
/// <summary>
/// Initializes a new instance of the <see cref="UVCoord"/> struct.
/// </summary>
public UVCoord(Point point, Orientation orientation) : this(point.X, point.Y, orientation)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UVCoord"/> struct.
/// </summary>
public UVCoord(Size size, Orientation orientation) : this(size.Width, size.Height, orientation)
{
}
/// <summary>
/// Gets or sets the X coordinate.
/// </summary>
public double X { readonly get; set; }
/// <summary>
/// Gets or sets the Y coordinate.
/// </summary>
public double Y { readonly get; set; }
/// <summary>
/// Gets or sets the orientation for translation between the XY and UV coordinate systems.
/// </summary>
public Orientation Orientation { get; set; }
/// <summary>
/// Gets or sets the U coordinate.
/// </summary>
public double U
{
readonly get => Orientation is Orientation.Horizontal ? X : Y;
set
{
if (Orientation is Orientation.Horizontal)
{
X = value;
}
else
{
Y = value;
}
}
}
/// <summary>
/// Gets or sets the V coordinate.
/// </summary>
public double V
{
readonly get => Orientation is Orientation.Vertical ? X : Y;
set
{
if (Orientation is Orientation.Vertical)
{
X = value;
}
else
{
Y = value;
}
}
}
/// <summary>
/// Implicitly casts a <see cref="UVCoord"/> to a <see cref="Point"/>.
/// </summary>
public static implicit operator Point(UVCoord uv) => new(uv.X, uv.Y);
/// <summary>
/// Implicitly casts a <see cref="UVCoord"/> to a <see cref="Size"/>.
/// </summary>
public static implicit operator Size(UVCoord uv) => new(uv.X, uv.Y);
public static UVCoord operator +(UVCoord addend1, UVCoord addend2)
{
if (addend1.Orientation != addend2.Orientation)
{
throw new InvalidOperationException($"Cannot add {nameof(UVCoord)} with mismatched {nameof(Orientation)}.");
}
var xSum = addend1.X + addend2.X;
var ySum = addend1.Y + addend2.Y;
var orientation = addend1.Orientation;
return new UVCoord(xSum, ySum, orientation);
}
public static bool operator ==(UVCoord coord1, UVCoord coord2)
{
return coord1.U == coord2.U && coord1.V == coord2.V;
}
public static bool operator !=(UVCoord measure1, UVCoord measure2)
{
return !(measure1 == measure2);
}
}