Skip to content

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

Description

@ulfemsoy

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestion(1) Early API idea and discussion, it is NOT ready for implementationarea-System.DrawingSystem.Drawing issues

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions