Files
RebootKit/Runtime/Engine/Code/Extensions/Vector3Ex.cs
2025-03-30 16:06:57 +02:00

36 lines
1.4 KiB
C#

using System.Runtime.CompilerServices;
using Unity.Mathematics;
using UnityEngine;
namespace RebootKit.Engine.Extensions {
public static class Vector3Ex {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 With(this Vector3 vec, float? x = null, float? y = null, float? z = null) {
return new Vector3(x ?? vec.x,
y ?? vec.y,
z ?? vec.z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsZero(this Vector3 vec, float epsilon = float.Epsilon) {
return math.abs(vec.x) < epsilon && math.abs(vec.y) < epsilon && math.abs(vec.z) < epsilon;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNonZero(this Vector3 vec, float epsilon = float.Epsilon) {
return !vec.IsZero(epsilon);
}
}
public static class float3Ex {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsZero(this float3 vec, float epsilon = float.Epsilon) {
return math.abs(vec.x) < epsilon && math.abs(vec.y) < epsilon && math.abs(vec.z) < epsilon;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNonZero(this float3 vec, float epsilon = float.Epsilon) {
return !vec.IsZero(epsilon);
}
}
}