diff --git a/Hypercube.Client/Graphics/Vertex.cs b/Hypercube.Client/Graphics/Vertex.cs index 62523b4..9ba010f 100644 --- a/Hypercube.Client/Graphics/Vertex.cs +++ b/Hypercube.Client/Graphics/Vertex.cs @@ -12,8 +12,8 @@ public readonly struct Vertex private static readonly Color DefaultColor = Color.White; public readonly Vector3 Position; - public readonly Vector2 UVCoords; public readonly Color Color; + public readonly Vector2 UVCoords; public Vertex(Vector3 position, Vector2 uvCoords, Color color) { diff --git a/Hypercube.Shared.Math/Color.cs b/Hypercube.Shared.Math/Color.cs index a926016..6ecd9ee 100644 --- a/Hypercube.Shared.Math/Color.cs +++ b/Hypercube.Shared.Math/Color.cs @@ -1,8 +1,10 @@ using System.Globalization; +using System.Runtime.InteropServices; using Hypercube.Shared.Math.Vector; namespace Hypercube.Shared.Math; +[StructLayout(LayoutKind.Sequential)] public readonly struct Color { public static readonly Color White = new(1f, 1f, 1f); diff --git a/Hypercube.Shared.Math/Matrix/Matrix3X3.cs b/Hypercube.Shared.Math/Matrix/Matrix3X3.cs index d2a7c36..4c6cbb1 100644 --- a/Hypercube.Shared.Math/Matrix/Matrix3X3.cs +++ b/Hypercube.Shared.Math/Matrix/Matrix3X3.cs @@ -1,8 +1,10 @@ using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Hypercube.Shared.Math.Vector; namespace Hypercube.Shared.Math.Matrix; +[StructLayout(LayoutKind.Sequential)] public struct Matrix3X3(Vector3 x, Vector3 y, Vector3 z) { private const int IndexRaw0 = 0; diff --git a/Hypercube.Shared.Math/Matrix/Matrix4X4.cs b/Hypercube.Shared.Math/Matrix/Matrix4X4.cs index aa924d7..95ca417 100644 --- a/Hypercube.Shared.Math/Matrix/Matrix4X4.cs +++ b/Hypercube.Shared.Math/Matrix/Matrix4X4.cs @@ -1,9 +1,11 @@ using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Hypercube.Shared.Math.Box; using Hypercube.Shared.Math.Vector; namespace Hypercube.Shared.Math.Matrix; +[StructLayout(LayoutKind.Sequential)] public partial struct Matrix4X4(Vector4 x, Vector4 y, Vector4 z, Vector4 w) : IEquatable { public static Matrix4X4 Zero => new(Vector4.Zero); diff --git a/Hypercube.Shared.Math/Vector/Vector2.cs b/Hypercube.Shared.Math/Vector/Vector2.cs index 61b3cf9..8ce7e98 100644 --- a/Hypercube.Shared.Math/Vector/Vector2.cs +++ b/Hypercube.Shared.Math/Vector/Vector2.cs @@ -1,7 +1,9 @@ using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Hypercube.Shared.Math.Vector; +[StructLayout(LayoutKind.Sequential)] public readonly partial struct Vector2(float x, float y) : IEquatable { public static readonly Vector2 Zero = new(0, 0); diff --git a/Hypercube.Shared.Math/Vector/Vector2Int.cs b/Hypercube.Shared.Math/Vector/Vector2Int.cs index 63aaf8e..c61fba7 100644 --- a/Hypercube.Shared.Math/Vector/Vector2Int.cs +++ b/Hypercube.Shared.Math/Vector/Vector2Int.cs @@ -1,5 +1,8 @@ -namespace Hypercube.Shared.Math.Vector; +using System.Runtime.InteropServices; +namespace Hypercube.Shared.Math.Vector; + +[StructLayout(LayoutKind.Sequential)] public readonly partial struct Vector2Int(int x, int y) { public static readonly Vector2Int Zero = new(0, 0); @@ -11,7 +14,8 @@ public readonly partial struct Vector2Int(int x, int y) public readonly int X = x; public readonly int Y = y; - public readonly float Ratio = x / (float)y; + + public float Ratio => x / (float)y; public static Vector2Int operator +(Vector2Int a, Vector2Int b) { diff --git a/Hypercube.Shared.Math/Vector/Vector3.cs b/Hypercube.Shared.Math/Vector/Vector3.cs index 07a5342..b6912a5 100644 --- a/Hypercube.Shared.Math/Vector/Vector3.cs +++ b/Hypercube.Shared.Math/Vector/Vector3.cs @@ -1,7 +1,9 @@ using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Hypercube.Shared.Math.Vector; +[StructLayout(LayoutKind.Sequential)] public readonly partial struct Vector3(float x, float y, float z) { public static readonly Vector3 Zero = new(0, 0, 0); @@ -20,9 +22,18 @@ public readonly partial struct Vector3(float x, float y, float z) public readonly float Y = y; public readonly float Z = z; - public float Length => (float)System.Math.Sqrt(X * X + Y * Y + Z * Z); - public Vector3 Normalized => this / Length; - + public float Length + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => MathF.Sqrt(X * X + Y * Y + Z * Z); + } + + public Vector3 Normalized + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => this / Length; + } + public Vector3(float value) : this(value, value, value) { } diff --git a/Hypercube.Shared.Math/Vector/Vector4.cs b/Hypercube.Shared.Math/Vector/Vector4.cs index 00f154f..2f1b43b 100644 --- a/Hypercube.Shared.Math/Vector/Vector4.cs +++ b/Hypercube.Shared.Math/Vector/Vector4.cs @@ -1,8 +1,10 @@ using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Hypercube.Shared.Math.Extensions; namespace Hypercube.Shared.Math.Vector; +[StructLayout(LayoutKind.Sequential)] public readonly partial struct Vector4(float x, float y, float z, float w) : IEquatable { public static readonly Vector4 Zero = new(0, 0, 0, 0);