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

add implicit convert operator for all variants of size struct #1540

Merged
merged 5 commits into from
Mar 9, 2023

Conversation

n0099
Copy link
Contributor

@n0099 n0099 commented Mar 7, 2023

No description provided.

@@ -73,22 +73,32 @@ public Size(double width, double height)
return !lhs.Equals(rhs);
}

public static implicit operator Size(Size2d size)
{
return new(size.Width, size.Height);
Copy link
Owner

Choose a reason for hiding this comment

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

I think Size -> Size2d is OK, but Size2d -> Size should be marked as explicit. This is because there is no implicit conversion from double to int in the case of scalar values. (For example, double d = 1; is OK but int i = 1.23; causes an error.)

public static explicit operator Point(Point2d self) => new((int) self.X, (int) self.Y);

n0099 and others added 2 commits March 8, 2023 18:54
Co-authored-by: shimat <schimatk@gmail.com>
Co-authored-by: shimat <schimatk@gmail.com>
@shimat shimat merged commit a14400b into shimat:master Mar 9, 2023
@shimat
Copy link
Owner

shimat commented Mar 9, 2023

Thank you 👍

@n0099 n0099 deleted the master branch June 5, 2023 07:43
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.

2 participants