Skip to content

Commit 9403918

Browse files
committed
IVectorMath.Zero
1 parent 114f721 commit 9403918

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Runtime/Numerics/IVectorMath.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static bool TryIntersectSphereAtOrigin<V, VM>( this VM vm, V o, V n, floa
6666

6767
public interface IVectorMath<V> {
6868
const MethodImplOptions INLINE = MethodImplOptions.AggressiveInlining;
69+
[MethodImpl( INLINE )] V Zero();
6970
[MethodImpl( INLINE )] V Add( V a, V b );
7071
[MethodImpl( INLINE )] V Sub( V a, V b );
7172
[MethodImpl( INLINE )] V Mul( V v, float c );
@@ -80,6 +81,7 @@ public interface IVectorMath<V> {
8081

8182
public struct VectorMath1D : IVectorMath<float> {
8283
const MethodImplOptions INLINE = MethodImplOptions.AggressiveInlining;
84+
[MethodImpl( INLINE )] public float Zero() => 0;
8385
[MethodImpl( INLINE )] public float Add( float a, float b ) => a + b;
8486
[MethodImpl( INLINE )] public float Sub( float a, float b ) => a - b;
8587
[MethodImpl( INLINE )] public float Mul( float v, float c ) => v * c;
@@ -95,6 +97,7 @@ public struct VectorMath1D : IVectorMath<float> {
9597

9698
public struct VectorMath2D : IVectorMath<Vector2> {
9799
const MethodImplOptions INLINE = MethodImplOptions.AggressiveInlining;
100+
[MethodImpl( INLINE )] public Vector2 Zero() => new(0, 0);
98101
[MethodImpl( INLINE )] public Vector2 Add( Vector2 a, Vector2 b ) => new(a.x + b.x, a.y + b.y);
99102
[MethodImpl( INLINE )] public Vector2 Sub( Vector2 a, Vector2 b ) => new(a.x - b.x, a.y - b.y);
100103
[MethodImpl( INLINE )] public Vector2 Mul( Vector2 v, float c ) => new(v.x * c, v.y * c);
@@ -115,6 +118,7 @@ public struct VectorMath2D : IVectorMath<Vector2> {
115118

116119
public struct VectorMath3D : IVectorMath<Vector3> {
117120
const MethodImplOptions INLINE = MethodImplOptions.AggressiveInlining;
121+
[MethodImpl( INLINE )] public Vector3 Zero() => new(0, 0, 0);
118122
[MethodImpl( INLINE )] public Vector3 Add( Vector3 a, Vector3 b ) => new(a.x + b.x, a.y + b.y, a.z + b.z);
119123
[MethodImpl( INLINE )] public Vector3 Sub( Vector3 a, Vector3 b ) => new(a.x - b.x, a.y - b.y, a.z - b.z);
120124
[MethodImpl( INLINE )] public Vector3 Mul( Vector3 v, float c ) => new(v.x * c, v.y * c, v.z * c);
@@ -134,6 +138,7 @@ public struct VectorMath3D : IVectorMath<Vector3> {
134138

135139
public struct VectorMath4D : IVectorMath<Vector4> {
136140
const MethodImplOptions INLINE = MethodImplOptions.AggressiveInlining;
141+
[MethodImpl( INLINE )] public Vector4 Zero() => new(0, 0, 0, 0);
137142
[MethodImpl( INLINE )] public Vector4 Add( Vector4 a, Vector4 b ) => new(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
138143
[MethodImpl( INLINE )] public Vector4 Sub( Vector4 a, Vector4 b ) => new(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
139144
[MethodImpl( INLINE )] public Vector4 Mul( Vector4 v, float c ) => new(v.x * c, v.y * c, v.z * c, v.w * c);
@@ -154,6 +159,7 @@ public struct VectorMath4D : IVectorMath<Vector4> {
154159
// todo: quaternions, as a treat. this is untested and unported basically lol
155160
public struct VectorMathQuat : IVectorMath<Quaternion> {
156161
const MethodImplOptions INLINE = MethodImplOptions.AggressiveInlining;
162+
[MethodImpl( INLINE )] public Quaternion Zero() => new(0, 0, 0, 0);
157163
[MethodImpl( INLINE )] public Quaternion Add( Quaternion a, Quaternion b ) => new(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
158164
[MethodImpl( INLINE )] public Quaternion Sub( Quaternion a, Quaternion b ) => new(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
159165
[MethodImpl( INLINE )] public Quaternion Mul( Quaternion v, float c ) => new(v.x * c, v.y * c, v.z * c, v.w * c);

0 commit comments

Comments
 (0)