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.Runtime.InteropServices;
using MoonWorks.Math;
using MoonWorks.Math.Float;
namespace MoonWorks.Audio
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -782,9 +782,9 @@ namespace MoonWorks.Math.Fixed
/// <summary>
/// Casts to floating point Matrix3x2.
/// </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.M21, (float) matrix.M22,
(float) matrix.M31, (float) matrix.M32

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ using System.Runtime.InteropServices;
#endregion
namespace MoonWorks.Math
namespace MoonWorks.Math.Float
{
/// <summary>
/// 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
namespace MoonWorks.Math
namespace MoonWorks.Math.Float
{
[Serializable]
[DebuggerDisplay("{DebugDisplayString,nq}")]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
namespace MoonWorks.Math
namespace MoonWorks.Math.Float
{
public struct Transform2D : System.IEquatable<Transform2D>
{
@ -6,7 +6,21 @@ namespace MoonWorks.Math
public float Rotation { 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 IsUniformScale => Scale.X == Scale.Y;
@ -16,7 +30,6 @@ namespace MoonWorks.Math
Position = Vector2.Zero;
Rotation = 0;
Scale = Vector2.One;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
}
public Transform2D(Vector2 position)
@ -24,7 +37,6 @@ namespace MoonWorks.Math
Position = position;
Rotation = 0;
Scale = Vector2.One;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
}
public Transform2D(Vector2 position, float rotation)
@ -32,7 +44,6 @@ namespace MoonWorks.Math
Position = position;
Rotation = rotation;
Scale = Vector2.One;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
}
public Transform2D(Vector2 position, float rotation, Vector2 scale)
@ -40,7 +51,6 @@ namespace MoonWorks.Math
Position = position;
Rotation = rotation;
Scale = scale;
TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale);
}
public Transform2D Compose(Transform2D other)

View File

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

View File

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

View File

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