oliverbooth / X10D

Extension methods on crack.
https://oliverbooth.github.io/X10D/
MIT License
28 stars 2 forks source link

Vector2/3/4.With* #56

Closed oliverbooth closed 2 years ago

oliverbooth commented 2 years ago

Types

System.Numerics.Vector2
System.Numerics.Vector3
System.Numerics.Vector4
UnityEngine.Vector2
UnityEngine.Vector3
UnityEngine.Vector4

Extension method signatures

Vector2 WithX(float);
Vector2 WithY(float);

Vector3 WithX(float);
Vector3 WithY(float);
Vector3 WithZ(float);

Vector4 WithX(float);
Vector4 WithY(float);
Vector4 WithZ(float);
Vector4 WithW(float);
Parameters Parameter Type Description
x / y / z / w float The new component value.

Description Returns a vector whose components are the same as a given vector, but with one component specified as a new value.

Benefits Provides an easy way to transform a Vector2/3/4 without constructing a new one.

Drawbacks This is already easily achievable using a with expression, since Vector2/3/4 are mutable.

(Optional) Implementation example n/a