Skip to content

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

not-phoeniix
Copy link

Description of changes:

  • Added Point * int scalar multiplication operator overload
  • Added Point / int scalar division operator overload
  • Added XML documentation for both new overloads

I figured these would prove helpful due to the existence of Vector2/3/4 float scalar operators, preventing unnecessary conversions between Points and Vector2s.

@dellis1972 dellis1972 requested a review from Copilot May 4, 2025 12:49
Copy link

@Copilot Copilot AI left a 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)
{
Copy link
Preview

Copilot AI May 4, 2025

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.

Suggested change
{
{
if (scaleFactor == 0)
throw new ArgumentException("scaleFactor cannot be zero.", nameof(scaleFactor));

Copilot uses AI. Check for mistakes.

@SimonDarksideJ
Copy link
Contributor

Care to address the suggestions from our AI Overlords @not-phoeniix so we can get this into the next preview?

@squarebananas
Copy link
Contributor

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:
"Hello Mr. Bot,
Why are you suggesting a different exception message appears for Point compared to the Vector2 / 3 / 4 counterparts? Humans are generally capable of understanding System.DivideByZeroException means an attempt to divide by zero was made.
Yours Sincerely
Human"

@not-phoeniix
Copy link
Author

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 System.DivideByZeroException error would be sufficient. If y'all think an exception would be better here then let me know and I'll add it but it seems unnecessary if the vectors don't have it either.

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.

3 participants