diff --git a/ScriptCore/Math/Attributes/VectorAttribute.cs b/ScriptCore/Math/Attributes/VectorAttribute.cs
index aad8bbc..c7cb303 100644
--- a/ScriptCore/Math/Attributes/VectorAttribute.cs
+++ b/ScriptCore/Math/Attributes/VectorAttribute.cs
@@ -1,17 +1,33 @@
using System;
-using System.Collections.Generic;
-using System.Text;
namespace GlitchyEngine.Math.Attributes;
+///
+/// Generates fields for the components of a vector as well as basic methods like constructors, type casts and equality checks.
+///
[AttributeUsage(AttributeTargets.Struct)]
public class VectorAttribute : Attribute
{
+ ///
+ /// The Type of the vectors components.
+ ///
public Type Type { get; set; }
+ ///
+ /// Number of components in the vectors (valid values are in the range of 2 to 4).
+ ///
public int ComponentCount { get; set; }
+ ///
+ /// The base name of the vector.
+ ///
public string TypeBase { get; set; }
+ ///
+ /// Creates a new instance of the class.
+ ///
+ ///
+ ///
+ ///
public VectorAttribute(Type type, int componentCount, string typeBase)
{
Type = type;
@@ -20,20 +36,45 @@ public class VectorAttribute : Attribute
}
}
+///
+/// Generates comparison operators (>, <, >= and <=) for the vectors type.
+///
[AttributeUsage(AttributeTargets.Struct)]
public class ComparableVectorAttribute : Attribute { }
+
+///
+/// Generates component wise math operators (+, -, *, / and %) for the vectors type.
+///
[AttributeUsage(AttributeTargets.Struct)]
public class VectorMathAttribute : Attribute { }
+
+///
+/// Generates component wise logic operators (&, ^ and |) for the vectors type.
+///
[AttributeUsage(AttributeTargets.Struct)]
public class VectorLogicAttribute : Attribute { }
+///
+/// Generates a cast cast from the vector type to the specified target type.
+///
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)]
public class VectorCastAttribute : Attribute
{
+ ///
+ /// The type of the target vector type.
+ ///
public Type TargetType { get; set; }
+ ///
+ /// If the cast will be explicit; if it will an implicit cast.
+ ///
public bool IsExplicit { get; set; }
+ ///
+ /// Creates a new instance of the class.
+ ///
+ ///
+ ///
public VectorCastAttribute(Type targetType, bool isExplicit)
{
TargetType = targetType;
diff --git a/ScriptCore/Math/BoolVectors.cs b/ScriptCore/Math/BoolVectors.cs
index 6572c51..ee4b4a7 100644
--- a/ScriptCore/Math/BoolVectors.cs
+++ b/ScriptCore/Math/BoolVectors.cs
@@ -4,6 +4,9 @@ using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
+///
+/// Represents a vector with two boolean values.
+///
[Vector(typeof(bool), 2, "bool")]
[VectorLogic]
public partial struct bool2
@@ -14,6 +17,9 @@ public partial struct bool2
}
}
+///
+/// Represents a vector with three boolean values.
+///
[Vector(typeof(bool), 3, "bool")]
[VectorLogic]
public partial struct bool3
@@ -24,6 +30,9 @@ public partial struct bool3
}
}
+///
+/// Represents a vector with four boolean values.
+///
[Vector(typeof(bool), 4, "bool")]
[VectorLogic]
public partial struct bool4
diff --git a/ScriptCore/Math/ColorRGBA.cs b/ScriptCore/Math/ColorRGBA.cs
index f837fd7..7e0d279 100644
--- a/ScriptCore/Math/ColorRGBA.cs
+++ b/ScriptCore/Math/ColorRGBA.cs
@@ -57,9 +57,13 @@ public struct ColorRGBA
public static explicit operator float4(ColorRGBA color) => new float4(color.R, color.G, color.B, color.A);
public static explicit operator ColorRGBA(float4 vector) => new ColorRGBA(vector.X, vector.Y, vector.Z, vector.W);
- // Converts a Color from sRGB color space to Linear color space.
+ ///
+ /// Converts a Color from sRGB color space to Linear color space.
+ ///
public static ColorRGBA SRgbToLinear(ColorRGBA sRGB) => new ColorRGBA(pow(sRGB.R, SrgbToLin), pow(sRGB.G, SrgbToLin), pow(sRGB.B, SrgbToLin), sRGB.A);
- // Converts a Color from linear color space to sRGB color space.
+ ///
+ /// Converts a Color from linear color space to sRGB color space.
+ ///
public static ColorRGBA LinearToSRGB(ColorRGBA linear) => new ColorRGBA(pow(linear.R, LinToSRGB), pow(linear.G, LinToSRGB), pow(linear.B, LinToSRGB), linear.A);
}
diff --git a/ScriptCore/Math/DoubleVectors.cs b/ScriptCore/Math/DoubleVectors.cs
index 800dc7f..0a397e3 100644
--- a/ScriptCore/Math/DoubleVectors.cs
+++ b/ScriptCore/Math/DoubleVectors.cs
@@ -4,6 +4,9 @@ using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
+///
+/// Represents a vector with two double-precision floating-point values.
+///
[Vector(typeof(double), 2, "double")]
[VectorMath]
[ComparableVector]
@@ -12,6 +15,9 @@ public partial struct double2
{
}
+///
+/// Represents a vector with three double-precision floating-point values.
+///
[Vector(typeof(double), 3, "double")]
[VectorMath]
[ComparableVector]
@@ -20,6 +26,9 @@ public partial struct double3
{
}
+///
+/// Represents a vector with four double-precision floating-point values.
+///
[Vector(typeof(double), 4, "double")]
[VectorMath]
[ComparableVector]
diff --git a/ScriptCore/Math/FloatVectors.cs b/ScriptCore/Math/FloatVectors.cs
index 2dd8c9d..42a12be 100644
--- a/ScriptCore/Math/FloatVectors.cs
+++ b/ScriptCore/Math/FloatVectors.cs
@@ -8,6 +8,9 @@ using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
+///
+/// Represents a vector with two single-precision floating-point values.
+///
[Vector(typeof(float), 2, "float")]
[ComparableVector]
[VectorMath]
@@ -16,15 +19,30 @@ namespace GlitchyEngine.Math;
[VectorCast(typeof(half2), true)]
public partial struct float2
{
+ ///
+ /// A vector whose elements are all equal to zero.
+ ///
public static readonly float2 Zero = new(0.0f, 0.0f);
+ ///
+ /// The vector (1, 0).
+ ///
public static readonly float2 UnitX = new(1.0f, 0.0f);
+ ///
+ /// The vector (0, 1).
+ ///
public static readonly float2 UnitY = new(0.0f, 1.0f);
+ ///
+ /// A vector whose elements are all equal to one.
+ ///
public static readonly float2 One = new(0.0f, 0.0f);
public static explicit operator Vector2(float2 self) => new(self.X, self.Y);
public static explicit operator float2(Vector2 self) => new(self.X, self.Y);
}
+///
+/// Represents a vector with three single-precision floating-point values.
+///
[Vector(typeof(float), 3, "float")]
[ComparableVector]
[VectorMath]
@@ -33,23 +51,59 @@ public partial struct float2
[VectorCast(typeof(half3), true)]
public partial struct float3
{
+ ///
+ /// A vector whose elements are all equal to zero.
+ ///
public static readonly float3 Zero = new(0.0f, 0.0f, 0.0f);
+ ///
+ /// The vector (1, 0, 0).
+ ///
public static readonly float3 UnitX = new(1.0f, 0.0f, 0.0f);
+ ///
+ /// The vector (0, 1, 0).
+ ///
public static readonly float3 UnitY = new(0.0f, 1.0f, 0.0f);
+ ///
+ /// The vector (0, 0, 1).
+ ///
public static readonly float3 UnitZ = new(0.0f, 0.0f, 1.0f);
+ ///
+ /// A vector whose elements are all equal to one.
+ ///
public static readonly float3 One = new(0.0f, 0.0f, 0.0f);
+ ///
+ /// The vector (0, 0, 1).
+ ///
public static readonly float3 Forward = new(0.0f, 0.0f, 1.0f);
+ ///
+ /// The vector (0, 0, -1).
+ ///
public static readonly float3 Backward = new(0.0f, 0.0f, -1.0f);
+ ///
+ /// The vector (-1, 0, 0).
+ ///
public static readonly float3 Left = new(-1.0f, 0.0f, 0.0f);
+ ///
+ /// The vector (1, 0, 0).
+ ///
public static readonly float3 Right = new(1.0f, 0.0f, 0.0f);
+ ///
+ /// The vector (0, 1, 0).
+ ///
public static readonly float3 Up = new(0.0f, 1.0f, 0.0f);
+ ///
+ /// The vector (0, -1, 0).
+ ///
public static readonly float3 Down = new(0.0f, -1.0f, 0.0f);
public static explicit operator Vector3(float3 self) => new(self.X, self.Y, self.Z);
public static explicit operator float3(Vector3 self) => new(self.X, self.Y, self.Z);
}
+///
+/// Represents a vector with four single-precision floating-point values.
+///
[Vector(typeof(float), 4, "float")]
[ComparableVector]
[VectorMath]
@@ -58,11 +112,29 @@ public partial struct float3
[VectorCast(typeof(half4), true)]
public partial struct float4
{
+ ///
+ /// A vector whose elements are all equal to zero.
+ ///
public static readonly float4 Zero = new(0f, 0f, 0f, 0f);
+ ///
+ /// The vector (1, 0, 0, 0).
+ ///
public static readonly float4 UnitX = new(1f, 0f, 0f, 0f);
+ ///
+ /// The vector (0, 1, 0, 0).
+ ///
public static readonly float4 UnitY = new(0f, 1f, 0f, 0f);
+ ///
+ /// The vector (0, 0, 1, 0).
+ ///
public static readonly float4 UnitZ = new(0f, 0f, 1f, 0f);
+ ///
+ /// The vector (0, 0, 0, 1).
+ ///
public static readonly float4 UnitW = new(0f, 0f, 0f, 1f);
+ ///
+ /// A vector whose elements are all equal to one.
+ ///
public static readonly float4 One = new(1f, 1f, 1f, 1f);
public static explicit operator Vector4(float4 self) => new(self.X, self.Y, self.Z, self.W);
diff --git a/ScriptCore/Math/Half.cs b/ScriptCore/Math/Half.cs
index 1643696..3fb5586 100644
--- a/ScriptCore/Math/Half.cs
+++ b/ScriptCore/Math/Half.cs
@@ -4,18 +4,19 @@ using System.Runtime.CompilerServices;
namespace GlitchyEngine.Math;
///
-/// Represents a 16-bit floating point number. (IEEE 754 half-precision binary floating-point (binary16))
+/// Represents a 16-bit (half-precision) floating point number. (aka. IEEE 754 half-precision binary floating-point (binary16))
///
///
-/// Even though it is possible, it's not recommended to perform calculations using this type directly, because most operators will simply cast the operands to and cast the result back to .
+/// Even though it is possible, it's not recommended to perform large calculations using this type directly because most operators will simply cast the operands to and cast the result back to .
+/// If you need to do larger calculations consider casting to once and cast the result back to afterwards. This will not only have better performance, but will also increase the accuracy of the result.
///
public struct Half : IComparable , IComparable, IConvertible, IEquatable, IFormattable
{
public static readonly Half MinValue = new(-65504); // Should be 0xFBFF
public static readonly Half MaxValue = new(65504); // Should be 0x7BFF
- // The numbers for Inifnity, NaN and Zero need to be hardcoded as binaries,
- // because the conversion intself relies on them.
+ // The numbers for Infinity, NaN and Zero need to be hardcoded as binaries,
+ // because the conversion itself relies on them.
public static readonly Half PositiveInfinity = new(0x7C00);
public static readonly Half NegativeInfinity = new(0xFC00);
diff --git a/ScriptCore/Math/HalfVectors.cs b/ScriptCore/Math/HalfVectors.cs
index 47ca32e..741063e 100644
--- a/ScriptCore/Math/HalfVectors.cs
+++ b/ScriptCore/Math/HalfVectors.cs
@@ -3,19 +3,37 @@ using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
+///
+/// Represents a vector with two half-precision floating-point values.
+///
+///
[Vector(typeof(Half), 2, "half")]
+[VectorMath]
+[ComparableVector]
[VectorCast(typeof(float2), true)]
public partial struct half2
{
}
+///
+/// Represents a vector with three half-precision floating-point values.
+///
+///
[Vector(typeof(Half), 3, "half")]
+[VectorMath]
+[ComparableVector]
[VectorCast(typeof(float3), true)]
public partial struct half3
{
}
+///
+/// Represents a vector with four half-precision floating-point values.
+///
+///
[Vector(typeof(Half), 4, "half")]
+[VectorMath]
+[ComparableVector]
[VectorCast(typeof(float4), true)]
public partial struct half4
{
diff --git a/ScriptCore/Math/IntVectors.cs b/ScriptCore/Math/IntVectors.cs
index 983a142..9efac3b 100644
--- a/ScriptCore/Math/IntVectors.cs
+++ b/ScriptCore/Math/IntVectors.cs
@@ -4,6 +4,9 @@ using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
+///
+/// Represents a vector with two 32-bit signed integer values.
+///
[Vector(typeof(int), 2, "int")]
[VectorMath]
[VectorLogic]
@@ -18,6 +21,9 @@ public partial struct int2
}
}
+///
+/// Represents a vector with three 32-bit signed integer values.
+///
[Vector(typeof(int), 3, "int")]
[VectorMath]
[VectorLogic]
@@ -32,6 +38,9 @@ public partial struct int3
}
}
+///
+/// Represents a vector with four 32-bit signed integer values.
+///
[Vector(typeof(int), 4, "int")]
[VectorMath]
[VectorLogic]
diff --git a/ScriptCore/Math/UIntVectors.cs b/ScriptCore/Math/UIntVectors.cs
index 18f60e4..7889c13 100644
--- a/ScriptCore/Math/UIntVectors.cs
+++ b/ScriptCore/Math/UIntVectors.cs
@@ -6,6 +6,9 @@ namespace GlitchyEngine.Math;
// TODO: Currently no VectorMath-Attribute because -uint results in long
+///
+/// Represents a vector with two 32-bit unsigned integer values.
+///
[Vector(typeof(uint), 2, "uint")]
[VectorLogic]
[ComparableVector]
@@ -19,6 +22,9 @@ public partial struct uint2
}
}
+///
+/// Represents a vector with three 32-bit unsigned integer values.
+///
[Vector(typeof(uint), 3, "uint")]
[VectorLogic]
[ComparableVector]
@@ -32,6 +38,9 @@ public partial struct uint3
}
}
+///
+/// Represents a vector with four 32-bit unsigned integer values.
+///
[Vector(typeof(uint), 4, "uint")]
[VectorLogic]
[ComparableVector]