separate math into float and fixed

pull/19/head
cosmonaut 2022-05-11 10:31:16 -07:00
parent 85f21b7859
commit 17273d890a
52 changed files with 71 additions and 46 deletions

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Audio namespace MoonWorks.Audio
{ {

View File

@ -1,5 +1,5 @@
using System; using System;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Audio namespace MoonWorks.Audio
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Audio namespace MoonWorks.Audio
{ {
@ -53,7 +53,7 @@ namespace MoonWorks.Audio
get => _pitch; get => _pitch;
set set
{ {
_pitch = MathHelper.Clamp(value, -1f, 1f); _pitch = Math.MathHelper.Clamp(value, -1f, 1f);
UpdatePitch(); UpdatePitch();
} }
} }

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,4 +1,4 @@
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,4 +1,4 @@
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,4 +1,4 @@
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Collision.Float namespace MoonWorks.Collision.Float
{ {

View File

@ -19,6 +19,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -1,5 +1,5 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Graphics.Font namespace MoonWorks.Graphics.Font
{ {

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -16,7 +16,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -16,7 +16,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -16,7 +16,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -14,7 +14,7 @@
#endregion #endregion
using MoonWorks.Math; using MoonWorks.Math.Float;
namespace MoonWorks.Graphics namespace MoonWorks.Graphics
{ {

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -17,6 +17,7 @@
#region Using Statements #region Using Statements
using System; using System;
using MoonWorks.Math; using MoonWorks.Math;
using MoonWorks.Math.Float;
#endregion #endregion
namespace MoonWorks.Graphics namespace MoonWorks.Graphics

View File

@ -22,15 +22,15 @@
{ {
return Graphics.VertexElementFormat.Float; return Graphics.VertexElementFormat.Float;
} }
else if (type == typeof(Math.Vector2)) else if (type == typeof(Math.Float.Vector2))
{ {
return Graphics.VertexElementFormat.Vector2; return Graphics.VertexElementFormat.Vector2;
} }
else if (type == typeof(Math.Vector3)) else if (type == typeof(Math.Float.Vector3))
{ {
return Graphics.VertexElementFormat.Vector3; return Graphics.VertexElementFormat.Vector3;
} }
else if (type == typeof(Math.Vector4)) else if (type == typeof(Math.Float.Vector4))
{ {
return Graphics.VertexElementFormat.Vector4; return Graphics.VertexElementFormat.Vector4;
} }

View File

@ -782,9 +782,9 @@ namespace MoonWorks.Math.Fixed
/// <summary> /// <summary>
/// Casts to floating point Matrix3x2. /// Casts to floating point Matrix3x2.
/// </summary> /// </summary>
public static explicit operator Math.Matrix3x2(Matrix3x2 matrix) public static explicit operator Math.Float.Matrix3x2(Matrix3x2 matrix)
{ {
return new Math.Matrix3x2( return new Math.Float.Matrix3x2(
(float) matrix.M11, (float) matrix.M12, (float) matrix.M11, (float) matrix.M12,
(float) matrix.M21, (float) matrix.M22, (float) matrix.M21, (float) matrix.M22,
(float) matrix.M31, (float) matrix.M32 (float) matrix.M31, (float) matrix.M32

View File

@ -21,7 +21,7 @@ using System.Diagnostics;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
[Serializable] [Serializable]
[DebuggerDisplay("{DebugDisplayString,nq}")] [DebuggerDisplay("{DebugDisplayString,nq}")]

View File

@ -20,7 +20,7 @@ using System.Diagnostics;
using System.Text; using System.Text;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Defines a viewing frustum for intersection operations. /// Defines a viewing frustum for intersection operations.

View File

@ -21,7 +21,7 @@ using System.Diagnostics;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Describes a sphere in 3D-space for bounding operations. /// Describes a sphere in 3D-space for bounding operations.

View File

@ -14,7 +14,7 @@
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Defines how the bounding volumes intersects or contain one another. /// Defines how the bounding volumes intersects or contain one another.

View File

@ -10,7 +10,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// A structure encapsulating a 3x2 matrix. /// A structure encapsulating a 3x2 matrix.

View File

@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Represents the right-handed 4x4 floating point matrix, which can store translation, scale and rotation information. /// Represents the right-handed 4x4 floating point matrix, which can store translation, scale and rotation information.

View File

@ -20,7 +20,7 @@ using System.Diagnostics;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
[Serializable] [Serializable]
[DebuggerDisplay("{DebugDisplayString,nq}")] [DebuggerDisplay("{DebugDisplayString,nq}")]

View File

@ -14,7 +14,7 @@
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Defines the intersection between a <see cref="Plane"/> and a bounding volume. /// Defines the intersection between a <see cref="Plane"/> and a bounding volume.

View File

@ -20,7 +20,7 @@ using System.Diagnostics;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Describes a 2D-point. /// Describes a 2D-point.

View File

@ -20,7 +20,7 @@ using System.Diagnostics;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// An efficient mathematical representation for three dimensional rotations. /// An efficient mathematical representation for three dimensional rotations.

View File

@ -20,7 +20,7 @@ using System.Diagnostics;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
[Serializable] [Serializable]
[DebuggerDisplay("{DebugDisplayString,nq}")] [DebuggerDisplay("{DebugDisplayString,nq}")]

View File

@ -20,7 +20,7 @@ using System.Diagnostics;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Describes a 2D-rectangle. /// Describes a 2D-rectangle.

View File

@ -1,4 +1,4 @@
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
public struct Transform2D : System.IEquatable<Transform2D> public struct Transform2D : System.IEquatable<Transform2D>
{ {
@ -6,7 +6,21 @@ namespace MoonWorks.Math
public float Rotation { get; } public float Rotation { get; }
public Vector2 Scale { get; } public Vector2 Scale { get; }
public Matrix3x2 TransformMatrix { get; } private bool transformMatrixCalculated = false;
private Matrix3x2 transformMatrix = Matrix3x2.Identity;
public Matrix3x2 TransformMatrix
{
get
{
if (!transformMatrixCalculated)
{
transformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
transformMatrixCalculated = true;
}
return transformMatrix;
}
}
public bool IsAxisAligned => Rotation % MathHelper.PiOver2 == 0; public bool IsAxisAligned => Rotation % MathHelper.PiOver2 == 0;
public bool IsUniformScale => Scale.X == Scale.Y; public bool IsUniformScale => Scale.X == Scale.Y;
@ -16,7 +30,6 @@ namespace MoonWorks.Math
Position = Vector2.Zero; Position = Vector2.Zero;
Rotation = 0; Rotation = 0;
Scale = Vector2.One; Scale = Vector2.One;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
} }
public Transform2D(Vector2 position) public Transform2D(Vector2 position)
@ -24,7 +37,6 @@ namespace MoonWorks.Math
Position = position; Position = position;
Rotation = 0; Rotation = 0;
Scale = Vector2.One; Scale = Vector2.One;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
} }
public Transform2D(Vector2 position, float rotation) public Transform2D(Vector2 position, float rotation)
@ -32,7 +44,6 @@ namespace MoonWorks.Math
Position = position; Position = position;
Rotation = rotation; Rotation = rotation;
Scale = Vector2.One; Scale = Vector2.One;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
} }
public Transform2D(Vector2 position, float rotation, Vector2 scale) public Transform2D(Vector2 position, float rotation, Vector2 scale)
@ -40,7 +51,6 @@ namespace MoonWorks.Math
Position = position; Position = position;
Rotation = rotation; Rotation = rotation;
Scale = scale; Scale = scale;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
} }
public Transform2D Compose(Transform2D other) public Transform2D Compose(Transform2D other)

View File

@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Describes a 2D-vector. /// Describes a 2D-vector.

View File

@ -22,7 +22,7 @@ using System.Text;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Describes a 3D-vector. /// Describes a 3D-vector.

View File

@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
#endregion #endregion
namespace MoonWorks.Math namespace MoonWorks.Math.Float
{ {
/// <summary> /// <summary>
/// Describes a 4D-vector. /// Describes a 4D-vector.