mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Fixed vector indexed access
This commit is contained in:
@@ -29,6 +29,21 @@ namespace GlitchyEngine.Math
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ref float this[int index]
|
public ref float this[int index]
|
||||||
|
{
|
||||||
|
[Checked]
|
||||||
|
get mut
|
||||||
|
{
|
||||||
|
if(index < 0 || index >= Length)
|
||||||
|
Internal.ThrowIndexOutOfRange(1);
|
||||||
|
|
||||||
|
return ref (&X)[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
get mut => ref (&X)[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public float this[int index]
|
||||||
{
|
{
|
||||||
[Checked]
|
[Checked]
|
||||||
get
|
get
|
||||||
@@ -36,13 +51,41 @@ namespace GlitchyEngine.Math
|
|||||||
if(index < 0 || index >= Length)
|
if(index < 0 || index >= Length)
|
||||||
Internal.ThrowIndexOutOfRange(1);
|
Internal.ThrowIndexOutOfRange(1);
|
||||||
|
|
||||||
#unwarn
|
if(index == 0)
|
||||||
return ref (&X)[index];
|
return X;
|
||||||
|
else
|
||||||
|
return Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
#unwarn
|
get
|
||||||
get => ref (&X)[index];
|
{
|
||||||
|
if(index == 0)
|
||||||
|
return X;
|
||||||
|
else
|
||||||
|
return Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Checked]
|
||||||
|
set mut
|
||||||
|
{
|
||||||
|
if(index < 0 || index >= Length)
|
||||||
|
Internal.ThrowIndexOutOfRange(1);
|
||||||
|
|
||||||
|
if(index == 0)
|
||||||
|
X = value;
|
||||||
|
else
|
||||||
|
Y = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
set mut
|
||||||
|
{
|
||||||
|
if(index == 0)
|
||||||
|
X = value;
|
||||||
|
else
|
||||||
|
Y = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace GlitchyEngine.Math
|
|||||||
public const Vector3 Up = .(0f, 1f, 0f);
|
public const Vector3 Up = .(0f, 1f, 0f);
|
||||||
public const Vector3 Down = .(0f, -1f, 0f);
|
public const Vector3 Down = .(0f, -1f, 0f);
|
||||||
|
|
||||||
|
public const int Length = 3;
|
||||||
|
|
||||||
public float X, Y, Z;
|
public float X, Y, Z;
|
||||||
|
|
||||||
public this() => this = default;
|
public this() => this = default;
|
||||||
@@ -46,18 +48,41 @@ namespace GlitchyEngine.Math
|
|||||||
public ref float this[int index]
|
public ref float this[int index]
|
||||||
{
|
{
|
||||||
[Checked]
|
[Checked]
|
||||||
get
|
get mut
|
||||||
{
|
{
|
||||||
if(index < 0 || index > 2)
|
if(index < 0 || index >= Length)
|
||||||
Internal.ThrowIndexOutOfRange();
|
Internal.ThrowIndexOutOfRange(1);
|
||||||
|
|
||||||
#unwarn
|
|
||||||
return ref (&X)[index];
|
return ref (&X)[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
#unwarn
|
get mut => ref (&X)[index];
|
||||||
get => ref (&X)[index];
|
}
|
||||||
|
|
||||||
|
public float this[int index]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
switch(index)
|
||||||
|
{
|
||||||
|
case 0: return X;
|
||||||
|
case 1: return Y;
|
||||||
|
case 2: return Z;
|
||||||
|
default: Internal.ThrowIndexOutOfRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set mut
|
||||||
|
{
|
||||||
|
switch(index)
|
||||||
|
{
|
||||||
|
case 0: X = value;
|
||||||
|
case 1: Y = value;
|
||||||
|
case 2: Z = value;
|
||||||
|
default: Internal.ThrowIndexOutOfRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace GlitchyEngine.Math
|
|||||||
public const Vector4 UnitW = .(0f, 0f, 0f, 1f);
|
public const Vector4 UnitW = .(0f, 0f, 0f, 1f);
|
||||||
public const Vector4 One = .(1f, 1f, 1f, 1f);
|
public const Vector4 One = .(1f, 1f, 1f, 1f);
|
||||||
|
|
||||||
|
public const int Length = 4;
|
||||||
|
|
||||||
public float X, Y, Z, W;
|
public float X, Y, Z, W;
|
||||||
|
|
||||||
public this() => this = default;
|
public this() => this = default;
|
||||||
@@ -59,17 +61,43 @@ namespace GlitchyEngine.Math
|
|||||||
public ref float this[int index]
|
public ref float this[int index]
|
||||||
{
|
{
|
||||||
[Checked]
|
[Checked]
|
||||||
get
|
get mut
|
||||||
{
|
{
|
||||||
if(index < 0 || index > 3)
|
if(index < 0 || index >= Length)
|
||||||
Internal.ThrowIndexOutOfRange();
|
Internal.ThrowIndexOutOfRange(1);
|
||||||
#unwarn
|
|
||||||
return ref (&X)[index];
|
return ref (&X)[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
#unwarn
|
get mut => ref (&X)[index];
|
||||||
get => ref (&X)[index];
|
}
|
||||||
|
|
||||||
|
public float this[int index]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
switch(index)
|
||||||
|
{
|
||||||
|
case 0: return X;
|
||||||
|
case 1: return Y;
|
||||||
|
case 2: return Z;
|
||||||
|
case 3: return W;
|
||||||
|
default: Internal.ThrowIndexOutOfRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set mut
|
||||||
|
{
|
||||||
|
switch(index)
|
||||||
|
{
|
||||||
|
case 0: X = value;
|
||||||
|
case 1: Y = value;
|
||||||
|
case 2: Z = value;
|
||||||
|
case 3: W = value;
|
||||||
|
default: Internal.ThrowIndexOutOfRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user