2 public struct Vector4 : IEquatable<Vector4> {
30 public Vector4(
float x,
float y,
float z,
float w) {
51 public static implicit
operator Vector4((
float X,
float Y,
float Z,
float W) v) =>
new(v.X, v.Y, v.Z, v.W);
55 public override int GetHashCode() =>
X.GetHashCode() +
Y.GetHashCode() +
Z.GetHashCode() +
W.GetHashCode();
57 public override string ToString() => $
"{X},{Y},{Z},{W}";
59 public bool Equals(
Vector4 other) =>
X == other.X &&
Y == other.Y &&
Z == other.Z &&
W == other.
W;
66 public static float Dot(
Vector4 v1,
Vector4 v2) => v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z + v1.W * v2.
W;
78 public static Vector4 Min(
Vector4 v,
float f) =>
new(MathF.Min(v.
X, f), MathF.Min(v.
Y, f), MathF.Min(v.
Z, f), MathF.Min(v.
W, f));
81 MathF.Min(v1.
X, v2.
X),
82 MathF.Min(v1.
Y, v2.
Y),
83 MathF.Min(v1.
Z, v2.
Z),
87 public static Vector4 Max(
Vector4 v,
float f) =>
new(MathF.Max(v.
X, f), MathF.Max(v.
Y, f), MathF.Max(v.
Z, f), MathF.Max(v.
W, f));
90 MathF.Max(v1.
X, v2.
X),
91 MathF.Max(v1.
Y, v2.
Y),
92 MathF.Max(v1.
Z, v2.
Z),
97 Math.Clamp(v.
X, min, max),
98 Math.Clamp(v.
Y, min, max),
99 Math.Clamp(v.
Z, min, max),
100 Math.Clamp(v.
W, min, max)
126 return !(num > 0f) ?
UnitX : v / num;
131 return num > maxLength * maxLength ? v * (maxLength / MathF.Sqrt(num)) : v;
135 v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31 + m.
M41,
136 v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32 + m.
M42,
137 v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33 + m.
M43,
138 v.X * m.M14 + v.Y * m.M24 + v.Z * m.M34 + m.M44
143 v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31 + m.M41,
144 v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32 + m.M42,
145 v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33 + m.M43,
146 v.X * m.M14 + v.Y * m.M24 + v.Z * m.M34 + m.M44
154 int destinationIndex,
156 for (
int i = 0; i < count; i++) {
157 Vector4 vector = sourceArray[sourceIndex + i];
158 destinationArray[destinationIndex + i] =
new Vector4(
159 vector.
X * m.M11 + vector.
Y * m.M21 + vector.
Z * m.M31 + m.M41,
160 vector.
X * m.M12 + vector.
Y * m.M22 + vector.
Z * m.M32 + m.M42,
161 vector.
X * m.M13 + vector.
Y * m.M23 + vector.
Z * m.M33 + m.M43,
162 vector.
X * m.M14 + vector.
Y * m.M24 + vector.
Z * m.M34 + m.M44
189 return new Vector4(v.
X * num, v.
Y * num, v.
Z * num, v.
W * num);
193 if (
float.IsNaN(v.
X)) {
196 if (
float.IsNaN(v.
Y)) {
199 if (
float.IsNaN(v.
Z)) {
202 if (
float.IsNaN(v.
W)) {
209 if (
float.IsNaN(
X)) {
212 if (
float.IsNaN(
Y)) {
215 if (
float.IsNaN(
Z)) {
218 if (
float.IsNaN(
W)) {
225 fixed (
float* ptr = &
X) {
226 return new Span<float>(ptr, 4);
231 fixed (
float* ptr = &
X) {
static float Saturate(float x)
static float CatmullRom(float v1, float v2, float v3, float v4, float f)
static float Lerp(float x1, float x2, float f)
static Vector4 operator+(Vector4 v)
static Vector4 Max(Vector4 v1, Vector4 v2)
static Vector4 Round(Vector4 v)
static readonly Vector4 UnitW
static bool operator==(Vector4 v1, Vector4 v2)
static bool operator!=(Vector4 v1, Vector4 v2)
static Vector4 CatmullRom(Vector4 v1, Vector4 v2, Vector4 v3, Vector4 v4, float f)
static void Transform(ref Vector4 v, ref Matrix m, out Vector4 result)
static Vector4 FixNaN(Vector4 v)
static readonly Vector4 One
static Vector4 Lerp(Vector4 v1, Vector4 v2, float f)
unsafe Span< float > AsSpan()
static Vector4 LimitLength(Vector4 v, float maxLength)
static void Transform(Vector4[] sourceArray, int sourceIndex, ref Matrix m, Vector4[] destinationArray, int destinationIndex, int count)
static Vector4 Max(Vector4 v, float f)
static readonly Vector4 UnitZ
static Vector4 operator/(Vector4 v1, Vector4 v2)
static float Dot(Vector4 v1, Vector4 v2)
Vector4(float x, float y, float z, float w)
static Vector4 Floor(Vector4 v)
override string ToString()
bool Equals(Vector4 other)
static Vector4 Saturate(Vector4 v)
static float DistanceSquared(Vector4 v1, Vector4 v2)
static Vector4 operator*(Vector4 v1, Vector4 v2)
static Vector4 operator-(Vector4 v)
static Vector4 Transform(Vector4 v, Matrix m)
static Vector4 Ceiling(Vector4 v)
override bool Equals(object obj)
static readonly Vector4 UnitX
static readonly Vector4 Zero
static Vector4 Min(Vector4 v, float f)
override int GetHashCode()
Vector4(Vector3 xyz, float w)
static readonly Vector4 UnitY
static Vector4 Normalize(Vector4 v)
unsafe float * AsPointer()
static float Distance(Vector4 v1, Vector4 v2)
static Vector4 Clamp(Vector4 v, float min, float max)
static Vector4 Min(Vector4 v1, Vector4 v2)