diff --git a/Engine.Core/Extensions/Vector2DExtensions.cs b/Engine.Core/Extensions/Vector2DExtensions.cs deleted file mode 100644 index c51003f..0000000 --- a/Engine.Core/Extensions/Vector2DExtensions.cs +++ /dev/null @@ -1,195 +0,0 @@ -namespace Syntriax.Engine.Core; - -/// -/// Provides extension methods for type. -/// -public static class Vector2DExtensions -{ - /// - /// Returns the representation of the . - /// - /// The input . - /// The representation of the provided . - public static Vector3D As3D(this Vector2D vector) => new(vector.X, vector.Y, 0f); - - /// - /// Calculates the length of the . - /// - /// The input . - /// The length of the . - public static float Length(this Vector2D vector) => Vector2D.Length(vector); - - /// - /// Calculates the squared length of the . - /// - /// The input . - /// The squared length of the . - public static float LengthSquared(this Vector2D vector) => Vector2D.LengthSquared(vector); - - /// - /// Calculates the distance between two s. - /// - /// The starting . - /// The ending . - /// The distance between the two s. - public static float Distance(this Vector2D from, Vector2D to) => Vector2D.Distance(from, to); - - /// - /// Returns the with its components inverted. - /// - /// The input . - /// The inverted . - public static Vector2D Invert(this Vector2D vector) => Vector2D.Invert(vector); - - /// - /// Adds two s component-wise. - /// - /// The first . - /// The vector to be added. - /// The result of the addition. - public static Vector2D Add(this Vector2D vector, Vector2D vectorToAdd) => Vector2D.Add(vector, vectorToAdd); - - /// - /// Subtracts one from another component-wise. - /// - /// The first . - /// The to be subtracted. - /// The result of the subtraction. - public static Vector2D Subtract(this Vector2D vector, Vector2D vectorToSubtract) => Vector2D.Subtract(vector, vectorToSubtract); - - /// - /// Multiplies a by a scalar value. - /// - /// The to multiply. - /// The scalar value to multiply with. - /// The result of the multiplication. - public static Vector2D Multiply(this Vector2D vector, float value) => Vector2D.Multiply(vector, value); - - /// - /// Divides a by a scalar value. - /// - /// The to divide. - /// The scalar value to divide with. - /// The result of the division. - public static Vector2D Divide(this Vector2D vector, float value) => Vector2D.Divide(vector, value); - - /// - /// Returns a with the absolute values of each component. - /// - /// The input . - /// The with absolute values. - public static Vector2D Abs(this Vector2D vector) => Vector2D.Abs(vector); - - /// - /// Reflects a off a surface with the specified normal. - /// - /// The to reflect. - /// The normal of the reflecting surface. - /// The reflected . - public static Vector2D Reflect(this Vector2D vector, Vector2D normal) => Vector2D.Reflect(vector, normal); - - /// - /// Normalizes the (creates a with the same direction but with a length of 1). - /// - /// The input . - /// The normalized . - public static Vector2D Normalize(this Vector2D vector) => Vector2D.Normalize(vector); - - /// - /// Creates a pointing from one point to another. - /// - /// The starting point. - /// The ending point. - /// The pointing from to . - public static Vector2D FromTo(this Vector2D from, Vector2D to) => Vector2D.FromTo(from, to); - - /// - /// Scales a by another component-wise. - /// - /// The to scale. - /// The containing the scaling factors for each component. - /// The scaled . - public static Vector2D Scale(this Vector2D vector, Vector2D scale) => Vector2D.Scale(vector, scale); - - /// - /// Calculates the perpendicular to the given . - /// - /// The input . - /// A perpendicular to the input . - public static Vector2D Perpendicular(this Vector2D vector) => Vector2D.Perpendicular(vector); - - /// - /// Rotates a by the specified angle (in radians). - /// - /// The to rotate. - /// The angle to rotate by, in radians. - /// The rotated . - public static Vector2D Rotate(this Vector2D vector, float angleInRadian) => Vector2D.Rotate(vector, angleInRadian); - - /// - /// Returns the component-wise minimum of two s. - /// - /// The first . - /// The second . - /// The containing the minimum components from both input s. - public static Vector2D Min(this Vector2D left, Vector2D right) => Vector2D.Min(left, right); - - /// - /// Returns the component-wise maximum of two s. - /// - /// The first . - /// The second . - /// The containing the maximum components from both input s. - public static Vector2D Max(this Vector2D left, Vector2D right) => Vector2D.Max(left, right); - - /// - /// Clamps each component of a between the corresponding component of two other s. - /// - /// The to clamp. - /// The representing the minimum values for each component. - /// The representing the maximum values for each component. - /// The clamped . - public static Vector2D Clamp(this Vector2D vector, Vector2D min, Vector2D max) => Vector2D.Clamp(vector, min, max); - - /// - /// Linearly interpolates between two s. - /// - /// The start . - /// The end . - /// The interpolation parameter (between 0 and 1). - /// The interpolated . - public static Vector2D Lerp(this Vector2D from, Vector2D to, float t) => Vector2D.Lerp(from, to, t); - - /// - /// Calculates the cross product of two s. - /// - /// The first . - /// The second . - /// The cross product of the two s. - public static float Cross(this Vector2D left, Vector2D right) => Vector2D.Cross(left, right); - - /// - /// Calculates the angle in radians between two s. - /// - /// The first . - /// The second . - /// The angle between the two s in radians. - public static float AngleBetween(this Vector2D left, Vector2D right) => Vector2D.Angle(left, right); - - /// - /// Calculates the dot product of two s. - /// - /// The first . - /// The second . - /// The dot product of the two s. - public static float Dot(this Vector2D left, Vector2D right) => Vector2D.Dot(left, right); - - /// - /// Checks whether two s are approximately equal within a certain epsilon range. - /// - /// The first . - /// The second . - /// The maximum difference allowed between components. - /// True if the s are approximately equal, false otherwise. - public static bool ApproximatelyEquals(this Vector2D left, Vector2D right, float epsilon = float.Epsilon) => Vector2D.ApproximatelyEquals(left, right, epsilon); -} diff --git a/Engine.Core/Extensions/Vector3DExtensions.cs b/Engine.Core/Extensions/Vector3DExtensions.cs deleted file mode 100644 index d3612d4..0000000 --- a/Engine.Core/Extensions/Vector3DExtensions.cs +++ /dev/null @@ -1,189 +0,0 @@ -namespace Syntriax.Engine.Core; - -/// -/// Provides extension methods for type. -/// -public static class Vector3DExtensions -{ - /// - /// Returns the representation of the . - /// - /// The input . - /// The representation of the provided . - public static Vector2D As2D(this Vector3D vector) => new(vector.X, vector.Y); - - /// - /// Calculates the length of the . - /// - /// The input . - /// The length of the . - public static float Length(this Vector3D vector) => Vector3D.Length(vector); - - /// - /// Calculates the squared length of the . - /// - /// The input . - /// The squared length of the . - public static float LengthSquared(this Vector3D vector) => Vector3D.LengthSquared(vector); - - /// - /// Calculates the distance between two s. - /// - /// The starting . - /// The ending . - /// The distance between the two s. - public static float Distance(this Vector3D from, Vector3D to) => Vector3D.Distance(from, to); - - /// - /// Returns the with its components inverted. - /// - /// The input . - /// The inverted . - public static Vector3D Invert(this Vector3D vector) => Vector3D.Invert(vector); - - /// - /// Adds two s component-wise. - /// - /// The first . - /// The vector to be added. - /// The result of the addition. - public static Vector3D Add(this Vector3D vector, Vector3D vectorToAdd) => Vector3D.Add(vector, vectorToAdd); - - /// - /// Subtracts one from another component-wise. - /// - /// The first . - /// The to be subtracted. - /// The result of the subtraction. - public static Vector3D Subtract(this Vector3D vector, Vector3D vectorToSubtract) => Vector3D.Subtract(vector, vectorToSubtract); - - /// - /// Multiplies a by a scalar value. - /// - /// The to multiply. - /// The scalar value to multiply with. - /// The result of the multiplication. - public static Vector3D Multiply(this Vector3D vector, float value) => Vector3D.Multiply(vector, value); - - /// - /// Divides a by a scalar value. - /// - /// The to divide. - /// The scalar value to divide with. - /// The result of the division. - public static Vector3D Divide(this Vector3D vector, float value) => Vector3D.Divide(vector, value); - - /// - /// Returns a with the absolute values of each component. - /// - /// The input . - /// The with absolute values. - public static Vector3D Abs(this Vector3D vector) => Vector3D.Abs(vector); - - /// - /// Reflects a off a surface with the specified normal. - /// - /// The to reflect. - /// The normal of the reflecting surface. - /// The reflected . - public static Vector3D Reflect(this Vector3D vector, Vector3D normal) => Vector3D.Reflect(vector, normal); - - /// - /// Normalizes the (creates a with the same direction but with a length of 1). - /// - /// The input . - /// The normalized . - public static Vector3D Normalize(this Vector3D vector) => Vector3D.Normalize(vector); - - /// - /// Creates a pointing from one point to another. - /// - /// The starting point. - /// The ending point. - /// The pointing from to . - public static Vector3D FromTo(this Vector3D from, Vector3D to) => Vector3D.FromTo(from, to); - - /// - /// Scales a by another component-wise. - /// - /// The to scale. - /// The containing the scaling factors for each component. - /// The scaled . - public static Vector3D Scale(this Vector3D vector, Vector3D scale) => Vector3D.Scale(vector, scale); - - /// - /// Rotates a by the specified angle (in radians). - /// - /// The to rotate. - /// The to rotate around. - /// The angle to rotate by, in radians. - /// The rotated . - public static Vector3D Rotate(this Vector3D vector, Vector3D normal, float angleInRadian) => Vector3D.Rotate(vector, normal, angleInRadian); - - /// - /// Returns the component-wise minimum of two s. - /// - /// The first . - /// The second . - /// The containing the minimum components from both input s. - public static Vector3D Min(this Vector3D left, Vector3D right) => Vector3D.Min(left, right); - - /// - /// Returns the component-wise maximum of two s. - /// - /// The first . - /// The second . - /// The containing the maximum components from both input s. - public static Vector3D Max(this Vector3D left, Vector3D right) => Vector3D.Max(left, right); - - /// - /// Clamps each component of a between the corresponding component of two other s. - /// - /// The to clamp. - /// The representing the minimum values for each component. - /// The representing the maximum values for each component. - /// The clamped . - public static Vector3D Clamp(this Vector3D vector, Vector3D min, Vector3D max) => Vector3D.Clamp(vector, min, max); - - /// - /// Linearly interpolates between two s. - /// - /// The start . - /// The end . - /// The interpolation parameter (between 0 and 1). - /// The interpolated . - public static Vector3D Lerp(this Vector3D from, Vector3D to, float t) => Vector3D.Lerp(from, to, t); - - /// - /// Calculates the cross product of two s. - /// - /// The first . - /// The second . - /// The cross product of the two s. - public static Vector3D Cross(this Vector3D left, Vector3D right) => Vector3D.Cross(left, right); - - /// - /// Calculates the angle in radians between two s. - /// - /// The first . - /// The second . - /// The angle between the two s in radians. - public static float AngleBetween(this Vector3D left, Vector3D right) => Vector3D.Angle(left, right); - - /// - /// Calculates the dot product of two s. - /// - /// The first . - /// The second . - /// The dot product of the two s. - public static float Dot(this Vector3D left, Vector3D right) => Vector3D.Dot(left, right); - - /// - /// Checks whether two s are approximately equal within a certain epsilon range. - /// - /// The first . - /// The second . - /// The maximum difference allowed between components. - /// True if the s are approximately equal, false otherwise. - public static bool ApproximatelyEquals(this Vector3D left, Vector3D right, float epsilon = float.Epsilon) => Vector3D.ApproximatelyEquals(left, right, epsilon); -} diff --git a/Engine.Physics2D/Primitives/AABB.cs b/Engine.Core/Primitives/AABB.cs similarity index 98% rename from Engine.Physics2D/Primitives/AABB.cs rename to Engine.Core/Primitives/AABB.cs index 6d1191b..cbf60a5 100644 --- a/Engine.Physics2D/Primitives/AABB.cs +++ b/Engine.Core/Primitives/AABB.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; -using Syntriax.Engine.Core; - -namespace Syntriax.Engine.Physics2D.Primitives; +namespace Syntriax.Engine.Core; /// /// Represents an Axis-Aligned Bounding Box (AABB) in 2D space. diff --git a/Engine.Physics2D/Primitives/Circle.cs b/Engine.Core/Primitives/Circle.cs similarity index 96% rename from Engine.Physics2D/Primitives/Circle.cs rename to Engine.Core/Primitives/Circle.cs index 5787921..1833a65 100644 --- a/Engine.Physics2D/Primitives/Circle.cs +++ b/Engine.Core/Primitives/Circle.cs @@ -1,9 +1,7 @@ using System.Diagnostics; - -using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; -namespace Syntriax.Engine.Physics2D.Primitives; +namespace Syntriax.Engine.Core; /// /// Represents a 2D circle. @@ -11,7 +9,7 @@ namespace Syntriax.Engine.Physics2D.Primitives; /// The center of the circle. /// The radius of the circle. /// -/// Initializes a new instance of the Circle struct with the specified center and radius. +/// Initializes a new instance of the struct with the specified center and radius. /// [DebuggerDisplay("Center: {Center.ToString(),nq}, Radius: {Radius}")] public readonly struct Circle(Vector2D center, float radius) diff --git a/Engine.Physics2D/Primitives/Line2D.cs b/Engine.Core/Primitives/Line2D.cs similarity index 98% rename from Engine.Physics2D/Primitives/Line2D.cs rename to Engine.Core/Primitives/Line2D.cs index 920fda5..0a11de2 100644 --- a/Engine.Physics2D/Primitives/Line2D.cs +++ b/Engine.Core/Primitives/Line2D.cs @@ -1,18 +1,16 @@ using System; using System.Diagnostics.CodeAnalysis; -using Syntriax.Engine.Core; - -namespace Syntriax.Engine.Physics2D.Primitives; +namespace Syntriax.Engine.Core; /// /// Represents a 2D line segment defined by two endpoints. /// -/// -/// Initializes a new instance of the Line struct with the specified endpoints. -/// /// The starting point of the segment. /// The ending point of the segment. +/// +/// Initializes a new instance of the struct with the specified endpoints. +/// [System.Diagnostics.DebuggerDisplay("From: {From.ToString(),nq}, To: {To.ToString(),nq}, Direction: {Direction.ToString(),nq}, Length: {Length}")] public readonly struct Line2D(Vector2D from, Vector2D to) { diff --git a/Engine.Physics2D/Primitives/Line2DEquation.cs b/Engine.Core/Primitives/Line2DEquation.cs similarity index 97% rename from Engine.Physics2D/Primitives/Line2DEquation.cs rename to Engine.Core/Primitives/Line2DEquation.cs index b64f7a2..20d33ab 100644 --- a/Engine.Physics2D/Primitives/Line2DEquation.cs +++ b/Engine.Core/Primitives/Line2DEquation.cs @@ -1,6 +1,4 @@ -using Syntriax.Engine.Core; - -namespace Syntriax.Engine.Physics2D.Primitives; +namespace Syntriax.Engine.Core; /// /// Represents a line equation in the form y = mx + b. diff --git a/Engine.Physics2D/Primitives/Projection1D.cs b/Engine.Core/Primitives/Projection1D.cs similarity index 98% rename from Engine.Physics2D/Primitives/Projection1D.cs rename to Engine.Core/Primitives/Projection1D.cs index 3ee27bd..9c72fdd 100644 --- a/Engine.Physics2D/Primitives/Projection1D.cs +++ b/Engine.Core/Primitives/Projection1D.cs @@ -1,4 +1,4 @@ -namespace Syntriax.Engine.Physics2D.Primitives; +namespace Syntriax.Engine.Core; /// /// Represents a range of values along a single axis. diff --git a/Engine.Physics2D/Primitives/Shape2D.cs b/Engine.Core/Primitives/Shape2D.cs similarity index 99% rename from Engine.Physics2D/Primitives/Shape2D.cs rename to Engine.Core/Primitives/Shape2D.cs index 335323e..95d94df 100644 --- a/Engine.Physics2D/Primitives/Shape2D.cs +++ b/Engine.Core/Primitives/Shape2D.cs @@ -1,10 +1,8 @@ using System.Collections; using System.Collections.Generic; - -using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; -namespace Syntriax.Engine.Physics2D.Primitives; +namespace Syntriax.Engine.Core; /// /// Represents a shape defined by a collection of vertices. diff --git a/Engine.Physics2D/Primitives/Triangle.cs b/Engine.Core/Primitives/Triangle.cs similarity index 95% rename from Engine.Physics2D/Primitives/Triangle.cs rename to Engine.Core/Primitives/Triangle.cs index 9695460..8e3ce88 100644 --- a/Engine.Physics2D/Primitives/Triangle.cs +++ b/Engine.Core/Primitives/Triangle.cs @@ -1,8 +1,6 @@ using System; -using Syntriax.Engine.Core; - -namespace Syntriax.Engine.Physics2D.Primitives; +namespace Syntriax.Engine.Core; [System.Diagnostics.DebuggerDisplay("A: {A.ToString(), nq}, B: {B.ToString(), nq}, B: {C.ToString(), nq}")] public readonly struct Triangle(Vector2D A, Vector2D B, Vector2D C) diff --git a/Engine.Core/Vector2D.cs b/Engine.Core/Primitives/Vector2D.cs similarity index 58% rename from Engine.Core/Vector2D.cs rename to Engine.Core/Primitives/Vector2D.cs index cfa0b18..001973d 100644 --- a/Engine.Core/Vector2D.cs +++ b/Engine.Core/Primitives/Vector2D.cs @@ -5,6 +5,11 @@ namespace Syntriax.Engine.Core; /// /// Represents a two-dimensional vector. /// +/// X position of the . +/// Y position of the . +/// +/// Initializes a new instance of the struct with the specified positions. +/// [System.Diagnostics.DebuggerDisplay("{ToString(),nq}, Length: {Magnitude}, LengthSquared: {MagnitudeSquared}, Normalized: {Normalized.ToString(),nq}")] public readonly struct Vector2D(float x, float y) { @@ -300,3 +305,197 @@ public readonly struct Vector2D(float x, float y) /// A hash code for the . public override int GetHashCode() => HashCode.Combine(X, Y); } + +/// +/// Provides extension methods for type. +/// +public static class Vector2DExtensions +{ + /// + /// Returns the representation of the . + /// + /// The input . + /// The representation of the provided . + public static Vector3D As3D(this Vector2D vector) => new(vector.X, vector.Y, 0f); + + /// + /// Calculates the length of the . + /// + /// The input . + /// The length of the . + public static float Length(this Vector2D vector) => Vector2D.Length(vector); + + /// + /// Calculates the squared length of the . + /// + /// The input . + /// The squared length of the . + public static float LengthSquared(this Vector2D vector) => Vector2D.LengthSquared(vector); + + /// + /// Calculates the distance between two s. + /// + /// The starting . + /// The ending . + /// The distance between the two s. + public static float Distance(this Vector2D from, Vector2D to) => Vector2D.Distance(from, to); + + /// + /// Returns the with its components inverted. + /// + /// The input . + /// The inverted . + public static Vector2D Invert(this Vector2D vector) => Vector2D.Invert(vector); + + /// + /// Adds two s component-wise. + /// + /// The first . + /// The vector to be added. + /// The result of the addition. + public static Vector2D Add(this Vector2D vector, Vector2D vectorToAdd) => Vector2D.Add(vector, vectorToAdd); + + /// + /// Subtracts one from another component-wise. + /// + /// The first . + /// The to be subtracted. + /// The result of the subtraction. + public static Vector2D Subtract(this Vector2D vector, Vector2D vectorToSubtract) => Vector2D.Subtract(vector, vectorToSubtract); + + /// + /// Multiplies a by a scalar value. + /// + /// The to multiply. + /// The scalar value to multiply with. + /// The result of the multiplication. + public static Vector2D Multiply(this Vector2D vector, float value) => Vector2D.Multiply(vector, value); + + /// + /// Divides a by a scalar value. + /// + /// The to divide. + /// The scalar value to divide with. + /// The result of the division. + public static Vector2D Divide(this Vector2D vector, float value) => Vector2D.Divide(vector, value); + + /// + /// Returns a with the absolute values of each component. + /// + /// The input . + /// The with absolute values. + public static Vector2D Abs(this Vector2D vector) => Vector2D.Abs(vector); + + /// + /// Reflects a off a surface with the specified normal. + /// + /// The to reflect. + /// The normal of the reflecting surface. + /// The reflected . + public static Vector2D Reflect(this Vector2D vector, Vector2D normal) => Vector2D.Reflect(vector, normal); + + /// + /// Normalizes the (creates a with the same direction but with a length of 1). + /// + /// The input . + /// The normalized . + public static Vector2D Normalize(this Vector2D vector) => Vector2D.Normalize(vector); + + /// + /// Creates a pointing from one point to another. + /// + /// The starting point. + /// The ending point. + /// The pointing from to . + public static Vector2D FromTo(this Vector2D from, Vector2D to) => Vector2D.FromTo(from, to); + + /// + /// Scales a by another component-wise. + /// + /// The to scale. + /// The containing the scaling factors for each component. + /// The scaled . + public static Vector2D Scale(this Vector2D vector, Vector2D scale) => Vector2D.Scale(vector, scale); + + /// + /// Calculates the perpendicular to the given . + /// + /// The input . + /// A perpendicular to the input . + public static Vector2D Perpendicular(this Vector2D vector) => Vector2D.Perpendicular(vector); + + /// + /// Rotates a by the specified angle (in radians). + /// + /// The to rotate. + /// The angle to rotate by, in radians. + /// The rotated . + public static Vector2D Rotate(this Vector2D vector, float angleInRadian) => Vector2D.Rotate(vector, angleInRadian); + + /// + /// Returns the component-wise minimum of two s. + /// + /// The first . + /// The second . + /// The containing the minimum components from both input s. + public static Vector2D Min(this Vector2D left, Vector2D right) => Vector2D.Min(left, right); + + /// + /// Returns the component-wise maximum of two s. + /// + /// The first . + /// The second . + /// The containing the maximum components from both input s. + public static Vector2D Max(this Vector2D left, Vector2D right) => Vector2D.Max(left, right); + + /// + /// Clamps each component of a between the corresponding component of two other s. + /// + /// The to clamp. + /// The representing the minimum values for each component. + /// The representing the maximum values for each component. + /// The clamped . + public static Vector2D Clamp(this Vector2D vector, Vector2D min, Vector2D max) => Vector2D.Clamp(vector, min, max); + + /// + /// Linearly interpolates between two s. + /// + /// The start . + /// The end . + /// The interpolation parameter (between 0 and 1). + /// The interpolated . + public static Vector2D Lerp(this Vector2D from, Vector2D to, float t) => Vector2D.Lerp(from, to, t); + + /// + /// Calculates the cross product of two s. + /// + /// The first . + /// The second . + /// The cross product of the two s. + public static float Cross(this Vector2D left, Vector2D right) => Vector2D.Cross(left, right); + + /// + /// Calculates the angle in radians between two s. + /// + /// The first . + /// The second . + /// The angle between the two s in radians. + public static float AngleBetween(this Vector2D left, Vector2D right) => Vector2D.Angle(left, right); + + /// + /// Calculates the dot product of two s. + /// + /// The first . + /// The second . + /// The dot product of the two s. + public static float Dot(this Vector2D left, Vector2D right) => Vector2D.Dot(left, right); + + /// + /// Checks whether two s are approximately equal within a certain epsilon range. + /// + /// The first . + /// The second . + /// The maximum difference allowed between components. + /// True if the s are approximately equal, false otherwise. + public static bool ApproximatelyEquals(this Vector2D left, Vector2D right, float epsilon = float.Epsilon) => Vector2D.ApproximatelyEquals(left, right, epsilon); +} diff --git a/Engine.Core/Vector3D.cs b/Engine.Core/Primitives/Vector3D.cs similarity index 58% rename from Engine.Core/Vector3D.cs rename to Engine.Core/Primitives/Vector3D.cs index 3c259b5..6b57ef5 100644 --- a/Engine.Core/Vector3D.cs +++ b/Engine.Core/Primitives/Vector3D.cs @@ -5,6 +5,12 @@ namespace Syntriax.Engine.Core; /// /// Represents a three-dimensional vector. /// +/// X position of the . +/// Y position of the . +/// Z position of the . +/// +/// Initializes a new instance of the struct with the specified positions. +/// [System.Diagnostics.DebuggerDisplay("{ToString(),nq}, Length: {Magnitude}, LengthSquared: {MagnitudeSquared}, Normalized: {Normalized.ToString(),nq}")] public readonly struct Vector3D(float x, float y, float z) { @@ -284,3 +290,191 @@ public readonly struct Vector3D(float x, float y, float z) /// A hash code for the . public override int GetHashCode() => HashCode.Combine(X, Y, Z); } + +/// +/// Provides extension methods for type. +/// +public static class Vector3DExtensions +{ + /// + /// Returns the representation of the . + /// + /// The input . + /// The representation of the provided . + public static Vector2D As2D(this Vector3D vector) => new(vector.X, vector.Y); + + /// + /// Calculates the length of the . + /// + /// The input . + /// The length of the . + public static float Length(this Vector3D vector) => Vector3D.Length(vector); + + /// + /// Calculates the squared length of the . + /// + /// The input . + /// The squared length of the . + public static float LengthSquared(this Vector3D vector) => Vector3D.LengthSquared(vector); + + /// + /// Calculates the distance between two s. + /// + /// The starting . + /// The ending . + /// The distance between the two s. + public static float Distance(this Vector3D from, Vector3D to) => Vector3D.Distance(from, to); + + /// + /// Returns the with its components inverted. + /// + /// The input . + /// The inverted . + public static Vector3D Invert(this Vector3D vector) => Vector3D.Invert(vector); + + /// + /// Adds two s component-wise. + /// + /// The first . + /// The vector to be added. + /// The result of the addition. + public static Vector3D Add(this Vector3D vector, Vector3D vectorToAdd) => Vector3D.Add(vector, vectorToAdd); + + /// + /// Subtracts one from another component-wise. + /// + /// The first . + /// The to be subtracted. + /// The result of the subtraction. + public static Vector3D Subtract(this Vector3D vector, Vector3D vectorToSubtract) => Vector3D.Subtract(vector, vectorToSubtract); + + /// + /// Multiplies a by a scalar value. + /// + /// The to multiply. + /// The scalar value to multiply with. + /// The result of the multiplication. + public static Vector3D Multiply(this Vector3D vector, float value) => Vector3D.Multiply(vector, value); + + /// + /// Divides a by a scalar value. + /// + /// The to divide. + /// The scalar value to divide with. + /// The result of the division. + public static Vector3D Divide(this Vector3D vector, float value) => Vector3D.Divide(vector, value); + + /// + /// Returns a with the absolute values of each component. + /// + /// The input . + /// The with absolute values. + public static Vector3D Abs(this Vector3D vector) => Vector3D.Abs(vector); + + /// + /// Reflects a off a surface with the specified normal. + /// + /// The to reflect. + /// The normal of the reflecting surface. + /// The reflected . + public static Vector3D Reflect(this Vector3D vector, Vector3D normal) => Vector3D.Reflect(vector, normal); + + /// + /// Normalizes the (creates a with the same direction but with a length of 1). + /// + /// The input . + /// The normalized . + public static Vector3D Normalize(this Vector3D vector) => Vector3D.Normalize(vector); + + /// + /// Creates a pointing from one point to another. + /// + /// The starting point. + /// The ending point. + /// The pointing from to . + public static Vector3D FromTo(this Vector3D from, Vector3D to) => Vector3D.FromTo(from, to); + + /// + /// Scales a by another component-wise. + /// + /// The to scale. + /// The containing the scaling factors for each component. + /// The scaled . + public static Vector3D Scale(this Vector3D vector, Vector3D scale) => Vector3D.Scale(vector, scale); + + /// + /// Rotates a by the specified angle (in radians). + /// + /// The to rotate. + /// The to rotate around. + /// The angle to rotate by, in radians. + /// The rotated . + public static Vector3D Rotate(this Vector3D vector, Vector3D normal, float angleInRadian) => Vector3D.Rotate(vector, normal, angleInRadian); + + /// + /// Returns the component-wise minimum of two s. + /// + /// The first . + /// The second . + /// The containing the minimum components from both input s. + public static Vector3D Min(this Vector3D left, Vector3D right) => Vector3D.Min(left, right); + + /// + /// Returns the component-wise maximum of two s. + /// + /// The first . + /// The second . + /// The containing the maximum components from both input s. + public static Vector3D Max(this Vector3D left, Vector3D right) => Vector3D.Max(left, right); + + /// + /// Clamps each component of a between the corresponding component of two other s. + /// + /// The to clamp. + /// The representing the minimum values for each component. + /// The representing the maximum values for each component. + /// The clamped . + public static Vector3D Clamp(this Vector3D vector, Vector3D min, Vector3D max) => Vector3D.Clamp(vector, min, max); + + /// + /// Linearly interpolates between two s. + /// + /// The start . + /// The end . + /// The interpolation parameter (between 0 and 1). + /// The interpolated . + public static Vector3D Lerp(this Vector3D from, Vector3D to, float t) => Vector3D.Lerp(from, to, t); + + /// + /// Calculates the cross product of two s. + /// + /// The first . + /// The second . + /// The cross product of the two s. + public static Vector3D Cross(this Vector3D left, Vector3D right) => Vector3D.Cross(left, right); + + /// + /// Calculates the angle in radians between two s. + /// + /// The first . + /// The second . + /// The angle between the two s in radians. + public static float AngleBetween(this Vector3D left, Vector3D right) => Vector3D.Angle(left, right); + + /// + /// Calculates the dot product of two s. + /// + /// The first . + /// The second . + /// The dot product of the two s. + public static float Dot(this Vector3D left, Vector3D right) => Vector3D.Dot(left, right); + + /// + /// Checks whether two s are approximately equal within a certain epsilon range. + /// + /// The first . + /// The second . + /// The maximum difference allowed between components. + /// True if the s are approximately equal, false otherwise. + public static bool ApproximatelyEquals(this Vector3D left, Vector3D right, float epsilon = float.Epsilon) => Vector3D.ApproximatelyEquals(left, right, epsilon); +} diff --git a/Engine.Physics2D/Abstract/ICircleCollider2D.cs b/Engine.Physics2D/Abstract/ICircleCollider2D.cs index a41820f..2dc2efc 100644 --- a/Engine.Physics2D/Abstract/ICircleCollider2D.cs +++ b/Engine.Physics2D/Abstract/ICircleCollider2D.cs @@ -1,4 +1,4 @@ -using Syntriax.Engine.Physics2D.Primitives; +using Syntriax.Engine.Core; namespace Syntriax.Engine.Physics2D.Abstract; diff --git a/Engine.Physics2D/Abstract/IShapeCollider2D.cs b/Engine.Physics2D/Abstract/IShapeCollider2D.cs index 87aca76..e9d0ba4 100644 --- a/Engine.Physics2D/Abstract/IShapeCollider2D.cs +++ b/Engine.Physics2D/Abstract/IShapeCollider2D.cs @@ -1,4 +1,4 @@ -using Syntriax.Engine.Physics2D.Primitives; +using Syntriax.Engine.Core; namespace Syntriax.Engine.Physics2D.Abstract; diff --git a/Engine.Physics2D/Collider2DCircleBehaviour.cs b/Engine.Physics2D/Collider2DCircleBehaviour.cs index 37bf006..ebf7766 100644 --- a/Engine.Physics2D/Collider2DCircleBehaviour.cs +++ b/Engine.Physics2D/Collider2DCircleBehaviour.cs @@ -1,5 +1,5 @@ +using Syntriax.Engine.Core; using Syntriax.Engine.Physics2D.Abstract; -using Syntriax.Engine.Physics2D.Primitives; namespace Syntriax.Engine.Physics2D; diff --git a/Engine.Physics2D/Collider2DShapeBehaviour.cs b/Engine.Physics2D/Collider2DShapeBehaviour.cs index 95de053..a5d393c 100644 --- a/Engine.Physics2D/Collider2DShapeBehaviour.cs +++ b/Engine.Physics2D/Collider2DShapeBehaviour.cs @@ -1,5 +1,5 @@ +using Syntriax.Engine.Core; using Syntriax.Engine.Physics2D.Abstract; -using Syntriax.Engine.Physics2D.Primitives; namespace Syntriax.Engine.Physics2D; diff --git a/Engine.Physics2D/CollisionDetector2D.cs b/Engine.Physics2D/CollisionDetector2D.cs index e6fd1e7..69bb501 100644 --- a/Engine.Physics2D/CollisionDetector2D.cs +++ b/Engine.Physics2D/CollisionDetector2D.cs @@ -1,6 +1,5 @@ using Syntriax.Engine.Core; using Syntriax.Engine.Physics2D.Abstract; -using Syntriax.Engine.Physics2D.Primitives; namespace Syntriax.Engine.Physics2D; diff --git a/Engine.Physics2D/Physics2D.cs b/Engine.Physics2D/Physics2D.cs index 60b9d8b..6293b95 100644 --- a/Engine.Physics2D/Physics2D.cs +++ b/Engine.Physics2D/Physics2D.cs @@ -1,5 +1,4 @@ using Syntriax.Engine.Core; -using Syntriax.Engine.Physics2D.Primitives; namespace Syntriax.Engine.Physics2D;