oliverbooth / X10D

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

[Request]: Vector rounding #65

Closed oliverbooth closed 2 years ago

oliverbooth commented 2 years ago

Type to extend

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

Signature

Vector2 Round([int digits[, MidpointRounding mode]])
Vector3 Round([int digits[, MidpointRounding mode]])
Vector4 Round([int digits[, MidpointRounding mode]])

Summary

Rounds a vector by rounding its single-precision floating-point values, separately, to a specified number of fractional digits using the specified rounding convention.

Parameters

Parameter Type Description
digits float The number of fractional digits in the return value.
mode MidpointRounding One of the enumeration values that specifies which rounding strategy to use.

Benefits

This method used to exist in X10D but was removed for some reason.

Drawbacks

n/a

Implementation Example

value.X = MathF.Round(value.X, digits, mode);
value.Y = MathF.Round(value.Y, digits, mode);
value.Z = MathF.Round(value.Z, digits, mode); // if Vector3/4
value.W = MathF.Round(value.W, digits, mode); // if Vector4
return value;

Code of Conduct

oliverbooth commented 2 years ago

Added with 46bfa17b93839ac0d303dc7660958bd8503361dc