-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New SizeExtensions for Windows.Foundation.Size #3489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ae61cf0
Added SizeExtensions class
Sergio0694 fbaad65
Added tests for size extensions
Sergio0694 a8de01a
Added PointExtensions class
Sergio0694 23e223c
Added unit tests for Point extensions
Sergio0694 ad0e6fd
Minor code refactoring to use the new extensions
Sergio0694 fb6b43c
Added missing Point extension
Sergio0694 6462cf4
Merge branch 'master' into feature/size-extensions
Sergio0694 f250898
Reordered using directives
Sergio0694 0941b5e
Merge branch 'master' into feature/size-extensions
Sergio0694 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // 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.Diagnostics.Contracts; | ||
| using System.Runtime.CompilerServices; | ||
| using Point = Windows.Foundation.Point; | ||
| using Rect = Windows.Foundation.Rect; | ||
| using Size = Windows.Foundation.Size; | ||
|
|
||
| namespace Microsoft.Toolkit.Uwp.Extensions | ||
| { | ||
| /// <summary> | ||
| /// Extensions for the <see cref="Point"/> type. | ||
| /// </summary> | ||
| public static class PointExtensions | ||
| { | ||
| /// <summary> | ||
| /// Creates a new <see cref="Rect"/> of the specified size, starting at a given point. | ||
| /// </summary> | ||
| /// <param name="point">The input <see cref="Point"/> value to convert.</param> | ||
| /// <param name="width">The width of the rectangle.</param> | ||
| /// <param name="height">The height of the rectangle.</param> | ||
| /// <returns>A <see cref="Rect"/> value of the specified size, starting at the given point.</returns> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static Rect ToRect(this Point point, double width, double height) | ||
| { | ||
| return new Rect(point.X, point.Y, width, height); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="Rect"/> ending at the specified point, starting at the given coordinates. | ||
| /// </summary> | ||
| /// <param name="point">The input <see cref="Point"/> value to convert.</param> | ||
| /// <param name="end">The ending position for the rectangle.</param> | ||
| /// <returns>A <see cref="Rect"/> value between the two specified points.</returns> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static Rect ToRect(this Point point, Point end) | ||
| { | ||
| return new Rect(point, end); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="Rect"/> of the specified size, starting at the given coordinates. | ||
| /// </summary> | ||
| /// <param name="point">The input <see cref="Point"/> value to convert.</param> | ||
| /// <param name="size">The size of the rectangle to create.</param> | ||
| /// <returns>A <see cref="Rect"/> value of the specified size, starting at the given coordinates.</returns> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static Rect ToRect(this Point point, Size size) | ||
| { | ||
| return new Rect(point, size); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // 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.Diagnostics.Contracts; | ||
| using System.Runtime.CompilerServices; | ||
| using Point = Windows.Foundation.Point; | ||
| using Rect = Windows.Foundation.Rect; | ||
| using Size = Windows.Foundation.Size; | ||
|
|
||
| namespace Microsoft.Toolkit.Uwp.Extensions | ||
| { | ||
| /// <summary> | ||
| /// Extensions for the <see cref="Size"/> type. | ||
| /// </summary> | ||
| public static class SizeExtensions | ||
| { | ||
| /// <summary> | ||
| /// Creates a new <see cref="Rect"/> of the specified size, starting at the origin. | ||
| /// </summary> | ||
| /// <param name="size">The input <see cref="Size"/> value to convert.</param> | ||
| /// <returns>A <see cref="Rect"/> value of the specified size, starting at the origin.</returns> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static Rect ToRect(this Size size) | ||
| { | ||
| return new Rect(0, 0, size.Width, size.Height); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="Rect"/> of the specified size, starting at the given coordinates. | ||
| /// </summary> | ||
| /// <param name="size">The input <see cref="Size"/> value to convert.</param> | ||
| /// <param name="x">The horizontal offset.</param> | ||
| /// <param name="y">The vertical offset.</param> | ||
| /// <returns>A <see cref="Rect"/> value of the specified size, starting at the given coordinates.</returns> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static Rect ToRect(this Size size, double x, double y) | ||
| { | ||
| return new Rect(x, y, size.Width, size.Height); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="Rect"/> of the specified size, starting at the given position. | ||
| /// </summary> | ||
| /// <param name="size">The input <see cref="Size"/> value to convert.</param> | ||
| /// <param name="point">The starting position to use.</param> | ||
| /// <returns>A <see cref="Rect"/> value of the specified size, starting at the given position.</returns> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static Rect ToRect(this Size size, Point point) | ||
| { | ||
| return new Rect(point, size); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sergio0694 noticed in this case we don't have a way to construct a rect from x, y, x2, y2. Would it be useful for us to create a helper for this scenario too and avoid creating both two new points just to create a Rect? This pattern is used 3 times in the other file as well. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-hawker That would be the ideal use case for static extension methods 😢
As in, ideally we'd just add a
Rect.FromCoordinatesstatic method takingx1,y1,x2,x2.Withough that (C# doesn't support that yet unfortunately), not sure about this - I mean we could add a
RectHelperclass with that method, but having a whole new helper class just for that single method might be a bit overkill 🤔If you like that idea just let me know and I can create another PR with that though!