refactor: code styles enforced with .editorconfig
This commit is contained in:
@@ -2,7 +2,6 @@ using Syntriax.Engine.Physics2D.Primitives;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Represents a <see cref="ICollider2D"/> with a custom <see cref="Shape"/>.
|
||||
/// </summary>
|
||||
|
@@ -10,7 +10,6 @@ public abstract class Collider2DBehaviourBase : Behaviour, ICollider2D
|
||||
public event ICollider2D.OnCollisionResolvedEventHandler? OnCollisionResolved = null;
|
||||
public event ICollider2D.OnTriggeredEventHandler? OnTriggered = null;
|
||||
|
||||
|
||||
protected bool NeedsRecalculation { get; private set; } = true;
|
||||
protected IRigidBody2D? _rigidBody2D = null;
|
||||
|
||||
|
@@ -8,10 +8,8 @@ public class Collider2DCircleBehaviour : Collider2DBehaviourBase, ICircleCollide
|
||||
public Circle CircleWorld { get; protected set; } = Circle.UnitCircle;
|
||||
public Circle CircleLocal { get; set; } = Circle.UnitCircle;
|
||||
|
||||
|
||||
public override void CalculateCollider() => CircleWorld = Transform.TransformCircle(CircleLocal);
|
||||
|
||||
|
||||
public Collider2DCircleBehaviour() { }
|
||||
public Collider2DCircleBehaviour(Circle circle) => CircleLocal = circle;
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@ public class Collider2DShapeBehaviour : Collider2DBehaviourBase, IShapeCollider2
|
||||
|
||||
public override void CalculateCollider() => Transform.TransformShape(ShapeLocal, ref _shapeWorld);
|
||||
|
||||
|
||||
public Collider2DShapeBehaviour() { }
|
||||
public Collider2DShapeBehaviour(Shape shape) => ShapeLocal = shape;
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ public class CollisionDetector2D : ICollisionDetector2D
|
||||
|
||||
private static bool DetectShapeShapeOneWay(IShapeCollider2D left, IShapeCollider2D right, ref CollisionDetectionInformation collisionInformation)
|
||||
{
|
||||
var vertices = left.ShapeWorld.Vertices;
|
||||
System.Collections.Generic.IReadOnlyList<Vector2D> vertices = left.ShapeWorld.Vertices;
|
||||
int count = vertices.Count;
|
||||
|
||||
for (int indexProjection = 0; indexProjection < count; indexProjection++)
|
||||
@@ -66,7 +66,7 @@ public class CollisionDetector2D : ICollisionDetector2D
|
||||
{
|
||||
collisionInformation = default;
|
||||
|
||||
var vertices = shapeCollider.ShapeWorld.Vertices;
|
||||
System.Collections.Generic.IReadOnlyList<Vector2D> vertices = shapeCollider.ShapeWorld.Vertices;
|
||||
int count = vertices.Count;
|
||||
|
||||
for (int indexProjection = 0; indexProjection < count; indexProjection++)
|
||||
|
@@ -5,11 +5,11 @@ namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public static partial class Physics2D
|
||||
{
|
||||
public static bool Overlaps(this Shape shape, Vector2D point) => Overlaps(shape, point, out var _);
|
||||
public static bool Overlaps(this Shape shape, Vector2D point) => Overlaps(shape, point, out float _);
|
||||
public static bool Overlaps(this Shape shape, Vector2D point, out float depth)
|
||||
{
|
||||
depth = float.MaxValue;
|
||||
var vertices = shape.Vertices;
|
||||
System.Collections.Generic.IReadOnlyList<Vector2D> vertices = shape.Vertices;
|
||||
int count = vertices.Count;
|
||||
|
||||
for (int indexProjection = 0; indexProjection < count; indexProjection++)
|
||||
|
@@ -27,7 +27,7 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
||||
|
||||
rigidBodies.Add(rigidBody);
|
||||
|
||||
foreach (var collider2D in rigidBody.BehaviourController.GetBehaviours<ICollider2D>())
|
||||
foreach (ICollider2D collider2D in rigidBody.BehaviourController.GetBehaviours<ICollider2D>())
|
||||
colliders.Add(collider2D);
|
||||
|
||||
rigidBody.BehaviourController.OnBehaviourAdded += OnBehaviourAdded;
|
||||
@@ -50,7 +50,7 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
||||
StepRigidBody(rigidBodies[i], intervalDeltaTime);
|
||||
|
||||
// Can Parallel
|
||||
foreach (var collider in colliders)
|
||||
foreach (ICollider2D collider in colliders)
|
||||
collider.Recalculate();
|
||||
|
||||
// Can Parallel
|
||||
|
@@ -18,7 +18,6 @@ public class PhysicsEngine2DCollector : HierarchyObjectBase, IPhysicsEngine2D
|
||||
protected BehaviourCollector<ICollider2D> colliderCollector = new();
|
||||
protected BehaviourCollector<IPhysicsUpdate> physicsUpdateCollector = new();
|
||||
|
||||
|
||||
public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; }
|
||||
|
||||
public void Step(float deltaTime)
|
||||
@@ -28,11 +27,11 @@ public class PhysicsEngine2DCollector : HierarchyObjectBase, IPhysicsEngine2D
|
||||
for (int iterationIndex = 0; iterationIndex < IterationPerStep; iterationIndex++)
|
||||
{
|
||||
// Can Parallel
|
||||
foreach (var rigidBody in rigidBodyCollector)
|
||||
foreach (IRigidBody2D rigidBody in rigidBodyCollector)
|
||||
StepRigidBody(rigidBody, intervalDeltaTime);
|
||||
|
||||
// Can Parallel
|
||||
foreach (var collider in colliderCollector)
|
||||
foreach (ICollider2D collider in colliderCollector)
|
||||
collider.Recalculate();
|
||||
|
||||
// Can Parallel
|
||||
|
@@ -173,17 +173,13 @@ public readonly struct Line(Vector2D from, Vector2D to)
|
||||
/// </summary>
|
||||
public static Vector2D ClosestPointTo(Line line, Vector2D point)
|
||||
{
|
||||
// Convert edge points to vectors
|
||||
var edgeVector = new Vector2D(line.To.X - line.From.X, line.To.Y - line.From.Y);
|
||||
var pointVector = new Vector2D(point.X - line.From.X, point.Y - line.From.Y);
|
||||
Vector2D edgeVector = new(line.To.X - line.From.X, line.To.Y - line.From.Y);
|
||||
Vector2D pointVector = new(point.X - line.From.X, point.Y - line.From.Y);
|
||||
|
||||
// Calculate the projection of pointVector onto edgeVector
|
||||
float t = (pointVector.X * edgeVector.X + pointVector.Y * edgeVector.Y) / (edgeVector.X * edgeVector.X + edgeVector.Y * edgeVector.Y);
|
||||
|
||||
// Clamp t to the range [0, 1] to ensure the closest point is on the edge
|
||||
t = MathF.Max(0, MathF.Min(1, t));
|
||||
|
||||
// Calculate the closest point on the edge
|
||||
float closestX = line.From.X + t * edgeVector.X;
|
||||
float closestY = line.From.Y + t * edgeVector.Y;
|
||||
|
||||
@@ -207,13 +203,11 @@ public static class LineExtensions
|
||||
/// </summary>
|
||||
public static Vector2D Lerp(this Line line, float t) => Line.Lerp(line, t);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The equation of the <see cref="Line"/> defined by this <see cref="Line"/> segment.
|
||||
/// </summary>
|
||||
public static LineEquation ToLineEquation(this Line line) => Line.GetLineEquation(line);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified <see cref="Vector2D"/> lies on the <see cref="Line"/>.
|
||||
/// </summary>
|
||||
@@ -224,13 +218,11 @@ public static class LineExtensions
|
||||
/// </summary>
|
||||
public static float GetT(this Line line, Vector2D point) => Line.GetT(line, point);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the <see cref="Line"/> segment intersects with another <see cref="Line"/> segment.
|
||||
/// </summary>
|
||||
public static bool Intersects(this Line left, Line right) => Line.Intersects(left, right);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether two <see cref="Line"/> segments intersect.
|
||||
/// </summary>
|
||||
|
@@ -27,7 +27,7 @@ public readonly struct Projection(float min, float max)
|
||||
/// <param name="left">The first projection to check.</param>
|
||||
/// <param name="right">The second projection to check.</param>
|
||||
/// <returns><see cref="true"/> if the projections overlap; otherwise, <see cref="false"/>.</returns>
|
||||
public static bool Overlaps(Projection left, Projection right) => Overlaps(left, right, out var _);
|
||||
public static bool Overlaps(Projection left, Projection right) => Overlaps(left, right, out float _);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if two projections overlap and calculates the depth of the overlap.
|
||||
|
@@ -11,7 +11,6 @@ public class RigidBody2D : Behaviour, IRigidBody2D
|
||||
private const float LOWEST_ALLOWED_MASS = 0.00001f;
|
||||
private float _mass = 1f;
|
||||
|
||||
|
||||
public IPhysicsMaterial2D Material { get; set; } = new PhysicsMaterial2DDefault();
|
||||
|
||||
public Vector2D Velocity { get; set; } = Vector2D.Zero;
|
||||
@@ -22,6 +21,5 @@ public class RigidBody2D : Behaviour, IRigidBody2D
|
||||
|
||||
ITransform IAssignableTransform.Transform => Transform;
|
||||
|
||||
|
||||
public bool Assign(ITransform transform) => GameObject.Assign(transform);
|
||||
}
|
||||
|
Reference in New Issue
Block a user