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

feat(PinchGestureRecognizer): Report Pinch angle in degrees #13244

Conversation

workgroupengineering
Copy link
Contributor

@workgroupengineering workgroupengineering commented Oct 13, 2023

What does the pull request do?

Report Pinch angle in degrees

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

  • Add to PinchEventArgs ctor orverload
  • Add ro Add to PinchEventArgs ctor orverload read only Agnle property

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #13227

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0040828-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

{
Scale = scale;
ScaleOrigin = scaleOrigin;
}

public PinchEventArgs(double scale, Point scaleOrigin, double degree) : base(Gestures.PinchEvent)
Copy link
Contributor

Choose a reason for hiding this comment

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

double degree should really be double angle to follow standard parameter naming conventions. Degrees would then be in comments.

public double Scale { get; } = 1;

public Point ScaleOrigin { get; }

/// <summary>
/// Pinch angle in degrees
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a lot more descriptive. Also needs to start with "Gets" and have a "." at the end to avoid analyzer warnings and follow conventions.

/// <summary>
/// Gets the angle of the pinch gesture, in degrees.
/// <summary>
/// <remarks>
/// A pinch gesture is the movement of two pressed points closer together. This property is the measured angle of the line between those two points. Remember zero degrees is a line pointing up.
/// </remarks>

// https://stackoverflow.com/a/15994225/20894223
var deltaX = point.X - _origin.X;
var deltaY = -(point.Y - _origin.Y); // I reverse the sign, because on the screen the Y axes are reversed with respect to the Cartesian plane.
var rad = System.Math.Atan2(deltaX, deltaY); // radiant
Copy link
Contributor

Choose a reason for hiding this comment

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

"radiant" is "radians" in English

var deltaY = -(point.Y - _origin.Y); // I reverse the sign, because on the screen the Y axes are reversed with respect to the Cartesian plane.
var rad = System.Math.Atan2(deltaX, deltaY); // radiant
var degree = rad * (180 / System.Math.PI);
degree += 90; // Shift angle of 90°
Copy link
Contributor

@robloo robloo Oct 13, 2023

Choose a reason for hiding this comment

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

  1. Why is this +90 degrees done?
  2. I wonder if the angle should be normalized between 0 and 180 degrees. This would remove the directionality of the start/end points. I'm not sure a start and end point even make sense in the context of a pinch. In a pinch how is 300 degrees different from 120 degrees?
    • Edit: It is common for pinch to be used on object directly when interacting with them on screen. In this case you may want to manipulate the object using pinch AND rotate it at the same time. In this context the vector of the pinch event and the full 360deg rotation is important info to have.

Also, I'm assuming WPF's coordinates system for measure degrees:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

90° is wrog, the corrent 180. Atan2 returns a radian value between -π to +π, in degrees -180 to +180. To get the angle between 0 and 360 degrees you need to add 180 degrees.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if the angle should be normalized between 0 and 180 degrees. This would remove the directionality of the start/end points. I'm not sure a start and end point even make sense in the context of a pinch. In a pinch how is 300 degrees different from 120 degrees?

* Edit: It is common for pinch to be used on object directly when interacting with them on screen. In this case you may want to manipulate the object using pinch AND rotate it at the same time. In this context the vector of the pinch event and the full 360deg rotation is important info to have.

Do you suggest adding a Sing or AngleDelta property?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me think about this some more and compare to other platforms:

adding a Sign

Actually, yes, I think is probably a good idea. + is clockwise. - is counterclockwise.

AngleDelta

Yea... that might be useful. I also wonder if we should track (or if it is even possible to track) rotations past 360 degrees. If a user wants to just keep rotating something during a pin/zoom/rotate operation triggered by this gesture it might be useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've been thinking about this more. I realize it is a larger topic. We really are starting to add features that should be in a generic ManipulationStarted/Completed event as in WinUI.

Specifically for the angle delta, ManipulationDelta in WinUI is a generic representation of everything you would want to know about the gesture. We probably should be using that.

I still think Pinch is a useful special-case of the fully generic Manipulation gesture (which doesn't exist yet). But I guess we either 1) should exclude delta in pinch for now or 2) design the manipulation gesture as well so event args and data types can be shared with the pinch gesture.

The most future-proof is to implement ManipulationDelta now within Pinch. Maybe even a ManipulationCompletedEventArgs-similar class.

Looking at other platforms, https://developer.apple.com/documentation/uikit/uirotationgesturerecognizer, I notice the name Rotation as well. This should be the name of the property instead of Angle. It is also what is done in ManipulationDelta and WinUI.

@workgroupengineering workgroupengineering marked this pull request as draft October 13, 2023 16:19
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0040848-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@workgroupengineering workgroupengineering marked this pull request as ready for review October 16, 2023 08:19
@maxkatz6 maxkatz6 requested a review from emmauss October 17, 2023 23:08
@workgroupengineering
Copy link
Contributor Author

@emmauss do I need to make any other changes?

@maxkatz6 maxkatz6 added this pull request to the merge queue Nov 23, 2023
Merged via the queue into AvaloniaUI:master with commit 2852c14 Nov 23, 2023
5 checks passed
@workgroupengineering workgroupengineering deleted the features/Core/Gestures/PinchGesture-Angle branch November 23, 2023 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add AngleDegree and AngleRadiant to PinchEventArgs
5 participants