This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathMatrix3x2Node.cs
More file actions
393 lines (357 loc) · 15.6 KB
/
Matrix3x2Node.cs
File metadata and controls
393 lines (357 loc) · 15.6 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// 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.
using System;
using System.Numerics;
namespace Microsoft.Toolkit.Uwp.UI.Animations.Expressions
{
// Ignore warning: 'Matrix3x2Node' defines operator == or operator != but does not override Object.Equals(object o) && Object.GetHashCode()
#pragma warning disable CS0660, CS0661
/// <summary>
/// Class Matrix3x2Node. This class cannot be inherited.
/// </summary>
/// <seealso cref="Microsoft.Toolkit.Uwp.UI.Animations.Expressions.ExpressionNode" />
public sealed class Matrix3x2Node : ExpressionNode
{
/// <summary>
/// Initializes a new instance of the <see cref="Matrix3x2Node"/> class.
/// </summary>
internal Matrix3x2Node()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Matrix3x2Node"/> class.
/// </summary>
/// <param name="value">The value.</param>
internal Matrix3x2Node(Matrix3x2 value)
{
_value = value;
NodeType = ExpressionNodeType.ConstantValue;
}
/// <summary>
/// Initializes a new instance of the <see cref="Matrix3x2Node"/> class.
/// </summary>
/// <param name="paramName">Name of the parameter.</param>
internal Matrix3x2Node(string paramName)
{
ParamName = paramName;
NodeType = ExpressionNodeType.ConstantParameter;
}
/// <summary>
/// Initializes a new instance of the <see cref="Matrix3x2Node"/> class.
/// </summary>
/// <param name="paramName">Name of the parameter.</param>
/// <param name="value">The value.</param>
internal Matrix3x2Node(string paramName, Matrix3x2 value)
{
ParamName = paramName;
_value = value;
NodeType = ExpressionNodeType.ConstantParameter;
SetMatrix3x2Parameter(paramName, value);
}
/// <summary>
/// Performs an implicit conversion from <see cref="Matrix3x2"/> to <see cref="Matrix3x2Node"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator Matrix3x2Node(Matrix3x2 value)
{
return new Matrix3x2Node(value);
}
/// <summary>
/// Implements the + operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix3x2Node operator +(Matrix3x2Node left, Matrix3x2Node right)
{
return ExpressionFunctions.Function<Matrix3x2Node>(ExpressionNodeType.Add, left, right);
}
/// <summary>
/// Implements the - operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix3x2Node operator -(Matrix3x2Node left, Matrix3x2Node right)
{
return ExpressionFunctions.Function<Matrix3x2Node>(ExpressionNodeType.Subtract, left, right);
}
/// <summary>
/// Implements the - operator.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the operator.</returns>
public static Matrix3x2Node operator -(Matrix3x2Node value)
{
return ExpressionFunctions.Function<Matrix3x2Node>(ExpressionNodeType.Negate, value);
}
/// <summary>
/// Implements the * operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix3x2Node operator *(Matrix3x2Node left, ScalarNode right)
{
return ExpressionFunctions.Function<Matrix3x2Node>(ExpressionNodeType.Multiply, left, right);
}
/// <summary>
/// Implements the * operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static Matrix3x2Node operator *(Matrix3x2Node left, Matrix3x2Node right)
{
return ExpressionFunctions.Function<Matrix3x2Node>(ExpressionNodeType.Multiply, left, right);
}
/// <summary>
/// Implements the == operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static BooleanNode operator ==(Matrix3x2Node left, Matrix3x2Node right)
{
return ExpressionFunctions.Function<BooleanNode>(ExpressionNodeType.Equals, left, right);
}
/// <summary>
/// Implements the != operator.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static BooleanNode operator !=(Matrix3x2Node left, Matrix3x2Node right)
{
return ExpressionFunctions.Function<BooleanNode>(ExpressionNodeType.NotEquals, left, right);
}
/// <summary>
/// Enum Subchannel
/// </summary>
public enum Subchannel
{
/// <summary>
/// The channel11
/// </summary>
Channel11,
/// <summary>
/// The channel12
/// </summary>
Channel12,
/// <summary>
/// The channel21
/// </summary>
Channel21,
/// <summary>
/// The channel22
/// </summary>
Channel22,
/// <summary>
/// The channel31
/// </summary>
Channel31,
/// <summary>
/// The channel32
/// </summary>
Channel32,
}
/// <summary>
/// Gets the channel11.
/// </summary>
/// <value>The channel11.</value>
public ScalarNode Channel11
{
get { return GetSubchannels(Subchannel.Channel11); }
}
/// <summary>
/// Gets the channel12.
/// </summary>
/// <value>The channel12.</value>
public ScalarNode Channel12
{
get { return GetSubchannels(Subchannel.Channel12); }
}
/// <summary>
/// Gets the channel21.
/// </summary>
/// <value>The channel21.</value>
public ScalarNode Channel21
{
get { return GetSubchannels(Subchannel.Channel21); }
}
/// <summary>
/// Gets the channel22.
/// </summary>
/// <value>The channel22.</value>
public ScalarNode Channel22
{
get { return GetSubchannels(Subchannel.Channel22); }
}
/// <summary>
/// Gets the channel31.
/// </summary>
/// <value>The channel31.</value>
public ScalarNode Channel31
{
get { return GetSubchannels(Subchannel.Channel31); }
}
/// <summary>
/// Gets the channel32.
/// </summary>
/// <value>The channel32.</value>
public ScalarNode Channel32
{
get { return GetSubchannels(Subchannel.Channel32); }
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s">The subchannel.</param>
/// <returns>ScalarNode</returns>
public ScalarNode GetSubchannels(Subchannel s)
{
return SubchannelsInternal<ScalarNode>(s.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <returns>Vector2Node</returns>
public Vector2Node GetSubchannels(Subchannel s1, Subchannel s2)
{
return SubchannelsInternal<Vector2Node>(s1.ToString(), s2.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <returns>Vector3Node</returns>
public Vector3Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3)
{
return SubchannelsInternal<Vector3Node>(s1.ToString(), s2.ToString(), s3.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <param name="s4">The fourth subchannel.</param>
/// <returns>Vector4Node</returns>
public Vector4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3, Subchannel s4)
{
return SubchannelsInternal<Vector4Node>(s1.ToString(), s2.ToString(), s3.ToString(), s4.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <param name="s4">The fourth subchannel.</param>
/// <param name="s5">The fifth subchannel.</param>
/// <param name="s6">The sixth subchannel.</param>
/// <returns>Matrix3x2Node</returns>
public Matrix3x2Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3, Subchannel s4, Subchannel s5, Subchannel s6)
{
return SubchannelsInternal<Matrix3x2Node>(s1.ToString(), s2.ToString(), s3.ToString(), s4.ToString(), s5.ToString(), s6.ToString());
}
/// <summary>
/// Create a new type by re-arranging the Matrix subchannels.
/// </summary>
/// <param name="s1">The first subchannel.</param>
/// <param name="s2">The second subchannel.</param>
/// <param name="s3">The third subchannel.</param>
/// <param name="s4">The fourth subchannel.</param>
/// <param name="s5">The fifth subchannel.</param>
/// <param name="s6">The sixth subchannel.</param>
/// <param name="s7">The seventh subchannel.</param>
/// <param name="s8">The eighth subchannel.</param>
/// <param name="s9">The ninth subchannel.</param>
/// <param name="s10">The tenth subchannel.</param>
/// <param name="s11">The eleventh subchannel.</param>
/// <param name="s12">The twelfth subchannel.</param>
/// <param name="s13">The thirteenth subchannel.</param>
/// <param name="s14">The fourteenth subchannel.</param>
/// <param name="s15">The fifteenth subchannel.</param>
/// <param name="s16">The sixteenth subchannel.</param>
/// <returns>Matrix4x4Node</returns>
#pragma warning disable SA1117 // Parameters must be on same line or separate lines
public Matrix4x4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3, Subchannel s4,
Subchannel s5, Subchannel s6, Subchannel s7, Subchannel s8,
Subchannel s9, Subchannel s10, Subchannel s11, Subchannel s12,
Subchannel s13, Subchannel s14, Subchannel s15, Subchannel s16)
{
return SubchannelsInternal<Matrix4x4Node>(s1.ToString(), s2.ToString(), s3.ToString(), s4.ToString(),
s5.ToString(), s6.ToString(), s7.ToString(), s8.ToString(),
s9.ToString(), s10.ToString(), s11.ToString(), s12.ToString(),
s13.ToString(), s14.ToString(), s15.ToString(), s16.ToString());
}
#pragma warning restore SA1117 // Parameters must be on same line or separate lines
/// <summary>
/// Gets the value.
/// </summary>
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Matrix3x2({_value.M11.ToCompositionString()},{_value.M12.ToCompositionString()},{_value.M21.ToCompositionString()},{_value.M22.ToCompositionString()},{_value.M31.ToCompositionString()},{_value.M32.ToCompositionString()})";
}
private Matrix3x2 _value;
/// <summary>
/// Evaluates the current value of the expression
/// </summary>
/// <returns>The current value of the expression</returns>
public Matrix3x2 Evaluate()
{
switch (NodeType)
{
case ExpressionNodeType.ConstantValue:
return _value;
case ExpressionNodeType.ReferenceProperty:
var reference = (Children[0] as ReferenceNode).Reference;
reference.Properties.TryGetMatrix3x2(PropertyName, out var referencedProperty);
return referencedProperty;
case ExpressionNodeType.Add:
return
(Children[0] as Matrix3x2Node).Evaluate() +
(Children[1] as Matrix3x2Node).Evaluate();
case ExpressionNodeType.Subtract:
return
(Children[0] as Matrix3x2Node).Evaluate() -
(Children[1] as Matrix3x2Node).Evaluate();
case ExpressionNodeType.Negate:
return
-(Children[0] as Matrix3x2Node).Evaluate();
case ExpressionNodeType.Multiply:
return (Children[0], Children[1]) switch
{
(Matrix3x2Node v1, Matrix3x2Node v2) => v1.Evaluate() * v2.Evaluate(),
(Matrix3x2Node v1, ScalarNode s2) => v1.Evaluate() * s2.Evaluate(),
(ScalarNode s1, Matrix3x2Node v2) => v2.Evaluate() * s1.Evaluate(),
_ => throw new NotImplementedException()
};
case ExpressionNodeType.Conditional:
return
(Children[0] as BooleanNode).Evaluate() ?
(Children[1] as Matrix3x2Node).Evaluate() :
(Children[2] as Matrix3x2Node).Evaluate();
case ExpressionNodeType.Swizzle:
return new Matrix3x2(
Children[0].EvaluateSubchannel(Subchannels[0]),
Children[0].EvaluateSubchannel(Subchannels[1]),
Children[0].EvaluateSubchannel(Subchannels[2]),
Children[0].EvaluateSubchannel(Subchannels[3]),
Children[0].EvaluateSubchannel(Subchannels[4]),
Children[0].EvaluateSubchannel(Subchannels[5]));
default:
throw new NotImplementedException();
}
}
}
#pragma warning restore CS0660, CS0661
}