Skip to content
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

New SizeExtensions for Windows.Foundation.Size #3489

Merged
9 commits merged into from
Sep 24, 2020

Conversation

Sergio0694
Copy link
Member

@Sergio0694 Sergio0694 commented Sep 21, 2020

Closes #3317

PR Type

What kind of change does this PR introduce?

  • Feature

What is the new behavior?

This PR adds new extensions to easily convert Windows.Foundation.Size and Point values to Rect:

namespace Microsoft.Toolkit.Uwp.Extensions
{
    public static class SizeExtensions
    {
        public static Rect ToRect(this Size size);
        public static Rect ToRect(this Size size, double x, double y);
        public static Rect ToRect(this Size size, Point point);
    }

    public static class PointExtensions
    {
        public static Rect ToRect(this Point point, double width, double height);
        public static Rect ToRect(this Point point, Point end);
        public static Rect ToRect(this Point point, Size size);
    }
}

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

@ghost
Copy link

ghost commented Sep 21, 2020

Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from azchohfi and Kyaa-dost September 21, 2020 16:00
@ghost ghost added the feature request 📬 A request for new changes to improve functionality label Sep 21, 2020
Copy link
Contributor

@Rosuavio Rosuavio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these extensions, should help make code a little more explicit.

@michael-hawker
Copy link
Member

Hey Sergio, thanks for picking this up! Couple of quick comments:

  1. We should apply these changes within the Toolkit itself to use them as called out in the issue. 🙂
  2. Can we add a Point.ToRect(Size) extension set as well? That way devs can pick whichever duality they like for construction. e.g. rectangle of size at point or rectangle at a point with size.

@Sergio0694
Copy link
Member Author

@azchohfi I'm seeing lots of CI failures due to "using directives not being sorted alphabetically", although they're from files I've personally not touched, and that apparently have never caused issues before. Also weird that the CI here is only failing after I've merged changes from master, though the CI from master is actually... Passing fine? 🤔

I can just fix that here so it's not a problem, but I was wondering whether these errors were due to some change in a StyleCop file or something else? Because I don't remember seeing these errors in the CI before, nor in my other branches so far 🤔

@ghost
Copy link

ghost commented Sep 24, 2020

Hello @Sergio0694!

Because this pull request has the auto merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@azchohfi
Copy link
Contributor

Hey @Sergio0694. I don't think that was a merge error. If you look at the full changes, those using directives were added by this PR, as they didn't exist on master before (for example: https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3489/files#diff-bd1fa812b1287e89ed50575105beb967).

@Sergio0694
Copy link
Member Author

@azchohfi You're absolutely right, I think I just got confused by the System.* usings always staying at the top and being an exception to that rule, my bad! I guess that's what I get for relying on ReSharper so much, it automatically adds using directives without you even looking so I just forgot I had actually modified them, just not by hand 😅

@ghost ghost merged commit 05d77c4 into CommunityToolkit:master Sep 24, 2020
@@ -460,7 +460,7 @@ private void UpdateMaskArea(bool animate = false)
case CropShape.Rectangular:
if (_innerGeometry is RectangleGeometry rectangleGeometry)
{
var to = new Rect(new Point(_startX, _startY), new Point(_endX, _endY));
var to = new Point(_startX, _startY).ToRect(new Point(_endX, _endY));
Copy link
Member

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?

Copy link
Member Author

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.FromCoordinates static method taking x1, y1, x2, x2.
Withough that (C# doesn't support that yet unfortunately), not sure about this - I mean we could add a RectHelper class 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!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merge ⚡ extensions ⚡ feature 💡 feature request 📬 A request for new changes to improve functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add Size Extensions
6 participants