diff --git a/docs/cswinrt3.0-spec.md b/docs/cswinrt3.0-spec.md index c9c171d12..a55d3da79 100644 --- a/docs/cswinrt3.0-spec.md +++ b/docs/cswinrt3.0-spec.md @@ -94,9 +94,15 @@ CsWinRT 3.0 will update the projection of `T[]` parameters to use first-class sp This means you no longer need to allocate and copy stuff into arrays all over the place (because you also need the size to be exactly right, so you can't even use the array pool). Instead, you'll be able to just use spans normally. Which also means you can now even make it 0-alloc and pass stack-allocated params entirely. This is source compatible thanks to the [first class span](https://learn.microsoft.com/dotnet/csharp/language-reference/proposals/first-class-span-types) types feature of C# 14. -### Fixing `Point`/`Rect`/`Size` properties +### Fixing `Point`/`Rect`/`Size` fields -These foundational types have historically been projecting their fields as `double`, instead of `float`. This is not ideal for several reasons: it introduces implicit casts when assigning to or reading from them, it doesn't match the WinRT ABI (the backing data is still just floats), and it unnecessary impacts performance when doing lots of heavy calculations with them. In CsWinRT 3.0, we want to try fixing this design aspect and correctly projecting these members as `float`, and monitor what the real impact is on popular projects using WinRT from C#. +These foundational types have historically been projecting their fields as `double` properties, instead of `float` fields. This is not ideal for several reasons: it introduces implicit casts when assigning to or reading from them, it doesn't match the WinRT ABI (the backing data is still just floats), and it unnecessary impacts performance when doing lots of heavy calculations with them. In CsWinRT 3.0, we want to try fixing this design aspect and correctly projecting these members as `float` fields, and monitor what the real impact is on popular projects using WinRT from C#. + +### Projecting struct fields as fields + +Windows Runtime structs are plain data: all their members are fields in metadata. CsWinRT 3.0 projects them as C# fields, matching both the metadata and what C++/WinRT does. This keeps the projected shape honest (there is no accessor to run any logic behind), it allows callers to take a reference to a member (e.g. to pass it as a `ref` argument), and it makes authoring work symmetrically: `cswinrtwinmdgen.exe` maps public instance fields of an authored `struct` back to Windows Runtime struct fields, so the shape you consume is exactly the shape you author. + +This also applies to the manually projected and custom-mapped struct types, such as `Windows.Foundation.Point` and `Microsoft.UI.Xaml.CornerRadius`. Any additional member those types expose that does not correspond to a Windows Runtime struct field (e.g. `Rect.Left` or `GridLength.IsAuto`) remains a managed-only property. ### Unifying foundational event handers with .NET diff --git a/docs/event-infrastructure.md b/docs/event-infrastructure.md index 8a95a8813..701f0899d 100644 --- a/docs/event-infrastructure.md +++ b/docs/event-infrastructure.md @@ -57,7 +57,7 @@ A simple value type wrapping a 64-bit integer. This is the Windows Runtime's con ```csharp public struct EventRegistrationToken : IEquatable { - public long Value { get; set; } + public long Value; } ``` diff --git a/src/Tests/ProjectionWriterTest/Test_ProjectedStructs.cs b/src/Tests/ProjectionWriterTest/Test_ProjectedStructs.cs new file mode 100644 index 000000000..8a82e5b27 --- /dev/null +++ b/src/Tests/ProjectionWriterTest/Test_ProjectedStructs.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using ProjectionWriterTest.Helpers; + +namespace ProjectionWriterTest; + +/// +/// Tests for how the projection writer projects the members of Windows Runtime struct types. +/// +/// +/// Windows Runtime structs are plain data: their members are fields in metadata, and they must be +/// projected as C# fields. Projecting them as properties breaks authoring (the WinMD generator only +/// maps public instance fields back to Windows Runtime struct fields, so an authored struct using +/// properties would produce an empty struct in metadata), and it prevents callers from taking a +/// reference to a member. +/// +[TestClass] +public class Test_ProjectedStructs +{ + /// + /// Every field of a projected struct is emitted as a public C# field. + /// + /// + /// Windows.Foundation.Numerics.Rational is the only non-mapped struct in the projected + /// namespace, so it is the anchor for both assertions. + /// + [TestMethod] + [DataRow(true)] + [DataRow(false)] + public void StructFields_AreProjectedAsFields(bool referenceProjection) + { + string sources = ProjectionWriterRunner.GetSources(referenceProjection); + + StringAssert.Contains(sources, "public uint Numerator;", "'Rational.Numerator' should be projected as a field."); + StringAssert.Contains(sources, "public uint Denominator;", "'Rational.Denominator' should be projected as a field."); + } + + /// + /// No projected struct member is emitted as an auto-property. + /// + /// + /// Guards against a regression to the { readonly get; set; } form that projected struct + /// members used to be emitted with. + /// + [TestMethod] + [DataRow(true)] + [DataRow(false)] + public void StructFields_AreNotProjectedAsProperties(bool referenceProjection) + { + string sources = ProjectionWriterRunner.GetSources(referenceProjection); + + Assert.IsFalse(sources.Contains("readonly get; set;"), "Struct members should be projected as fields, not as auto-properties."); + } +} diff --git a/src/WinRT.Projection.Writer/Builders/ProjectionFileBuilder.cs b/src/WinRT.Projection.Writer/Builders/ProjectionFileBuilder.cs index b2f3550b5..37e13317f 100644 --- a/src/WinRT.Projection.Writer/Builders/ProjectionFileBuilder.cs +++ b/src/WinRT.Projection.Writer/Builders/ProjectionFileBuilder.cs @@ -201,6 +201,16 @@ public partial struct {{projectionName}} : IEquatable<{{projectionName}}> using (writer.WriteBlock()) { + // Windows Runtime struct fields are projected as C# fields, matching the ABI + // layout exactly. They are emitted first, so that the declaration order (which + // determines the sequential layout of the struct) mirrors the metadata order. + foreach ((string typeStr, string name, string _, bool _) in fields) + { + writer.WriteLine($"public {typeStr} {name};"); + } + + writer.WriteLineIf(fields.Count > 0); + // Emit the constructor declaration writer.Write($"public {projectionName}("); for (int i = 0; i < fields.Count; i++) @@ -233,17 +243,6 @@ public partial struct {{projectionName}} : IEquatable<{{projectionName}}> writer.WriteLine(); } - // Properties (all getters are readonly) - foreach ((string typeStr, string name, string _, bool _) in fields) - { - writer.WriteLine($$""" - public {{typeStr}} {{name}} - { - readonly get; set; - } - """); - } - // Overridden '==' operator writer.Write($"public static bool operator ==({projectionName} x, {projectionName} y) => "); diff --git a/src/WinRT.Projection.Writer/Factories/AbiStructFactory.cs b/src/WinRT.Projection.Writer/Factories/AbiStructFactory.cs index a85abc020..8f804fa21 100644 --- a/src/WinRT.Projection.Writer/Factories/AbiStructFactory.cs +++ b/src/WinRT.Projection.Writer/Factories/AbiStructFactory.cs @@ -25,9 +25,10 @@ internal static class AbiStructFactory public static void WriteAbiStruct(IndentedTextWriter writer, ProjectionEmitContext context, TypeDefinition type) { // Emit the underlying ABI struct only when not blittable AND not a mapped struct - // (mapped structs like Duration/KeyTime/RepeatBehavior have addition files that - // replace the public struct's field layout, so a per-field ABI struct can't be - // built directly from the projected type). + // (mapped structs like Duration/KeyTime/RepeatBehavior are defined in full by an + // addition file rather than generated from metadata, so the writer can't build a + // per-field ABI struct from the projected type; those types instead guarantee a + // layout-compatible shape themselves and are passed through by value). bool blittable = AbiTypeHelpers.IsTypeBlittable(context.Cache, type); (string typeNs, string typeNm) = type.Names(); bool isMappedStruct = MappedTypes.Get(typeNs, typeNm) is not null; diff --git a/src/WinRT.Projection.Writer/Factories/StructEnumMarshallerFactory.cs b/src/WinRT.Projection.Writer/Factories/StructEnumMarshallerFactory.cs index b9b05aba7..279247bc9 100644 --- a/src/WinRT.Projection.Writer/Factories/StructEnumMarshallerFactory.cs +++ b/src/WinRT.Projection.Writer/Factories/StructEnumMarshallerFactory.cs @@ -75,9 +75,9 @@ internal static void WriteStructEnumMarshallerClass(IndentedTextWriter writer, P // For structs that are mapped (e.g. Duration, KeyTime, RepeatBehavior — they have // EmitAbi=true and an addition file that completely replaces the public struct), skip - // the per-field ConvertToUnmanaged/ConvertToManaged because the projected struct's - // public fields don't match the WinMD field layout. The truth marshaller for these - // contains only BoxToUnmanaged/UnboxToManaged. + // the per-field ConvertToUnmanaged/ConvertToManaged: no ABI struct is emitted for them + // (see AbiStructFactory), as they are passed through by value. The truth marshaller for + // these contains only BoxToUnmanaged/UnboxToManaged. (string typeNs, string typeNm) = type.Names(); bool isMappedStruct = isNonBlittableStruct && MappedTypes.Get(typeNs, typeNm) is not null; diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.KeyTime.cs b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.KeyTime.cs index 9d3429d4e..ee6e5b7cb 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.KeyTime.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.KeyTime.cs @@ -8,8 +8,10 @@ namespace Microsoft.UI.Xaml.Media.Animation [WindowsRuntimeClassName("Windows.Foundation.IReference`1")] [ABI.Microsoft.UI.Xaml.Media.Animation.KeyTimeComWrappersMarshaller] #endif - public readonly struct KeyTime : IEquatable + public struct KeyTime : IEquatable { + public TimeSpan TimeSpan; + public static KeyTime FromTimeSpan(TimeSpan timeSpan) { ArgumentOutOfRangeException.ThrowIfLessThan(timeSpan, TimeSpan.Zero, nameof(timeSpan)); @@ -56,10 +58,5 @@ public static implicit operator KeyTime(TimeSpan timeSpan) { return KeyTime.FromTimeSpan(timeSpan); } - - public TimeSpan TimeSpan - { - readonly get; private init; - } } } \ No newline at end of file diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.RepeatBehavior.cs b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.RepeatBehavior.cs index 314ace50e..679d66202 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.RepeatBehavior.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Animation/Microsoft.UI.Xaml.Media.Animation.RepeatBehavior.cs @@ -10,6 +10,10 @@ namespace Microsoft.UI.Xaml.Media.Animation #endif public struct RepeatBehavior : IFormattable, IEquatable { + public double Count; + public TimeSpan Duration; + public RepeatBehaviorType Type; + internal static bool IsFinite(double value) { return !(double.IsNaN(value) || double.IsInfinity(value)); @@ -63,21 +67,6 @@ public readonly bool HasDuration } } - public double Count - { - readonly get; set; - } - - public TimeSpan Duration - { - readonly get; set; - } - - public RepeatBehaviorType Type - { - readonly get; set; - } - public readonly override string ToString() { return InternalToString(null, null); diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Media3D/Microsoft.UI.Xaml.Media.Media3D.Matrix3D.cs b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Media3D/Microsoft.UI.Xaml.Media.Media3D.Matrix3D.cs index c626baf55..cabad6f96 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Media3D/Microsoft.UI.Xaml.Media.Media3D.Matrix3D.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml.Media.Media3D/Microsoft.UI.Xaml.Media.Media3D.Matrix3D.cs @@ -10,14 +10,31 @@ namespace Microsoft.UI.Xaml.Media.Media3D #endif public struct Matrix3D : IFormattable, IEquatable { + public double M11; + public double M12; + public double M13; + public double M14; + public double M21; + public double M22; + public double M23; + public double M24; + public double M31; + public double M32; + public double M33; + public double M34; + public double OffsetX; + public double OffsetY; + public double OffsetZ; + public double M44; + // Assuming this matrix has fourth column of 0,0,0,1 and isn't identity this function: // Returns false if HasInverse is false, otherwise inverts the matrix. private bool NormalizedAffineInvert() { - double z20 = _m12 * _m23 - _m22 * _m13; - double z10 = _m32 * _m13 - _m12 * _m33; - double z00 = _m22 * _m33 - _m32 * _m23; - double det = _m31 * z20 + _m21 * z10 + _m11 * z00; + double z20 = M12 * M23 - M22 * M13; + double z10 = M32 * M13 - M12 * M33; + double z00 = M22 * M33 - M32 * M23; + double det = M31 * z20 + M21 * z10 + M11 * z00; if (IsZero(det)) { @@ -25,23 +42,23 @@ private bool NormalizedAffineInvert() } // Compute 3x3 non-zero cofactors for the 2nd column - double z21 = _m21 * _m13 - _m11 * _m23; - double z11 = _m11 * _m33 - _m31 * _m13; - double z01 = _m31 * _m23 - _m21 * _m33; + double z21 = M21 * M13 - M11 * M23; + double z11 = M11 * M33 - M31 * M13; + double z01 = M31 * M23 - M21 * M33; // Compute all six 2x2 determinants of 1st two columns - double y01 = _m11 * _m22 - _m21 * _m12; - double y02 = _m11 * _m32 - _m31 * _m12; - double y03 = _m11 * _offsetY - _offsetX * _m12; - double y12 = _m21 * _m32 - _m31 * _m22; - double y13 = _m21 * _offsetY - _offsetX * _m22; - double y23 = _m31 * _offsetY - _offsetX * _m32; + double y01 = M11 * M22 - M21 * M12; + double y02 = M11 * M32 - M31 * M12; + double y03 = M11 * OffsetY - OffsetX * M12; + double y12 = M21 * M32 - M31 * M22; + double y13 = M21 * OffsetY - OffsetX * M22; + double y23 = M31 * OffsetY - OffsetX * M32; // Compute all non-zero and non-one 3x3 cofactors for 2nd // two columns - double z23 = _m23 * y03 - _offsetZ * y01 - _m13 * y13; - double z13 = _m13 * y23 - _m33 * y03 + _offsetZ * y02; - double z03 = _m33 * y13 - _offsetZ * y12 - _m23 * y23; + double z23 = M23 * y03 - OffsetZ * y01 - M13 * y13; + double z13 = M13 * y23 - M33 * y03 + OffsetZ * y02; + double z03 = M33 * y13 - OffsetZ * y12 - M23 * y23; double z22 = y01; double z12 = -y02; double z02 = y12; @@ -49,21 +66,21 @@ private bool NormalizedAffineInvert() double rcp = 1.0 / det; // Multiply all 3x3 cofactors by reciprocal & transpose - _m11 = (z00 * rcp); - _m12 = (z10 * rcp); - _m13 = (z20 * rcp); + M11 = (z00 * rcp); + M12 = (z10 * rcp); + M13 = (z20 * rcp); - _m21 = (z01 * rcp); - _m22 = (z11 * rcp); - _m23 = (z21 * rcp); + M21 = (z01 * rcp); + M22 = (z11 * rcp); + M23 = (z21 * rcp); - _m31 = (z02 * rcp); - _m32 = (z12 * rcp); - _m33 = (z22 * rcp); + M31 = (z02 * rcp); + M32 = (z12 * rcp); + M33 = (z22 * rcp); - _offsetX = (z03 * rcp); - _offsetY = (z13 * rcp); - _offsetZ = (z23 * rcp); + OffsetX = (z03 * rcp); + OffsetY = (z13 * rcp); + OffsetZ = (z23 * rcp); return true; } @@ -77,21 +94,21 @@ private bool InvertCore() } // compute all six 2x2 determinants of 2nd two columns - double y01 = _m13 * _m24 - _m23 * _m14; - double y02 = _m13 * _m34 - _m33 * _m14; - double y03 = _m13 * _m44 - _offsetZ * _m14; - double y12 = _m23 * _m34 - _m33 * _m24; - double y13 = _m23 * _m44 - _offsetZ * _m24; - double y23 = _m33 * _m44 - _offsetZ * _m34; + double y01 = M13 * M24 - M23 * M14; + double y02 = M13 * M34 - M33 * M14; + double y03 = M13 * M44 - OffsetZ * M14; + double y12 = M23 * M34 - M33 * M24; + double y13 = M23 * M44 - OffsetZ * M24; + double y23 = M33 * M44 - OffsetZ * M34; // Compute 3x3 cofactors for 1st the column - double z30 = _m22 * y02 - _m32 * y01 - _m12 * y12; - double z20 = _m12 * y13 - _m22 * y03 + _offsetY * y01; - double z10 = _m32 * y03 - _offsetY * y02 - _m12 * y23; - double z00 = _m22 * y23 - _m32 * y13 + _offsetY * y12; + double z30 = M22 * y02 - M32 * y01 - M12 * y12; + double z20 = M12 * y13 - M22 * y03 + OffsetY * y01; + double z10 = M32 * y03 - OffsetY * y02 - M12 * y23; + double z00 = M22 * y23 - M32 * y13 + OffsetY * y12; // Compute 4x4 determinant - double det = _offsetX * z30 + _m31 * z20 + _m21 * z10 + _m11 * z00; + double det = OffsetX * z30 + M31 * z20 + M21 * z10 + M11 * z00; if (IsZero(det)) { @@ -99,51 +116,51 @@ private bool InvertCore() } // Compute 3x3 cofactors for the 2nd column - double z31 = _m11 * y12 - _m21 * y02 + _m31 * y01; - double z21 = _m21 * y03 - _offsetX * y01 - _m11 * y13; - double z11 = _m11 * y23 - _m31 * y03 + _offsetX * y02; - double z01 = _m31 * y13 - _offsetX * y12 - _m21 * y23; + double z31 = M11 * y12 - M21 * y02 + M31 * y01; + double z21 = M21 * y03 - OffsetX * y01 - M11 * y13; + double z11 = M11 * y23 - M31 * y03 + OffsetX * y02; + double z01 = M31 * y13 - OffsetX * y12 - M21 * y23; // Compute all six 2x2 determinants of 1st two columns - y01 = _m11 * _m22 - _m21 * _m12; - y02 = _m11 * _m32 - _m31 * _m12; - y03 = _m11 * _offsetY - _offsetX * _m12; - y12 = _m21 * _m32 - _m31 * _m22; - y13 = _m21 * _offsetY - _offsetX * _m22; - y23 = _m31 * _offsetY - _offsetX * _m32; + y01 = M11 * M22 - M21 * M12; + y02 = M11 * M32 - M31 * M12; + y03 = M11 * OffsetY - OffsetX * M12; + y12 = M21 * M32 - M31 * M22; + y13 = M21 * OffsetY - OffsetX * M22; + y23 = M31 * OffsetY - OffsetX * M32; // Compute all 3x3 cofactors for 2nd two columns - double z33 = _m13 * y12 - _m23 * y02 + _m33 * y01; - double z23 = _m23 * y03 - _offsetZ * y01 - _m13 * y13; - double z13 = _m13 * y23 - _m33 * y03 + _offsetZ * y02; - double z03 = _m33 * y13 - _offsetZ * y12 - _m23 * y23; - double z32 = _m24 * y02 - _m34 * y01 - _m14 * y12; - double z22 = _m14 * y13 - _m24 * y03 + _m44 * y01; - double z12 = _m34 * y03 - _m44 * y02 - _m14 * y23; - double z02 = _m24 * y23 - _m34 * y13 + _m44 * y12; + double z33 = M13 * y12 - M23 * y02 + M33 * y01; + double z23 = M23 * y03 - OffsetZ * y01 - M13 * y13; + double z13 = M13 * y23 - M33 * y03 + OffsetZ * y02; + double z03 = M33 * y13 - OffsetZ * y12 - M23 * y23; + double z32 = M24 * y02 - M34 * y01 - M14 * y12; + double z22 = M14 * y13 - M24 * y03 + M44 * y01; + double z12 = M34 * y03 - M44 * y02 - M14 * y23; + double z02 = M24 * y23 - M34 * y13 + M44 * y12; double rcp = 1.0 / det; // Multiply all 3x3 cofactors by reciprocal & transpose - _m11 = (z00 * rcp); - _m12 = (z10 * rcp); - _m13 = (z20 * rcp); - _m14 = (z30 * rcp); - - _m21 = (z01 * rcp); - _m22 = (z11 * rcp); - _m23 = (z21 * rcp); - _m24 = (z31 * rcp); - - _m31 = (z02 * rcp); - _m32 = (z12 * rcp); - _m33 = (z22 * rcp); - _m34 = (z32 * rcp); - - _offsetX = (z03 * rcp); - _offsetY = (z13 * rcp); - _offsetZ = (z23 * rcp); - _m44 = (z33 * rcp); + M11 = (z00 * rcp); + M12 = (z10 * rcp); + M13 = (z20 * rcp); + M14 = (z30 * rcp); + + M21 = (z01 * rcp); + M22 = (z11 * rcp); + M23 = (z21 * rcp); + M24 = (z31 * rcp); + + M31 = (z02 * rcp); + M32 = (z12 * rcp); + M33 = (z22 * rcp); + M34 = (z32 * rcp); + + OffsetX = (z03 * rcp); + OffsetY = (z13 * rcp); + OffsetZ = (z23 * rcp); + M44 = (z33 * rcp); return true; } @@ -153,220 +170,28 @@ public Matrix3D(double m11, double m12, double m13, double m14, double m31, double m32, double m33, double m34, double offsetX, double offsetY, double offsetZ, double m44) { - _m11 = m11; - _m12 = m12; - _m13 = m13; - _m14 = m14; - _m21 = m21; - _m22 = m22; - _m23 = m23; - _m24 = m24; - _m31 = m31; - _m32 = m32; - _m33 = m33; - _m34 = m34; - _offsetX = offsetX; - _offsetY = offsetY; - _offsetZ = offsetZ; - _m44 = m44; + M11 = m11; + M12 = m12; + M13 = m13; + M14 = m14; + M21 = m21; + M22 = m22; + M23 = m23; + M24 = m24; + M31 = m31; + M32 = m32; + M33 = m33; + M34 = m34; + OffsetX = offsetX; + OffsetY = offsetY; + OffsetZ = offsetZ; + M44 = m44; } // the transform is identity by default // Actually fill in the fields - some (internal) code uses the fields directly for perf. private static Matrix3D s_identity = CreateIdentity(); - public double M11 - { - readonly get - { - return _m11; - } - set - { - _m11 = value; - } - } - - public double M12 - { - readonly get - { - return _m12; - } - set - { - _m12 = value; - } - } - - public double M13 - { - readonly get - { - return _m13; - } - set - { - _m13 = value; - } - } - - public double M14 - { - readonly get - { - return _m14; - } - set - { - _m14 = value; - } - } - - public double M21 - { - readonly get - { - return _m21; - } - set - { - _m21 = value; - } - } - - public double M22 - { - readonly get - { - return _m22; - } - set - { - _m22 = value; - } - } - - public double M23 - { - readonly get - { - return _m23; - } - set - { - _m23 = value; - } - } - - public double M24 - { - readonly get - { - return _m24; - } - set - { - _m24 = value; - } - } - - public double M31 - { - readonly get - { - return _m31; - } - set - { - _m31 = value; - } - } - - public double M32 - { - readonly get - { - return _m32; - } - set - { - _m32 = value; - } - } - - public double M33 - { - readonly get - { - return _m33; - } - set - { - _m33 = value; - } - } - - public double M34 - { - readonly get - { - return _m34; - } - set - { - _m34 = value; - } - } - - public double OffsetX - { - readonly get - { - return _offsetX; - } - set - { - _offsetX = value; - } - } - - public double OffsetY - { - readonly get - { - return _offsetY; - } - set - { - _offsetY = value; - } - } - - public double OffsetZ - { - readonly get - { - return _offsetZ; - } - set - { - _offsetZ = value; - } - } - - public double M44 - { - readonly get - { - return _m44; - } - set - { - _m44 = value; - } - } - public static Matrix3D Identity { get @@ -379,10 +204,10 @@ public readonly bool IsIdentity { get { - return _m11 == 1 && _m12 == 0 && _m13 == 0 && _m14 == 0 && - _m21 == 0 && _m22 == 1 && _m23 == 0 && _m24 == 0 && - _m31 == 0 && _m32 == 0 && _m33 == 1 && _m34 == 0 && - _offsetX == 0 && _offsetY == 0 && _offsetZ == 0 && _m44 == 1; + return M11 == 1 && M12 == 0 && M13 == 0 && M14 == 0 && + M21 == 0 && M22 == 1 && M23 == 0 && M24 == 0 && + M31 == 0 && M32 == 0 && M33 == 1 && M34 == 0 && + OffsetX == 0 && OffsetY == 0 && OffsetZ == 0 && M44 == 1; } } @@ -417,37 +242,37 @@ private readonly string ConvertToString(string format, IFormatProvider provider) // Helper to get the numeric list separator for a given culture. char separator = global::WindowsRuntime.InteropServices.TokenizerHelper.GetNumericListSeparator(provider); DefaultInterpolatedStringHandler handler = new(0, 31, provider, stackalloc char[256]); - handler.AppendFormatted(_m11, format); + handler.AppendFormatted(M11, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m12, format); + handler.AppendFormatted(M12, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m13, format); + handler.AppendFormatted(M13, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m14, format); + handler.AppendFormatted(M14, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m21, format); + handler.AppendFormatted(M21, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m22, format); + handler.AppendFormatted(M22, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m23, format); + handler.AppendFormatted(M23, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m24, format); + handler.AppendFormatted(M24, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m31, format); + handler.AppendFormatted(M31, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m32, format); + handler.AppendFormatted(M32, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m33, format); + handler.AppendFormatted(M33, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m34, format); + handler.AppendFormatted(M34, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_offsetX, format); + handler.AppendFormatted(OffsetX, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_offsetY, format); + handler.AppendFormatted(OffsetY, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_offsetZ, format); + handler.AppendFormatted(OffsetZ, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m44, format); + handler.AppendFormatted(M44, format); return handler.ToStringAndClear(); #endif } @@ -613,22 +438,22 @@ private void SetMatrix(double m11, double m12, double m13, double m14, double m31, double m32, double m33, double m34, double offsetX, double offsetY, double offsetZ, double m44) { - _m11 = m11; - _m12 = m12; - _m13 = m13; - _m14 = m14; - _m21 = m21; - _m22 = m22; - _m23 = m23; - _m24 = m24; - _m31 = m31; - _m32 = m32; - _m33 = m33; - _m34 = m34; - _offsetX = offsetX; - _offsetY = offsetY; - _offsetZ = offsetZ; - _m44 = m44; + M11 = m11; + M12 = m12; + M13 = m13; + M14 = m14; + M21 = m21; + M22 = m22; + M23 = m23; + M24 = m24; + M31 = m31; + M32 = m32; + M33 = m33; + M34 = m34; + OffsetX = offsetX; + OffsetY = offsetY; + OffsetZ = offsetZ; + M44 = m44; } private static bool Equals(Matrix3D matrix1, Matrix3D matrix2) @@ -653,18 +478,18 @@ private static bool Equals(Matrix3D matrix1, Matrix3D matrix2) private readonly double GetNormalizedAffineDeterminant() { - double z20 = _m12 * _m23 - _m22 * _m13; - double z10 = _m32 * _m13 - _m12 * _m33; - double z00 = _m22 * _m33 - _m32 * _m23; + double z20 = M12 * M23 - M22 * M13; + double z10 = M32 * M13 - M12 * M33; + double z00 = M22 * M33 - M32 * M23; - return _m31 * z20 + _m21 * z10 + _m11 * z00; + return M31 * z20 + M21 * z10 + M11 * z00; } private readonly bool IsAffine { get { - return _m14 == 0.0 && _m24 == 0.0 && _m34 == 0.0 && _m44 == 1.0; + return M14 == 0.0 && M24 == 0.0 && M34 == 0.0 && M44 == 1.0; } } @@ -678,20 +503,20 @@ private readonly double Determinant } // compute all six 2x2 determinants of 2nd two columns - double y01 = _m13 * _m24 - _m23 * _m14; - double y02 = _m13 * _m34 - _m33 * _m14; - double y03 = _m13 * _m44 - _offsetZ * _m14; - double y12 = _m23 * _m34 - _m33 * _m24; - double y13 = _m23 * _m44 - _offsetZ * _m24; - double y23 = _m33 * _m44 - _offsetZ * _m34; + double y01 = M13 * M24 - M23 * M14; + double y02 = M13 * M34 - M33 * M14; + double y03 = M13 * M44 - OffsetZ * M14; + double y12 = M23 * M34 - M33 * M24; + double y13 = M23 * M44 - OffsetZ * M24; + double y23 = M33 * M44 - OffsetZ * M34; // Compute 3x3 cofactors for 1st the column - double z30 = _m22 * y02 - _m32 * y01 - _m12 * y12; - double z20 = _m12 * y13 - _m22 * y03 + _offsetY * y01; - double z10 = _m32 * y03 - _offsetY * y02 - _m12 * y23; - double z00 = _m22 * y23 - _m32 * y13 + _offsetY * y12; + double z30 = M22 * y02 - M32 * y01 - M12 * y12; + double z20 = M12 * y13 - M22 * y03 + OffsetY * y01; + double z10 = M32 * y03 - OffsetY * y02 - M12 * y23; + double z00 = M22 * y23 - M32 * y13 + OffsetY * y12; - return _offsetX * z30 + _m31 * z20 + _m21 * z10 + _m11 * z00; + return OffsetX * z30 + M31 * z20 + M21 * z10 + M11 * z00; } } @@ -701,22 +526,5 @@ private static bool IsZero(double value) } private const double DBL_EPSILON_RELATIVE_1 = 1.1102230246251567e-016; /* smallest such that 1.0+DBL_EPSILON != 1.0 */ - - private double _m11; - private double _m12; - private double _m13; - private double _m14; - private double _m21; - private double _m22; - private double _m23; - private double _m24; - private double _m31; - private double _m32; - private double _m33; - private double _m34; - private double _offsetX; - private double _offsetY; - private double _offsetZ; - private double _m44; } } \ No newline at end of file diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.CornerRadius.cs b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.CornerRadius.cs index 378a2ff88..505d6f466 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.CornerRadius.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.CornerRadius.cs @@ -10,25 +10,25 @@ namespace Microsoft.UI.Xaml #endif public struct CornerRadius : IEquatable { - private double _TopLeft; - private double _TopRight; - private double _BottomRight; - private double _BottomLeft; + public double TopLeft; + public double TopRight; + public double BottomRight; + public double BottomLeft; public CornerRadius(double uniformRadius) { Validate(uniformRadius, uniformRadius, uniformRadius, uniformRadius); - _TopLeft = _TopRight = _BottomRight = _BottomLeft = uniformRadius; + TopLeft = TopRight = BottomRight = BottomLeft = uniformRadius; } public CornerRadius(double topLeft, double topRight, double bottomRight, double bottomLeft) { Validate(topLeft, topRight, bottomRight, bottomLeft); - _TopLeft = topLeft; - _TopRight = topRight; - _BottomRight = bottomRight; - _BottomLeft = bottomLeft; + TopLeft = topLeft; + TopRight = topRight; + BottomRight = bottomRight; + BottomLeft = bottomLeft; } private static void Validate(double topLeft, double topRight, double bottomRight, double bottomLeft) @@ -62,13 +62,13 @@ private readonly string ToString(global::System.Globalization.CultureInfo cultur // 48 = 4x double (twelve digits is generous for the range of values likely) // 3 = 3x separator characters DefaultInterpolatedStringHandler handler = new(0, 7, cultureInfo, stackalloc char[64]); - InternalAddToHandler(_TopLeft, ref handler); + InternalAddToHandler(TopLeft, ref handler); handler.AppendFormatted(listSeparator); - InternalAddToHandler(_TopRight, ref handler); + InternalAddToHandler(TopRight, ref handler); handler.AppendFormatted(listSeparator); - InternalAddToHandler(_BottomRight, ref handler); + InternalAddToHandler(BottomRight, ref handler); handler.AppendFormatted(listSeparator); - InternalAddToHandler(_BottomLeft, ref handler); + InternalAddToHandler(BottomLeft, ref handler); return handler.ToStringAndClear(); #endif } @@ -101,57 +101,17 @@ public readonly bool Equals(CornerRadius cornerRadius) public readonly override int GetHashCode() { - return _TopLeft.GetHashCode() ^ _TopRight.GetHashCode() ^ _BottomLeft.GetHashCode() ^ _BottomRight.GetHashCode(); + return TopLeft.GetHashCode() ^ TopRight.GetHashCode() ^ BottomLeft.GetHashCode() ^ BottomRight.GetHashCode(); } public static bool operator ==(CornerRadius cr1, CornerRadius cr2) { - return cr1._TopLeft == cr2._TopLeft && cr1._TopRight == cr2._TopRight && cr1._BottomRight == cr2._BottomRight && cr1._BottomLeft == cr2._BottomLeft; + return cr1.TopLeft == cr2.TopLeft && cr1.TopRight == cr2.TopRight && cr1.BottomRight == cr2.BottomRight && cr1.BottomLeft == cr2.BottomLeft; } public static bool operator !=(CornerRadius cr1, CornerRadius cr2) { return !(cr1 == cr2); } - - public double TopLeft - { - readonly get { return _TopLeft; } - set - { - Validate(value, 0, 0, 0); - _TopLeft = value; - } - } - - public double TopRight - { - readonly get { return _TopRight; } - set - { - Validate(0, value, 0, 0); - _TopRight = value; - } - } - - public double BottomRight - { - readonly get { return _BottomRight; } - set - { - Validate(0, 0, value, 0); - _BottomRight = value; - } - } - - public double BottomLeft - { - readonly get { return _BottomLeft; } - set - { - Validate(0, 0, 0, value); - _BottomLeft = value; - } - } } } \ No newline at end of file diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.Duration.cs b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.Duration.cs index d44f825ea..534871800 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.Duration.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.Duration.cs @@ -8,20 +8,20 @@ namespace Microsoft.UI.Xaml [WindowsRuntimeClassName("Windows.Foundation.IReference`1")] [ABI.Microsoft.UI.Xaml.DurationComWrappersMarshaller] #endif - public readonly struct Duration : IEquatable + public struct Duration : IEquatable { - private readonly TimeSpan _timeSpan; - private readonly DurationType _durationType; + public TimeSpan TimeSpan; + public DurationType Type; public Duration(TimeSpan timeSpan) { - _durationType = DurationType.TimeSpan; - _timeSpan = timeSpan; + Type = DurationType.TimeSpan; + TimeSpan = timeSpan; } private Duration(DurationType durationType) { - _durationType = durationType; + Type = durationType; } public static implicit operator Duration(TimeSpan timeSpan) @@ -33,9 +33,9 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return new Duration(t1._timeSpan + t2._timeSpan); + return new Duration(t1.TimeSpan + t2.TimeSpan); } - else if (t1._durationType != DurationType.Automatic && t2._durationType != DurationType.Automatic) + else if (t1.Type != DurationType.Automatic && t2.Type != DurationType.Automatic) { return Duration.Forever; } @@ -50,9 +50,9 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return new Duration(t1._timeSpan - t2._timeSpan); + return new Duration(t1.TimeSpan - t2.TimeSpan); } - else if (t1._durationType == DurationType.Forever && t2.HasTimeSpan) + else if (t1.Type == DurationType.Forever && t2.HasTimeSpan) { return Duration.Forever; } @@ -76,13 +76,13 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return t1._timeSpan > t2._timeSpan; + return t1.TimeSpan > t2.TimeSpan; } - else if (t1.HasTimeSpan && t2._durationType == DurationType.Forever) + else if (t1.HasTimeSpan && t2.Type == DurationType.Forever) { return false; } - else if (t1._durationType == DurationType.Forever && t2.HasTimeSpan) + else if (t1.Type == DurationType.Forever && t2.HasTimeSpan) { return true; } @@ -94,11 +94,11 @@ public static implicit operator Duration(TimeSpan timeSpan) public static bool operator >=(Duration t1, Duration t2) { - if (t1._durationType == DurationType.Automatic && t2._durationType == DurationType.Automatic) + if (t1.Type == DurationType.Automatic && t2.Type == DurationType.Automatic) { return true; } - else if (t1._durationType == DurationType.Automatic || t2._durationType == DurationType.Automatic) + else if (t1.Type == DurationType.Automatic || t2.Type == DurationType.Automatic) { return false; } @@ -112,13 +112,13 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return t1._timeSpan < t2._timeSpan; + return t1.TimeSpan < t2.TimeSpan; } - else if (t1.HasTimeSpan && t2._durationType == DurationType.Forever) + else if (t1.HasTimeSpan && t2.Type == DurationType.Forever) { return true; } - else if (t1._durationType == DurationType.Forever && t2.HasTimeSpan) + else if (t1.Type == DurationType.Forever && t2.HasTimeSpan) { return false; } @@ -130,11 +130,11 @@ public static implicit operator Duration(TimeSpan timeSpan) public static bool operator <=(Duration t1, Duration t2) { - if (t1._durationType == DurationType.Automatic && t2._durationType == DurationType.Automatic) + if (t1.Type == DurationType.Automatic && t2.Type == DurationType.Automatic) { return true; } - else if (t1._durationType == DurationType.Automatic || t2._durationType == DurationType.Automatic) + else if (t1.Type == DurationType.Automatic || t2.Type == DurationType.Automatic) { return false; } @@ -146,9 +146,9 @@ public static implicit operator Duration(TimeSpan timeSpan) public static int Compare(Duration t1, Duration t2) { - if (t1._durationType == DurationType.Automatic) + if (t1.Type == DurationType.Automatic) { - if (t2._durationType == DurationType.Automatic) + if (t2.Type == DurationType.Automatic) { return 0; } @@ -157,7 +157,7 @@ public static int Compare(Duration t1, Duration t2) return -1; } } - else if (t2._durationType == DurationType.Automatic) + else if (t2.Type == DurationType.Automatic) { return 1; } @@ -187,7 +187,7 @@ public readonly bool HasTimeSpan { get { - return _durationType == DurationType.TimeSpan; + return Type == DurationType.TimeSpan; } } @@ -207,21 +207,6 @@ public static Duration Forever } } - public readonly TimeSpan TimeSpan - { - get - { - if (HasTimeSpan) - { - return _timeSpan; - } - else - { - throw new InvalidOperationException(); - } - } - } - public readonly Duration Add(Duration duration) { return this + duration; @@ -238,7 +223,7 @@ public readonly bool Equals(Duration duration) { if (duration.HasTimeSpan) { - return _timeSpan == duration._timeSpan; + return TimeSpan == duration.TimeSpan; } else { @@ -247,7 +232,7 @@ public readonly bool Equals(Duration duration) } else { - return _durationType == duration._durationType; + return Type == duration.Type; } } @@ -260,11 +245,11 @@ public readonly override int GetHashCode() { if (HasTimeSpan) { - return _timeSpan.GetHashCode(); + return TimeSpan.GetHashCode(); } else { - return _durationType.GetHashCode() + 17; + return Type.GetHashCode() + 17; } } @@ -277,9 +262,9 @@ public readonly override string ToString() { if (HasTimeSpan) { - return _timeSpan.ToString(); // "00"; //TypeDescriptor.GetConverter(_timeSpan).ConvertToString(_timeSpan); + return TimeSpan.ToString(); } - else if (_durationType == DurationType.Forever) + else if (Type == DurationType.Forever) { return "Forever"; } diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.GridLength.cs b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.GridLength.cs index 76dd7f114..989940d45 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.GridLength.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.GridLength.cs @@ -8,10 +8,10 @@ namespace Microsoft.UI.Xaml [WindowsRuntimeClassName("Windows.Foundation.IReference`1")] [ABI.Microsoft.UI.Xaml.GridLengthComWrappersMarshaller] #endif - public readonly struct GridLength : IEquatable + public struct GridLength : IEquatable { - private readonly double _unitValue; - private readonly GridUnitType _unitType; + public double Value; + public GridUnitType GridUnitType; private const double Default = 1.0; private static readonly GridLength s_auto = new(Default, GridUnitType.Auto); @@ -21,35 +21,20 @@ public GridLength(double pixels) { } - internal static bool IsFinite(double value) - { - return !(double.IsNaN(value) || double.IsInfinity(value)); - } - public GridLength(double value, GridUnitType type) { - if (!IsFinite(value) || value < 0.0) - { - throw new ArgumentException(SR.DirectUI_InvalidArgument, nameof(value)); - } - if (type is not (GridUnitType.Auto or GridUnitType.Pixel or GridUnitType.Star)) { throw new ArgumentException(SR.DirectUI_InvalidArgument, nameof(type)); } - _unitValue = (type == GridUnitType.Auto) ? Default : value; - _unitType = type; + Value = (type == GridUnitType.Auto) ? Default : value; + GridUnitType = type; } - - public readonly double Value { get { return (_unitType == GridUnitType.Auto) ? s_auto._unitValue : _unitValue; } } - public readonly GridUnitType GridUnitType { get { return _unitType; } } - - - public readonly bool IsAbsolute { get { return _unitType == GridUnitType.Pixel; } } - public readonly bool IsAuto { get { return _unitType == GridUnitType.Auto; } } - public readonly bool IsStar { get { return _unitType == GridUnitType.Star; } } + public readonly bool IsAbsolute { get { return GridUnitType == GridUnitType.Pixel; } } + public readonly bool IsAuto { get { return GridUnitType == GridUnitType.Auto; } } + public readonly bool IsStar { get { return GridUnitType == GridUnitType.Star; } } public static GridLength Auto { @@ -85,19 +70,19 @@ public readonly bool Equals(GridLength gridLength) public readonly override int GetHashCode() { - return (int)_unitValue + (int)_unitType; + return (int)Value + (int)GridUnitType; } public readonly override string ToString() { - if (_unitType == GridUnitType.Auto) + if (GridUnitType == GridUnitType.Auto) { return "Auto"; } - bool isStar = (_unitType == GridUnitType.Star); + bool isStar = (GridUnitType == GridUnitType.Star); DefaultInterpolatedStringHandler handler = new(isStar ? 1 : 0, 1, global::System.Globalization.CultureInfo.InvariantCulture, stackalloc char[32]); - handler.AppendFormatted(_unitValue); + handler.AppendFormatted(Value); if (isStar) { handler.AppendLiteral("*"); diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.KeyTime.cs b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.KeyTime.cs index 24c8e7326..ba03f82f5 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.KeyTime.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.KeyTime.cs @@ -8,8 +8,10 @@ namespace Windows.UI.Xaml.Media.Animation [WindowsRuntimeClassName("Windows.Foundation.IReference`1")] [ABI.Windows.UI.Xaml.Media.Animation.KeyTimeComWrappersMarshaller] #endif - public readonly struct KeyTime : IEquatable + public struct KeyTime : IEquatable { + public TimeSpan TimeSpan; + public static KeyTime FromTimeSpan(TimeSpan timeSpan) { ArgumentOutOfRangeException.ThrowIfLessThan(timeSpan, TimeSpan.Zero, nameof(timeSpan)); @@ -56,10 +58,5 @@ public static implicit operator KeyTime(TimeSpan timeSpan) { return KeyTime.FromTimeSpan(timeSpan); } - - public TimeSpan TimeSpan - { - readonly get; private init; - } } } \ No newline at end of file diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.RepeatBehavior.cs b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.RepeatBehavior.cs index 0f867a6b9..2106d32c3 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.RepeatBehavior.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Animation/Windows.UI.Xaml.Media.Animation.RepeatBehavior.cs @@ -10,6 +10,10 @@ namespace Windows.UI.Xaml.Media.Animation #endif public struct RepeatBehavior : IFormattable, IEquatable { + public double Count; + public TimeSpan Duration; + public RepeatBehaviorType Type; + internal static bool IsFinite(double value) { return !(double.IsNaN(value) || double.IsInfinity(value)); @@ -63,21 +67,6 @@ public readonly bool HasDuration } } - public double Count - { - readonly get; set; - } - - public TimeSpan Duration - { - readonly get; set; - } - - public RepeatBehaviorType Type - { - readonly get; set; - } - public readonly override string ToString() { return InternalToString(null, null); diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.Matrix3D.cs b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.Matrix3D.cs index 0444241b9..1120ad38a 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.Matrix3D.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml.Media.Media3D/Windows.UI.Xaml.Media.Media3D.Matrix3D.cs @@ -10,14 +10,31 @@ namespace Windows.UI.Xaml.Media.Media3D #endif public struct Matrix3D : IFormattable, IEquatable { + public double M11; + public double M12; + public double M13; + public double M14; + public double M21; + public double M22; + public double M23; + public double M24; + public double M31; + public double M32; + public double M33; + public double M34; + public double OffsetX; + public double OffsetY; + public double OffsetZ; + public double M44; + // Assuming this matrix has fourth column of 0,0,0,1 and isn't identity this function: // Returns false if HasInverse is false, otherwise inverts the matrix. private bool NormalizedAffineInvert() { - double z20 = _m12 * _m23 - _m22 * _m13; - double z10 = _m32 * _m13 - _m12 * _m33; - double z00 = _m22 * _m33 - _m32 * _m23; - double det = _m31 * z20 + _m21 * z10 + _m11 * z00; + double z20 = M12 * M23 - M22 * M13; + double z10 = M32 * M13 - M12 * M33; + double z00 = M22 * M33 - M32 * M23; + double det = M31 * z20 + M21 * z10 + M11 * z00; if (IsZero(det)) { @@ -25,23 +42,23 @@ private bool NormalizedAffineInvert() } // Compute 3x3 non-zero cofactors for the 2nd column - double z21 = _m21 * _m13 - _m11 * _m23; - double z11 = _m11 * _m33 - _m31 * _m13; - double z01 = _m31 * _m23 - _m21 * _m33; + double z21 = M21 * M13 - M11 * M23; + double z11 = M11 * M33 - M31 * M13; + double z01 = M31 * M23 - M21 * M33; // Compute all six 2x2 determinants of 1st two columns - double y01 = _m11 * _m22 - _m21 * _m12; - double y02 = _m11 * _m32 - _m31 * _m12; - double y03 = _m11 * _offsetY - _offsetX * _m12; - double y12 = _m21 * _m32 - _m31 * _m22; - double y13 = _m21 * _offsetY - _offsetX * _m22; - double y23 = _m31 * _offsetY - _offsetX * _m32; + double y01 = M11 * M22 - M21 * M12; + double y02 = M11 * M32 - M31 * M12; + double y03 = M11 * OffsetY - OffsetX * M12; + double y12 = M21 * M32 - M31 * M22; + double y13 = M21 * OffsetY - OffsetX * M22; + double y23 = M31 * OffsetY - OffsetX * M32; // Compute all non-zero and non-one 3x3 cofactors for 2nd // two columns - double z23 = _m23 * y03 - _offsetZ * y01 - _m13 * y13; - double z13 = _m13 * y23 - _m33 * y03 + _offsetZ * y02; - double z03 = _m33 * y13 - _offsetZ * y12 - _m23 * y23; + double z23 = M23 * y03 - OffsetZ * y01 - M13 * y13; + double z13 = M13 * y23 - M33 * y03 + OffsetZ * y02; + double z03 = M33 * y13 - OffsetZ * y12 - M23 * y23; double z22 = y01; double z12 = -y02; double z02 = y12; @@ -49,21 +66,21 @@ private bool NormalizedAffineInvert() double rcp = 1.0 / det; // Multiply all 3x3 cofactors by reciprocal & transpose - _m11 = (z00 * rcp); - _m12 = (z10 * rcp); - _m13 = (z20 * rcp); + M11 = (z00 * rcp); + M12 = (z10 * rcp); + M13 = (z20 * rcp); - _m21 = (z01 * rcp); - _m22 = (z11 * rcp); - _m23 = (z21 * rcp); + M21 = (z01 * rcp); + M22 = (z11 * rcp); + M23 = (z21 * rcp); - _m31 = (z02 * rcp); - _m32 = (z12 * rcp); - _m33 = (z22 * rcp); + M31 = (z02 * rcp); + M32 = (z12 * rcp); + M33 = (z22 * rcp); - _offsetX = (z03 * rcp); - _offsetY = (z13 * rcp); - _offsetZ = (z23 * rcp); + OffsetX = (z03 * rcp); + OffsetY = (z13 * rcp); + OffsetZ = (z23 * rcp); return true; } @@ -77,21 +94,21 @@ private bool InvertCore() } // compute all six 2x2 determinants of 2nd two columns - double y01 = _m13 * _m24 - _m23 * _m14; - double y02 = _m13 * _m34 - _m33 * _m14; - double y03 = _m13 * _m44 - _offsetZ * _m14; - double y12 = _m23 * _m34 - _m33 * _m24; - double y13 = _m23 * _m44 - _offsetZ * _m24; - double y23 = _m33 * _m44 - _offsetZ * _m34; + double y01 = M13 * M24 - M23 * M14; + double y02 = M13 * M34 - M33 * M14; + double y03 = M13 * M44 - OffsetZ * M14; + double y12 = M23 * M34 - M33 * M24; + double y13 = M23 * M44 - OffsetZ * M24; + double y23 = M33 * M44 - OffsetZ * M34; // Compute 3x3 cofactors for 1st the column - double z30 = _m22 * y02 - _m32 * y01 - _m12 * y12; - double z20 = _m12 * y13 - _m22 * y03 + _offsetY * y01; - double z10 = _m32 * y03 - _offsetY * y02 - _m12 * y23; - double z00 = _m22 * y23 - _m32 * y13 + _offsetY * y12; + double z30 = M22 * y02 - M32 * y01 - M12 * y12; + double z20 = M12 * y13 - M22 * y03 + OffsetY * y01; + double z10 = M32 * y03 - OffsetY * y02 - M12 * y23; + double z00 = M22 * y23 - M32 * y13 + OffsetY * y12; // Compute 4x4 determinant - double det = _offsetX * z30 + _m31 * z20 + _m21 * z10 + _m11 * z00; + double det = OffsetX * z30 + M31 * z20 + M21 * z10 + M11 * z00; if (IsZero(det)) { @@ -99,51 +116,51 @@ private bool InvertCore() } // Compute 3x3 cofactors for the 2nd column - double z31 = _m11 * y12 - _m21 * y02 + _m31 * y01; - double z21 = _m21 * y03 - _offsetX * y01 - _m11 * y13; - double z11 = _m11 * y23 - _m31 * y03 + _offsetX * y02; - double z01 = _m31 * y13 - _offsetX * y12 - _m21 * y23; + double z31 = M11 * y12 - M21 * y02 + M31 * y01; + double z21 = M21 * y03 - OffsetX * y01 - M11 * y13; + double z11 = M11 * y23 - M31 * y03 + OffsetX * y02; + double z01 = M31 * y13 - OffsetX * y12 - M21 * y23; // Compute all six 2x2 determinants of 1st two columns - y01 = _m11 * _m22 - _m21 * _m12; - y02 = _m11 * _m32 - _m31 * _m12; - y03 = _m11 * _offsetY - _offsetX * _m12; - y12 = _m21 * _m32 - _m31 * _m22; - y13 = _m21 * _offsetY - _offsetX * _m22; - y23 = _m31 * _offsetY - _offsetX * _m32; + y01 = M11 * M22 - M21 * M12; + y02 = M11 * M32 - M31 * M12; + y03 = M11 * OffsetY - OffsetX * M12; + y12 = M21 * M32 - M31 * M22; + y13 = M21 * OffsetY - OffsetX * M22; + y23 = M31 * OffsetY - OffsetX * M32; // Compute all 3x3 cofactors for 2nd two columns - double z33 = _m13 * y12 - _m23 * y02 + _m33 * y01; - double z23 = _m23 * y03 - _offsetZ * y01 - _m13 * y13; - double z13 = _m13 * y23 - _m33 * y03 + _offsetZ * y02; - double z03 = _m33 * y13 - _offsetZ * y12 - _m23 * y23; - double z32 = _m24 * y02 - _m34 * y01 - _m14 * y12; - double z22 = _m14 * y13 - _m24 * y03 + _m44 * y01; - double z12 = _m34 * y03 - _m44 * y02 - _m14 * y23; - double z02 = _m24 * y23 - _m34 * y13 + _m44 * y12; + double z33 = M13 * y12 - M23 * y02 + M33 * y01; + double z23 = M23 * y03 - OffsetZ * y01 - M13 * y13; + double z13 = M13 * y23 - M33 * y03 + OffsetZ * y02; + double z03 = M33 * y13 - OffsetZ * y12 - M23 * y23; + double z32 = M24 * y02 - M34 * y01 - M14 * y12; + double z22 = M14 * y13 - M24 * y03 + M44 * y01; + double z12 = M34 * y03 - M44 * y02 - M14 * y23; + double z02 = M24 * y23 - M34 * y13 + M44 * y12; double rcp = 1.0 / det; // Multiply all 3x3 cofactors by reciprocal & transpose - _m11 = (z00 * rcp); - _m12 = (z10 * rcp); - _m13 = (z20 * rcp); - _m14 = (z30 * rcp); - - _m21 = (z01 * rcp); - _m22 = (z11 * rcp); - _m23 = (z21 * rcp); - _m24 = (z31 * rcp); - - _m31 = (z02 * rcp); - _m32 = (z12 * rcp); - _m33 = (z22 * rcp); - _m34 = (z32 * rcp); - - _offsetX = (z03 * rcp); - _offsetY = (z13 * rcp); - _offsetZ = (z23 * rcp); - _m44 = (z33 * rcp); + M11 = (z00 * rcp); + M12 = (z10 * rcp); + M13 = (z20 * rcp); + M14 = (z30 * rcp); + + M21 = (z01 * rcp); + M22 = (z11 * rcp); + M23 = (z21 * rcp); + M24 = (z31 * rcp); + + M31 = (z02 * rcp); + M32 = (z12 * rcp); + M33 = (z22 * rcp); + M34 = (z32 * rcp); + + OffsetX = (z03 * rcp); + OffsetY = (z13 * rcp); + OffsetZ = (z23 * rcp); + M44 = (z33 * rcp); return true; } @@ -153,220 +170,28 @@ public Matrix3D(double m11, double m12, double m13, double m14, double m31, double m32, double m33, double m34, double offsetX, double offsetY, double offsetZ, double m44) { - _m11 = m11; - _m12 = m12; - _m13 = m13; - _m14 = m14; - _m21 = m21; - _m22 = m22; - _m23 = m23; - _m24 = m24; - _m31 = m31; - _m32 = m32; - _m33 = m33; - _m34 = m34; - _offsetX = offsetX; - _offsetY = offsetY; - _offsetZ = offsetZ; - _m44 = m44; + M11 = m11; + M12 = m12; + M13 = m13; + M14 = m14; + M21 = m21; + M22 = m22; + M23 = m23; + M24 = m24; + M31 = m31; + M32 = m32; + M33 = m33; + M34 = m34; + OffsetX = offsetX; + OffsetY = offsetY; + OffsetZ = offsetZ; + M44 = m44; } // the transform is identity by default // Actually fill in the fields - some (internal) code uses the fields directly for perf. private static Matrix3D s_identity = CreateIdentity(); - public double M11 - { - readonly get - { - return _m11; - } - set - { - _m11 = value; - } - } - - public double M12 - { - readonly get - { - return _m12; - } - set - { - _m12 = value; - } - } - - public double M13 - { - readonly get - { - return _m13; - } - set - { - _m13 = value; - } - } - - public double M14 - { - readonly get - { - return _m14; - } - set - { - _m14 = value; - } - } - - public double M21 - { - readonly get - { - return _m21; - } - set - { - _m21 = value; - } - } - - public double M22 - { - readonly get - { - return _m22; - } - set - { - _m22 = value; - } - } - - public double M23 - { - readonly get - { - return _m23; - } - set - { - _m23 = value; - } - } - - public double M24 - { - readonly get - { - return _m24; - } - set - { - _m24 = value; - } - } - - public double M31 - { - readonly get - { - return _m31; - } - set - { - _m31 = value; - } - } - - public double M32 - { - readonly get - { - return _m32; - } - set - { - _m32 = value; - } - } - - public double M33 - { - readonly get - { - return _m33; - } - set - { - _m33 = value; - } - } - - public double M34 - { - readonly get - { - return _m34; - } - set - { - _m34 = value; - } - } - - public double OffsetX - { - readonly get - { - return _offsetX; - } - set - { - _offsetX = value; - } - } - - public double OffsetY - { - readonly get - { - return _offsetY; - } - set - { - _offsetY = value; - } - } - - public double OffsetZ - { - readonly get - { - return _offsetZ; - } - set - { - _offsetZ = value; - } - } - - public double M44 - { - readonly get - { - return _m44; - } - set - { - _m44 = value; - } - } - public static Matrix3D Identity { get @@ -379,10 +204,10 @@ public readonly bool IsIdentity { get { - return _m11 == 1 && _m12 == 0 && _m13 == 0 && _m14 == 0 && - _m21 == 0 && _m22 == 1 && _m23 == 0 && _m24 == 0 && - _m31 == 0 && _m32 == 0 && _m33 == 1 && _m34 == 0 && - _offsetX == 0 && _offsetY == 0 && _offsetZ == 0 && _m44 == 1; + return M11 == 1 && M12 == 0 && M13 == 0 && M14 == 0 && + M21 == 0 && M22 == 1 && M23 == 0 && M24 == 0 && + M31 == 0 && M32 == 0 && M33 == 1 && M34 == 0 && + OffsetX == 0 && OffsetY == 0 && OffsetZ == 0 && M44 == 1; } } @@ -417,37 +242,37 @@ private readonly string ConvertToString(string format, IFormatProvider provider) // Helper to get the numeric list separator for a given culture. char separator = global::WindowsRuntime.InteropServices.TokenizerHelper.GetNumericListSeparator(provider); DefaultInterpolatedStringHandler handler = new(0, 31, provider, stackalloc char[256]); - handler.AppendFormatted(_m11, format); + handler.AppendFormatted(M11, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m12, format); + handler.AppendFormatted(M12, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m13, format); + handler.AppendFormatted(M13, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m14, format); + handler.AppendFormatted(M14, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m21, format); + handler.AppendFormatted(M21, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m22, format); + handler.AppendFormatted(M22, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m23, format); + handler.AppendFormatted(M23, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m24, format); + handler.AppendFormatted(M24, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m31, format); + handler.AppendFormatted(M31, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m32, format); + handler.AppendFormatted(M32, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m33, format); + handler.AppendFormatted(M33, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m34, format); + handler.AppendFormatted(M34, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_offsetX, format); + handler.AppendFormatted(OffsetX, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_offsetY, format); + handler.AppendFormatted(OffsetY, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_offsetZ, format); + handler.AppendFormatted(OffsetZ, format); handler.AppendFormatted(separator); - handler.AppendFormatted(_m44, format); + handler.AppendFormatted(M44, format); return handler.ToStringAndClear(); #endif } @@ -613,22 +438,22 @@ private void SetMatrix(double m11, double m12, double m13, double m14, double m31, double m32, double m33, double m34, double offsetX, double offsetY, double offsetZ, double m44) { - _m11 = m11; - _m12 = m12; - _m13 = m13; - _m14 = m14; - _m21 = m21; - _m22 = m22; - _m23 = m23; - _m24 = m24; - _m31 = m31; - _m32 = m32; - _m33 = m33; - _m34 = m34; - _offsetX = offsetX; - _offsetY = offsetY; - _offsetZ = offsetZ; - _m44 = m44; + M11 = m11; + M12 = m12; + M13 = m13; + M14 = m14; + M21 = m21; + M22 = m22; + M23 = m23; + M24 = m24; + M31 = m31; + M32 = m32; + M33 = m33; + M34 = m34; + OffsetX = offsetX; + OffsetY = offsetY; + OffsetZ = offsetZ; + M44 = m44; } private static bool Equals(Matrix3D matrix1, Matrix3D matrix2) @@ -653,18 +478,18 @@ private static bool Equals(Matrix3D matrix1, Matrix3D matrix2) private readonly double GetNormalizedAffineDeterminant() { - double z20 = _m12 * _m23 - _m22 * _m13; - double z10 = _m32 * _m13 - _m12 * _m33; - double z00 = _m22 * _m33 - _m32 * _m23; + double z20 = M12 * M23 - M22 * M13; + double z10 = M32 * M13 - M12 * M33; + double z00 = M22 * M33 - M32 * M23; - return _m31 * z20 + _m21 * z10 + _m11 * z00; + return M31 * z20 + M21 * z10 + M11 * z00; } private readonly bool IsAffine { get { - return _m14 == 0.0 && _m24 == 0.0 && _m34 == 0.0 && _m44 == 1.0; + return M14 == 0.0 && M24 == 0.0 && M34 == 0.0 && M44 == 1.0; } } @@ -678,20 +503,20 @@ private readonly double Determinant } // compute all six 2x2 determinants of 2nd two columns - double y01 = _m13 * _m24 - _m23 * _m14; - double y02 = _m13 * _m34 - _m33 * _m14; - double y03 = _m13 * _m44 - _offsetZ * _m14; - double y12 = _m23 * _m34 - _m33 * _m24; - double y13 = _m23 * _m44 - _offsetZ * _m24; - double y23 = _m33 * _m44 - _offsetZ * _m34; + double y01 = M13 * M24 - M23 * M14; + double y02 = M13 * M34 - M33 * M14; + double y03 = M13 * M44 - OffsetZ * M14; + double y12 = M23 * M34 - M33 * M24; + double y13 = M23 * M44 - OffsetZ * M24; + double y23 = M33 * M44 - OffsetZ * M34; // Compute 3x3 cofactors for 1st the column - double z30 = _m22 * y02 - _m32 * y01 - _m12 * y12; - double z20 = _m12 * y13 - _m22 * y03 + _offsetY * y01; - double z10 = _m32 * y03 - _offsetY * y02 - _m12 * y23; - double z00 = _m22 * y23 - _m32 * y13 + _offsetY * y12; + double z30 = M22 * y02 - M32 * y01 - M12 * y12; + double z20 = M12 * y13 - M22 * y03 + OffsetY * y01; + double z10 = M32 * y03 - OffsetY * y02 - M12 * y23; + double z00 = M22 * y23 - M32 * y13 + OffsetY * y12; - return _offsetX * z30 + _m31 * z20 + _m21 * z10 + _m11 * z00; + return OffsetX * z30 + M31 * z20 + M21 * z10 + M11 * z00; } } @@ -701,22 +526,5 @@ private static bool IsZero(double value) } private const double DBL_EPSILON_RELATIVE_1 = 1.1102230246251567e-016; /* smallest such that 1.0+DBL_EPSILON != 1.0 */ - - private double _m11; - private double _m12; - private double _m13; - private double _m14; - private double _m21; - private double _m22; - private double _m23; - private double _m24; - private double _m31; - private double _m32; - private double _m33; - private double _m34; - private double _offsetX; - private double _offsetY; - private double _offsetZ; - private double _m44; } } diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.CornerRadius.cs b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.CornerRadius.cs index 262b88345..e217e5953 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.CornerRadius.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.CornerRadius.cs @@ -10,25 +10,25 @@ namespace Windows.UI.Xaml #endif public struct CornerRadius : IEquatable { - private double _TopLeft; - private double _TopRight; - private double _BottomRight; - private double _BottomLeft; + public double TopLeft; + public double TopRight; + public double BottomRight; + public double BottomLeft; public CornerRadius(double uniformRadius) { Validate(uniformRadius, uniformRadius, uniformRadius, uniformRadius); - _TopLeft = _TopRight = _BottomRight = _BottomLeft = uniformRadius; + TopLeft = TopRight = BottomRight = BottomLeft = uniformRadius; } public CornerRadius(double topLeft, double topRight, double bottomRight, double bottomLeft) { Validate(topLeft, topRight, bottomRight, bottomLeft); - _TopLeft = topLeft; - _TopRight = topRight; - _BottomRight = bottomRight; - _BottomLeft = bottomLeft; + TopLeft = topLeft; + TopRight = topRight; + BottomRight = bottomRight; + BottomLeft = bottomLeft; } private static void Validate(double topLeft, double topRight, double bottomRight, double bottomLeft) @@ -62,13 +62,13 @@ private readonly string ToString(global::System.Globalization.CultureInfo cultur // 48 = 4x double (twelve digits is generous for the range of values likely) // 3 = 3x separator characters DefaultInterpolatedStringHandler handler = new(0, 7, cultureInfo, stackalloc char[64]); - InternalAddToHandler(_TopLeft, ref handler); + InternalAddToHandler(TopLeft, ref handler); handler.AppendFormatted(listSeparator); - InternalAddToHandler(_TopRight, ref handler); + InternalAddToHandler(TopRight, ref handler); handler.AppendFormatted(listSeparator); - InternalAddToHandler(_BottomRight, ref handler); + InternalAddToHandler(BottomRight, ref handler); handler.AppendFormatted(listSeparator); - InternalAddToHandler(_BottomLeft, ref handler); + InternalAddToHandler(BottomLeft, ref handler); return handler.ToStringAndClear(); #endif } @@ -101,57 +101,17 @@ public readonly bool Equals(CornerRadius cornerRadius) public readonly override int GetHashCode() { - return _TopLeft.GetHashCode() ^ _TopRight.GetHashCode() ^ _BottomLeft.GetHashCode() ^ _BottomRight.GetHashCode(); + return TopLeft.GetHashCode() ^ TopRight.GetHashCode() ^ BottomLeft.GetHashCode() ^ BottomRight.GetHashCode(); } public static bool operator ==(CornerRadius cr1, CornerRadius cr2) { - return cr1._TopLeft == cr2._TopLeft && cr1._TopRight == cr2._TopRight && cr1._BottomRight == cr2._BottomRight && cr1._BottomLeft == cr2._BottomLeft; + return cr1.TopLeft == cr2.TopLeft && cr1.TopRight == cr2.TopRight && cr1.BottomRight == cr2.BottomRight && cr1.BottomLeft == cr2.BottomLeft; } public static bool operator !=(CornerRadius cr1, CornerRadius cr2) { return !(cr1 == cr2); } - - public double TopLeft - { - readonly get { return _TopLeft; } - set - { - Validate(value, 0, 0, 0); - _TopLeft = value; - } - } - - public double TopRight - { - readonly get { return _TopRight; } - set - { - Validate(0, value, 0, 0); - _TopRight = value; - } - } - - public double BottomRight - { - readonly get { return _BottomRight; } - set - { - Validate(0, 0, value, 0); - _BottomRight = value; - } - } - - public double BottomLeft - { - readonly get { return _BottomLeft; } - set - { - Validate(0, 0, 0, value); - _BottomLeft = value; - } - } } } \ No newline at end of file diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.Duration.cs b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.Duration.cs index 095ed31f3..a34c179c2 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.Duration.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.Duration.cs @@ -8,20 +8,20 @@ namespace Windows.UI.Xaml [WindowsRuntimeClassName("Windows.Foundation.IReference`1")] [ABI.Windows.UI.Xaml.DurationComWrappersMarshaller] #endif - public readonly struct Duration : IEquatable + public struct Duration : IEquatable { - private readonly TimeSpan _timeSpan; - private readonly DurationType _durationType; + public TimeSpan TimeSpan; + public DurationType Type; public Duration(TimeSpan timeSpan) { - _durationType = DurationType.TimeSpan; - _timeSpan = timeSpan; + Type = DurationType.TimeSpan; + TimeSpan = timeSpan; } private Duration(DurationType durationType) { - _durationType = durationType; + Type = durationType; } public static implicit operator Duration(TimeSpan timeSpan) @@ -33,9 +33,9 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return new Duration(t1._timeSpan + t2._timeSpan); + return new Duration(t1.TimeSpan + t2.TimeSpan); } - else if (t1._durationType != DurationType.Automatic && t2._durationType != DurationType.Automatic) + else if (t1.Type != DurationType.Automatic && t2.Type != DurationType.Automatic) { return Duration.Forever; } @@ -50,9 +50,9 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return new Duration(t1._timeSpan - t2._timeSpan); + return new Duration(t1.TimeSpan - t2.TimeSpan); } - else if (t1._durationType == DurationType.Forever && t2.HasTimeSpan) + else if (t1.Type == DurationType.Forever && t2.HasTimeSpan) { return Duration.Forever; } @@ -76,13 +76,13 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return t1._timeSpan > t2._timeSpan; + return t1.TimeSpan > t2.TimeSpan; } - else if (t1.HasTimeSpan && t2._durationType == DurationType.Forever) + else if (t1.HasTimeSpan && t2.Type == DurationType.Forever) { return false; } - else if (t1._durationType == DurationType.Forever && t2.HasTimeSpan) + else if (t1.Type == DurationType.Forever && t2.HasTimeSpan) { return true; } @@ -94,11 +94,11 @@ public static implicit operator Duration(TimeSpan timeSpan) public static bool operator >=(Duration t1, Duration t2) { - if (t1._durationType == DurationType.Automatic && t2._durationType == DurationType.Automatic) + if (t1.Type == DurationType.Automatic && t2.Type == DurationType.Automatic) { return true; } - else if (t1._durationType == DurationType.Automatic || t2._durationType == DurationType.Automatic) + else if (t1.Type == DurationType.Automatic || t2.Type == DurationType.Automatic) { return false; } @@ -112,13 +112,13 @@ public static implicit operator Duration(TimeSpan timeSpan) { if (t1.HasTimeSpan && t2.HasTimeSpan) { - return t1._timeSpan < t2._timeSpan; + return t1.TimeSpan < t2.TimeSpan; } - else if (t1.HasTimeSpan && t2._durationType == DurationType.Forever) + else if (t1.HasTimeSpan && t2.Type == DurationType.Forever) { return true; } - else if (t1._durationType == DurationType.Forever && t2.HasTimeSpan) + else if (t1.Type == DurationType.Forever && t2.HasTimeSpan) { return false; } @@ -130,11 +130,11 @@ public static implicit operator Duration(TimeSpan timeSpan) public static bool operator <=(Duration t1, Duration t2) { - if (t1._durationType == DurationType.Automatic && t2._durationType == DurationType.Automatic) + if (t1.Type == DurationType.Automatic && t2.Type == DurationType.Automatic) { return true; } - else if (t1._durationType == DurationType.Automatic || t2._durationType == DurationType.Automatic) + else if (t1.Type == DurationType.Automatic || t2.Type == DurationType.Automatic) { return false; } @@ -146,9 +146,9 @@ public static implicit operator Duration(TimeSpan timeSpan) public static int Compare(Duration t1, Duration t2) { - if (t1._durationType == DurationType.Automatic) + if (t1.Type == DurationType.Automatic) { - if (t2._durationType == DurationType.Automatic) + if (t2.Type == DurationType.Automatic) { return 0; } @@ -157,7 +157,7 @@ public static int Compare(Duration t1, Duration t2) return -1; } } - else if (t2._durationType == DurationType.Automatic) + else if (t2.Type == DurationType.Automatic) { return 1; } @@ -187,7 +187,7 @@ public readonly bool HasTimeSpan { get { - return _durationType == DurationType.TimeSpan; + return Type == DurationType.TimeSpan; } } @@ -207,21 +207,6 @@ public static Duration Forever } } - public readonly TimeSpan TimeSpan - { - get - { - if (HasTimeSpan) - { - return _timeSpan; - } - else - { - throw new InvalidOperationException(); - } - } - } - public readonly Duration Add(Duration duration) { return this + duration; @@ -238,7 +223,7 @@ public readonly bool Equals(Duration duration) { if (duration.HasTimeSpan) { - return _timeSpan == duration._timeSpan; + return TimeSpan == duration.TimeSpan; } else { @@ -247,7 +232,7 @@ public readonly bool Equals(Duration duration) } else { - return _durationType == duration._durationType; + return Type == duration.Type; } } @@ -260,11 +245,11 @@ public readonly override int GetHashCode() { if (HasTimeSpan) { - return _timeSpan.GetHashCode(); + return TimeSpan.GetHashCode(); } else { - return _durationType.GetHashCode() + 17; + return Type.GetHashCode() + 17; } } @@ -277,9 +262,9 @@ public readonly override string ToString() { if (HasTimeSpan) { - return _timeSpan.ToString(); // "00"; //TypeDescriptor.GetConverter(_timeSpan).ConvertToString(_timeSpan); + return TimeSpan.ToString(); } - else if (_durationType == DurationType.Forever) + else if (Type == DurationType.Forever) { return "Forever"; } diff --git a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.GridLength.cs b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.GridLength.cs index 63ce9d3d1..4e28a999f 100644 --- a/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.GridLength.cs +++ b/src/WinRT.Projection.Writer/Resources/Additions/Windows.UI.Xaml/Windows.UI.Xaml.GridLength.cs @@ -8,10 +8,10 @@ namespace Windows.UI.Xaml [WindowsRuntimeClassName("Windows.Foundation.IReference`1")] [ABI.Windows.UI.Xaml.GridLengthComWrappersMarshaller] #endif - public readonly struct GridLength : IEquatable + public struct GridLength : IEquatable { - private readonly double _unitValue; - private readonly GridUnitType _unitType; + public double Value; + public GridUnitType GridUnitType; private const double Default = 1.0; private static readonly GridLength s_auto = new(Default, GridUnitType.Auto); @@ -21,35 +21,20 @@ public GridLength(double pixels) { } - internal static bool IsFinite(double value) - { - return !(double.IsNaN(value) || double.IsInfinity(value)); - } - public GridLength(double value, GridUnitType type) { - if (!IsFinite(value) || value < 0.0) - { - throw new ArgumentException(SR.DirectUI_InvalidArgument, nameof(value)); - } - if (type is not (GridUnitType.Auto or GridUnitType.Pixel or GridUnitType.Star)) { throw new ArgumentException(SR.DirectUI_InvalidArgument, nameof(type)); } - _unitValue = (type == GridUnitType.Auto) ? Default : value; - _unitType = type; + Value = (type == GridUnitType.Auto) ? Default : value; + GridUnitType = type; } - - public readonly double Value { get { return (_unitType == GridUnitType.Auto) ? s_auto._unitValue : _unitValue; } } - public readonly GridUnitType GridUnitType { get { return _unitType; } } - - - public readonly bool IsAbsolute { get { return _unitType == GridUnitType.Pixel; } } - public readonly bool IsAuto { get { return _unitType == GridUnitType.Auto; } } - public readonly bool IsStar { get { return _unitType == GridUnitType.Star; } } + public readonly bool IsAbsolute { get { return GridUnitType == GridUnitType.Pixel; } } + public readonly bool IsAuto { get { return GridUnitType == GridUnitType.Auto; } } + public readonly bool IsStar { get { return GridUnitType == GridUnitType.Star; } } public static GridLength Auto { @@ -85,19 +70,19 @@ public readonly bool Equals(GridLength gridLength) public readonly override int GetHashCode() { - return (int)_unitValue + (int)_unitType; + return (int)Value + (int)GridUnitType; } public readonly override string ToString() { - if (_unitType == GridUnitType.Auto) + if (GridUnitType == GridUnitType.Auto) { return "Auto"; } - bool isStar = (_unitType == GridUnitType.Star); + bool isStar = (GridUnitType == GridUnitType.Star); DefaultInterpolatedStringHandler handler = new(isStar ? 1 : 0, 1, global::System.Globalization.CultureInfo.InvariantCulture, stackalloc char[32]); - handler.AppendFormatted(_unitValue); + handler.AppendFormatted(Value); if (isStar) { handler.AppendLiteral("*"); diff --git a/src/WinRT.Runtime2/InteropServices/Events/EventRegistrationToken.cs b/src/WinRT.Runtime2/InteropServices/Events/EventRegistrationToken.cs index db2d06d87..5db8158f5 100644 --- a/src/WinRT.Runtime2/InteropServices/Events/EventRegistrationToken.cs +++ b/src/WinRT.Runtime2/InteropServices/Events/EventRegistrationToken.cs @@ -19,6 +19,11 @@ namespace WindowsRuntime.InteropServices; #endif public struct EventRegistrationToken : IEquatable { + /// + /// The reference to the delegate. A valid reference will not have a value of zero. + /// + public long Value; + /// /// Creates a new value with the specified parameters. /// @@ -28,11 +33,6 @@ public EventRegistrationToken(long value) Value = value; } - /// - /// Gets or sets the reference to the delegate. A valid reference will not have a value of zero. - /// - public long Value { readonly get; set; } - /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly bool Equals(EventRegistrationToken other) diff --git a/src/WinRT.Runtime2/Windows.Foundation/Point.cs b/src/WinRT.Runtime2/Windows.Foundation/Point.cs index e299dbd3f..cb563163c 100644 --- a/src/WinRT.Runtime2/Windows.Foundation/Point.cs +++ b/src/WinRT.Runtime2/Windows.Foundation/Point.cs @@ -30,6 +30,16 @@ namespace Windows.Foundation; #endif public struct Point : IEquatable, IFormattable { + /// + /// The horizontal position of the point. + /// + public float X; + + /// + /// The vertical position of the point. + /// + public float Y; + /// /// Creates a new value with the specified parameters. /// @@ -41,16 +51,6 @@ public Point(float x, float y) Y = y; } - /// - /// Gets or sets the horizontal position of the point. - /// - public float X { readonly get; set; } - - /// - /// Gets or sets the vertical position of the point. - /// - public float Y { readonly get; set; } - /// /// Deconstructs the current value into its components. /// diff --git a/src/WinRT.Runtime2/Windows.Foundation/Rect.cs b/src/WinRT.Runtime2/Windows.Foundation/Rect.cs index 6c899b63b..088919d14 100644 --- a/src/WinRT.Runtime2/Windows.Foundation/Rect.cs +++ b/src/WinRT.Runtime2/Windows.Foundation/Rect.cs @@ -32,6 +32,26 @@ namespace Windows.Foundation; #endif public struct Rect : IEquatable, IFormattable { + /// + /// The x-coordinate of the upper-left corner of the rectangle. + /// + public float X; + + /// + /// The y-coordinate of the upper-left corner of the rectangle. + /// + public float Y; + + /// + /// The width of the rectangle, in pixels. + /// + public float Width; + + /// + /// The height of the rectangle, in pixels. + /// + public float Height; + /// /// Creates a new value with the specified parameters. /// @@ -76,52 +96,15 @@ public Rect(Point location, Size size) /// Thrown if or are less than zero. public Rect(float x, float y, float width, float height) { + ArgumentOutOfRangeException.ThrowIfNegative(width); + ArgumentOutOfRangeException.ThrowIfNegative(height); + X = x; Y = y; Width = width; Height = height; } - /// - /// Gets or sets the x-coordinate of the upper-left corner of the rectangle. - /// - public float X { readonly get; set; } - - /// - /// Gets or sets the y-coordinate of the upper-left corner of the rectangle. - /// - public float Y { readonly get; set; } - - /// - /// Gets or sets the width of the rectangle, in pixels. - /// - /// Thrown if the value is less than zero. - public float Width - { - readonly get; - set - { - ArgumentOutOfRangeException.ThrowIfNegative(value); - - field = value; - } - } - - /// - /// Gets or sets the height of the rectangle, in pixels. - /// - /// Thrown if the value is less than zero. - public float Height - { - readonly get; - set - { - ArgumentOutOfRangeException.ThrowIfNegative(value); - - field = value; - } - } - /// /// Gets the left x-coordinate of the rectangle. /// diff --git a/src/WinRT.Runtime2/Windows.Foundation/Size.cs b/src/WinRT.Runtime2/Windows.Foundation/Size.cs index 9d366807d..ddbd7676e 100644 --- a/src/WinRT.Runtime2/Windows.Foundation/Size.cs +++ b/src/WinRT.Runtime2/Windows.Foundation/Size.cs @@ -30,45 +30,28 @@ namespace Windows.Foundation; public struct Size : IEquatable, IFormattable { /// - /// Creates a new value with the specified parameters. + /// The width. /// - /// The width. - /// The height. - /// Thrown if or are less than zero. - public Size(float width, float height) - { - Width = width; - Height = height; - } + public float Width; /// - /// Gets or sets the width. + /// The height. /// - /// Thrown if the value is less than zero. - public float Width - { - readonly get; - set - { - ArgumentOutOfRangeException.ThrowIfNegative(value); - - field = value; - } - } + public float Height; /// - /// Gets or sets the height. + /// Creates a new value with the specified parameters. /// - /// Thrown if the value is less than zero. - public float Height + /// The width. + /// The height. + /// Thrown if or are less than zero. + public Size(float width, float height) { - readonly get; - set - { - ArgumentOutOfRangeException.ThrowIfNegative(value); + ArgumentOutOfRangeException.ThrowIfNegative(width); + ArgumentOutOfRangeException.ThrowIfNegative(height); - field = value; - } + Width = width; + Height = height; } ///