mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.17k stars 522 forks source link

[FEATURE] Implicit conversions between ValueTuples and SKPoint #2862

Open OJacot-Descombes opened 2 weeks ago

OJacot-Descombes commented 2 weeks ago

Is your feature request related to a problem?

I would like to be able to specify points in an easier way.

Describe the solution you would like

Therefore, I suggest adding an implicit conversion between a ValueTuple and a SKPoint as well as a deconstructor:

// In struct SKPoint

public static implicit operator SKPoint((float x, float y) tuple) => new SKPoint(tuple.x, tuple.y);

public void Deconstruct(out float x, out float y) => (x = X, y = Y);

This would allow us to define a point as SKPoint point = (x, y); instead of SKPoint point = new SKPoint(x, y);.

The inverse would also be possible: var (x, y) = point;.

Describe alternatives you have considered

It is currently (C#12) not possible to declare operators as extension methods.

Additional context

No response

Code of Conduct