refactor: TransformFoo like extension methods renamed to Transform
This commit is contained in:
parent
3a385900fb
commit
2535a1d6ec
@ -1,9 +0,0 @@
|
|||||||
namespace Syntriax.Engine.Core.Abstract;
|
|
||||||
|
|
||||||
public static class TransformExtensions
|
|
||||||
{
|
|
||||||
public static Vector2D TransformVector2D(this ITransform2D transform, Vector2D vector)
|
|
||||||
=> vector.Scale(transform.Scale)
|
|
||||||
.Rotate(transform.Rotation * Math.DegreeToRadian)
|
|
||||||
.Add(transform.Position);
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using Syntriax.Engine.Core.Abstract;
|
using Syntriax.Engine.Core.Abstract;
|
||||||
|
|
||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
@ -66,8 +67,8 @@ public readonly struct Circle(Vector2D center, float radius)
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transforms the <see cref="Circle"/> by the specified <see cref="ITransform2D"/>.
|
/// Transforms the <see cref="Circle"/> by the specified <see cref="ITransform2D"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Circle TransformCircle(ITransform2D transform, Circle circle)
|
public static Circle Transform(ITransform2D transform, Circle circle)
|
||||||
=> new(transform.TransformVector2D(circle.Center), circle.Radius * (transform.Scale.Magnitude / Vector2D.One.Magnitude));
|
=> new(transform.Transform(circle.Center), circle.Radius * (transform.Scale.Magnitude / Vector2D.One.Magnitude));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if two <see cref="Circle"/>s are approximately equal.
|
/// Checks if two <see cref="Circle"/>s are approximately equal.
|
||||||
@ -97,8 +98,8 @@ public static class CircleExtensions
|
|||||||
/// <inheritdoc cref="Circle.Project(Circle, Vector2D)" />
|
/// <inheritdoc cref="Circle.Project(Circle, Vector2D)" />
|
||||||
public static Projection1D ToProjection(this Circle circle, Vector2D projectionVector) => Circle.Project(circle, projectionVector);
|
public static Projection1D ToProjection(this Circle circle, Vector2D projectionVector) => Circle.Project(circle, projectionVector);
|
||||||
|
|
||||||
/// <inheritdoc cref="Circle.TransformCircle(ITransform2D, Circle)" />
|
/// <inheritdoc cref="Circle.Transform(ITransform2D, Circle)" />
|
||||||
public static Circle TransformCircle(this ITransform2D transform, Circle circle) => Circle.TransformCircle(transform, circle);
|
public static Circle Transform(this ITransform2D transform, Circle circle) => Circle.Transform(transform, circle);
|
||||||
|
|
||||||
/// <inheritdoc cref="Circle.ApproximatelyEquals(Circle, Circle, float)" />
|
/// <inheritdoc cref="Circle.ApproximatelyEquals(Circle, Circle, float)" />
|
||||||
public static bool ApproximatelyEquals(this Circle left, Circle right, float epsilon = float.Epsilon) => Circle.ApproximatelyEquals(left, right, epsilon);
|
public static bool ApproximatelyEquals(this Circle left, Circle right, float epsilon = float.Epsilon) => Circle.ApproximatelyEquals(left, right, epsilon);
|
||||||
|
@ -192,13 +192,13 @@ public readonly struct Shape2D(List<Vector2D> vertices) : IEnumerable<Vector2D>
|
|||||||
/// <param name="shape">The <see cref="Shape2D"/> to transform.</param>
|
/// <param name="shape">The <see cref="Shape2D"/> to transform.</param>
|
||||||
/// <param name="transform">The <see cref="ITransform2D"/> to apply.</param>
|
/// <param name="transform">The <see cref="ITransform2D"/> to apply.</param>
|
||||||
/// <returns>The transformed <see cref="Shape2D"/>.</returns>
|
/// <returns>The transformed <see cref="Shape2D"/>.</returns>
|
||||||
public static Shape2D TransformShape(Shape2D shape, ITransform2D transform)
|
public static Shape2D Transform(Shape2D shape, ITransform2D transform)
|
||||||
{
|
{
|
||||||
List<Vector2D> vertices = new(shape.Vertices.Count);
|
List<Vector2D> vertices = new(shape.Vertices.Count);
|
||||||
|
|
||||||
int count = shape.Vertices.Count;
|
int count = shape.Vertices.Count;
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
vertices.Add(transform.TransformVector2D(shape[i]));
|
vertices.Add(transform.Transform(shape[i]));
|
||||||
|
|
||||||
return new Shape2D(vertices);
|
return new Shape2D(vertices);
|
||||||
}
|
}
|
||||||
@ -209,13 +209,13 @@ public readonly struct Shape2D(List<Vector2D> vertices) : IEnumerable<Vector2D>
|
|||||||
/// <param name="from">The <see cref="Shape2D"/> to transform.</param>
|
/// <param name="from">The <see cref="Shape2D"/> to transform.</param>
|
||||||
/// <param name="transform">The <see cref="ITransform2D"/> to apply.</param>
|
/// <param name="transform">The <see cref="ITransform2D"/> to apply.</param>
|
||||||
/// <param name="to">The transformed <see cref="Shape2D"/>.</param>
|
/// <param name="to">The transformed <see cref="Shape2D"/>.</param>
|
||||||
public static void TransformShape(Shape2D from, ITransform2D transform, ref Shape2D to)
|
public static void Transform(Shape2D from, ITransform2D transform, ref Shape2D to)
|
||||||
{
|
{
|
||||||
to._verticesList.Clear();
|
to._verticesList.Clear();
|
||||||
|
|
||||||
int count = from._verticesList.Count;
|
int count = from._verticesList.Count;
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
to._verticesList.Add(transform.TransformVector2D(from[i]));
|
to._verticesList.Add(transform.Transform(from[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -273,17 +273,17 @@ public static class Shape2DExtensions
|
|||||||
/// <inheritdoc cref="Shape2D.Project(Shape2D, Vector2D)" />
|
/// <inheritdoc cref="Shape2D.Project(Shape2D, Vector2D)" />
|
||||||
public static Projection1D ToProjection(this Shape2D shape, Vector2D projectionVector) => Shape2D.Project(shape, projectionVector);
|
public static Projection1D ToProjection(this Shape2D shape, Vector2D projectionVector) => Shape2D.Project(shape, projectionVector);
|
||||||
|
|
||||||
/// <inheritdoc cref="Shape2D.TransformShape(Shape2D, ITransform2D)" />
|
/// <inheritdoc cref="Shape2D.Transform(Shape2D, ITransform2D)" />
|
||||||
public static Shape2D TransformShape(this ITransform2D transform, Shape2D shape) => Shape2D.TransformShape(shape, transform);
|
public static Shape2D Transform(this ITransform2D transform, Shape2D shape) => Shape2D.Transform(shape, transform);
|
||||||
|
|
||||||
/// <inheritdoc cref="Shape2D.TransformShape(Shape2D, ITransform2D, Shape2D)" />
|
/// <inheritdoc cref="Shape2D.Transform(Shape2D, ITransform2D, Shape2D)" />
|
||||||
public static void TransformShape(this ITransform2D transform, Shape2D from, ref Shape2D to) => Shape2D.TransformShape(from, transform, ref to);
|
public static void Transform(this ITransform2D transform, Shape2D from, ref Shape2D to) => Shape2D.Transform(from, transform, ref to);
|
||||||
|
|
||||||
/// <inheritdoc cref="Shape2D.TransformShape(Shape2D, ITransform2D)" />
|
/// <inheritdoc cref="Shape2D.Transform(Shape2D, ITransform2D)" />
|
||||||
public static Shape2D Transform(this Shape2D shape, ITransform2D transform) => Shape2D.TransformShape(shape, transform);
|
public static Shape2D Transform(this Shape2D shape, ITransform2D transform) => Shape2D.Transform(shape, transform);
|
||||||
|
|
||||||
/// <inheritdoc cref="Shape2D.TransformShape(Shape2D, ITransform2D, ref Shape2D)" />
|
/// <inheritdoc cref="Shape2D.Transform(Shape2D, ITransform2D, ref Shape2D)" />
|
||||||
public static void Transform(this Shape2D from, ITransform2D transform, ref Shape2D to) => Shape2D.TransformShape(from, transform, ref to);
|
public static void Transform(this Shape2D from, ITransform2D transform, ref Shape2D to) => Shape2D.Transform(from, transform, ref to);
|
||||||
|
|
||||||
/// <inheritdoc cref="Shape2D.ApproximatelyEquals(Shape2D, Shape2D, float)" />
|
/// <inheritdoc cref="Shape2D.ApproximatelyEquals(Shape2D, Shape2D, float)" />
|
||||||
public static bool ApproximatelyEquals(this Shape2D left, Shape2D right, float epsilon = float.Epsilon) => Shape2D.ApproximatelyEquals(left, right, epsilon);
|
public static bool ApproximatelyEquals(this Shape2D left, Shape2D right, float epsilon = float.Epsilon) => Shape2D.ApproximatelyEquals(left, right, epsilon);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Syntriax.Engine.Core.Abstract;
|
||||||
|
|
||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
|
|
||||||
@ -278,6 +279,17 @@ public readonly struct Vector2D(float x, float y)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Transforms the <see cref="Vector2D"/> using the specified <see cref="ITransform2D"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector">The <see cref="Vector2D"/> to transform.</param>
|
||||||
|
/// <param name="transform">The <see cref="ITransform2D"/> to apply.</param>
|
||||||
|
/// <returns>The transformed <see cref="Vector2D"/>.</returns>
|
||||||
|
public static Vector2D Transform(Vector2D vector, ITransform2D transform)
|
||||||
|
=> vector.Scale(transform.Scale)
|
||||||
|
.Rotate(transform.Rotation * Math.DegreeToRadian)
|
||||||
|
.Add(transform.Position);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if two <see cref="Vector2D"/>s are approximately equal within a specified epsilon range.
|
/// Checks if two <see cref="Vector2D"/>s are approximately equal within a specified epsilon range.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -379,6 +391,12 @@ public static class Vector2DExtensions
|
|||||||
/// <inheritdoc cref="Vector2D.Dot(Vector2D, Vector2D)" />
|
/// <inheritdoc cref="Vector2D.Dot(Vector2D, Vector2D)" />
|
||||||
public static float Dot(this Vector2D left, Vector2D right) => Vector2D.Dot(left, right);
|
public static float Dot(this Vector2D left, Vector2D right) => Vector2D.Dot(left, right);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="Vector2D.Transform(Vector2D, ITransform2D)" />
|
||||||
|
public static Vector2D Transform(this Vector2D vector, ITransform2D transform) => Vector2D.Transform(vector, transform);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="Vector2D.Transform(Vector2D, ITransform2D)" />
|
||||||
|
public static Vector2D Transform(this ITransform2D transform, Vector2D vector) => Vector2D.Transform(vector, transform);
|
||||||
|
|
||||||
/// <inheritdoc cref="Vector2D.ApproximatelyEquals(Vector2D, Vector2D, float) " />
|
/// <inheritdoc cref="Vector2D.ApproximatelyEquals(Vector2D, Vector2D, float) " />
|
||||||
public static bool ApproximatelyEquals(this Vector2D left, Vector2D right, float epsilon = float.Epsilon) => Vector2D.ApproximatelyEquals(left, right, epsilon);
|
public static bool ApproximatelyEquals(this Vector2D left, Vector2D right, float epsilon = float.Epsilon) => Vector2D.ApproximatelyEquals(left, right, epsilon);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user