|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.Diagnostics.Contracts; |
| 6 | +using System.Runtime.CompilerServices; |
| 7 | +using Point = Windows.Foundation.Point; |
| 8 | +using Rect = Windows.Foundation.Rect; |
| 9 | +using Size = Windows.Foundation.Size; |
| 10 | + |
| 11 | +namespace Microsoft.Toolkit.Uwp.Extensions |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Extensions for the <see cref="Size"/> type. |
| 15 | + /// </summary> |
| 16 | + public static class SizeExtensions |
| 17 | + { |
| 18 | + /// <summary> |
| 19 | + /// Creates a new <see cref="Rect"/> of the specified size, starting at the origin. |
| 20 | + /// </summary> |
| 21 | + /// <param name="size">The input <see cref="Size"/> value to convert.</param> |
| 22 | + /// <returns>A <see cref="Rect"/> value of the specified size, starting at the origin.</returns> |
| 23 | + [Pure] |
| 24 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 25 | + public static Rect ToRect(this Size size) |
| 26 | + { |
| 27 | + return new Rect(0, 0, size.Width, size.Height); |
| 28 | + } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Creates a new <see cref="Rect"/> of the specified size, starting at the given coordinates. |
| 32 | + /// </summary> |
| 33 | + /// <param name="size">The input <see cref="Size"/> value to convert.</param> |
| 34 | + /// <param name="x">The horizontal offset.</param> |
| 35 | + /// <param name="y">The vertical offset.</param> |
| 36 | + /// <returns>A <see cref="Rect"/> value of the specified size, starting at the given coordinates.</returns> |
| 37 | + [Pure] |
| 38 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 39 | + public static Rect ToRect(this Size size, double x, double y) |
| 40 | + { |
| 41 | + return new Rect(x, y, size.Width, size.Height); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Creates a new <see cref="Rect"/> of the specified size, starting at the given position. |
| 46 | + /// </summary> |
| 47 | + /// <param name="size">The input <see cref="Size"/> value to convert.</param> |
| 48 | + /// <param name="point">The starting position to use.</param> |
| 49 | + /// <returns>A <see cref="Rect"/> value of the specified size, starting at the given position.</returns> |
| 50 | + [Pure] |
| 51 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 52 | + public static Rect ToRect(this Size size, Point point) |
| 53 | + { |
| 54 | + return new Rect(point, size); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments