-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Point struct scalar multiplication/division operators #8745
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
base: develop
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This pull request introduces scalar multiplication and division operator overloads for the Point struct, along with accompanying XML documentation.
- Added operator* overload to multiply a Point by an integer.
- Added operator/ overload to divide a Point by an integer.
Comments suppressed due to low confidence (1)
MonoGame.Framework/Point.cs:134
- [nitpick] Consider adding an additional overload for int * Point to ensure commutative behavior and consistency with similar operator overloads in related types.
public static Point operator *(Point value, int scaleFactor)
/// <param name="scaleFactor">Scalar value on the right of the div sign.</param> | ||
/// <returns>Result of dividing point by a scalar.</returns> | ||
public static Point operator /(Point value, int scaleFactor) | ||
{ |
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.
Consider adding an explicit check to provide a clear exception message if scaleFactor is zero, rather than relying on the default System.DivideByZeroException.
{ | |
{ | |
if (scaleFactor == 0) | |
throw new ArgumentException("scaleFactor cannot be zero.", nameof(scaleFactor)); |
Copilot uses AI. Check for mistakes.
Care to address the suggestions from our AI Overlords @not-phoeniix so we can get this into the next preview? |
How do we address it? If you can pass on a message though: |
Yeah I assumed since the similar Vector 2/3/4 counterparts don't have this exception throw I'd keep it consistent across all data types and a |
Description of changes:
Point * int
scalar multiplication operator overloadPoint / int
scalar division operator overloadI figured these would prove helpful due to the existence of Vector2/3/4 float scalar operators, preventing unnecessary conversions between Points and Vector2s.