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

Point, PointF, Size and SizeF: Unary minus operator #11860

Open
ulfemsoy opened this issue Aug 12, 2024 · 5 comments
Open

Point, PointF, Size and SizeF: Unary minus operator #11860

ulfemsoy opened this issue Aug 12, 2024 · 5 comments
Labels
api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation area-System.Drawing System.Drawing issues
Milestone

Comments

@ulfemsoy
Copy link

ulfemsoy commented Aug 12, 2024

Background and motivation

I propose to add a unary minus operator to the Point, PointF, Size and SizeF structs. It is to improve readability during drawing operations.

API Proposal

namespace System.Drawing;

public struct Point
{
public static Point operator -(Point value) { return new Point(-value.X, -value.Y); }
}

public struct PointF
{
public static PointF operator -(PointF value) { return new PointF(-value.X, -value.Y); }
}

public struct Size
{
public static Size operator -(Size value) { return new Size(-value.Width, -value.Height); }
}

public struct SizeF
{
public static SizeF operator -(SizeF value) { return new SizeF(-value.Width, -value.Height); }
}

API Usage

// Translate
 graphics.TranslateTransform(
     pntLocation
 );

// Reverse translate
graphics.TranslateTransform(
     -pntLocation
 );

Alternative Designs

No response

Risks

No response

Will this feature affect UI controls?

No impact on UI controls.

@ulfemsoy ulfemsoy added api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation untriaged The team needs to look at this issue in the next triage labels Aug 12, 2024
@JeremyKuhne
Copy link
Member

Seems like a reasonable request. If we do this, it should be done for all Point and Size types. I don't think it makes sense for Rectangle.

@JeremyKuhne
Copy link
Member

@ulfemsoy would you mind updating the proposal to add both point and size types?

@JeremyKuhne JeremyKuhne added this to the .NET 10.0 milestone Aug 12, 2024
@JeremyKuhne JeremyKuhne added waiting-author-feedback The team requires more information from the author and removed untriaged The team needs to look at this issue in the next triage labels Aug 12, 2024
@ulfemsoy ulfemsoy changed the title PointF: Unary minus operator Point, PointF, Size and SizeF: Unary minus operator Aug 13, 2024
@JeremyKuhne JeremyKuhne removed the waiting-author-feedback The team requires more information from the author label Aug 13, 2024
@elachlan elachlan added the area-System.Drawing System.Drawing issues label Aug 14, 2024
@teo-tsirpanis
Copy link
Contributor

I think this should be moved to dotnet/runtime, that's where the source code for these types is.

@elachlan
Copy link
Contributor

elachlan commented Mar 6, 2025

@merriemcgaw apparently this should be moved to runtime?

@JeremyKuhne
Copy link
Member

@teo-tsirpanis, @elachlan we're keeping all System.Drawing issues here as our team owns the full namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation area-System.Drawing System.Drawing issues
Projects
None yet
Development

No branches or pull requests

4 participants