refactor: code styles enforced with .editorconfig
This commit is contained in:
parent
d71c135491
commit
9af44d48b3
225
.editorconfig
Normal file
225
.editorconfig
Normal file
@ -0,0 +1,225 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Don't use tabs for indentation.
|
||||
[*]
|
||||
indent_style = space
|
||||
# (Please don't specify an indent_size here; that has too many unintended consequences.)
|
||||
spelling_exclusion_path = SpellingExclusions.dic
|
||||
|
||||
# Code files
|
||||
[*.{cs,csx,vb,vbx}]
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
charset = utf-8-bom
|
||||
|
||||
# XML project files
|
||||
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
|
||||
indent_size = 2
|
||||
|
||||
# XML config files
|
||||
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
|
||||
indent_size = 2
|
||||
|
||||
# JSON files
|
||||
[*.json]
|
||||
indent_size = 2
|
||||
|
||||
# Powershell files
|
||||
[*.ps1]
|
||||
indent_size = 2
|
||||
|
||||
# Shell script files
|
||||
[*.sh]
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
|
||||
# Dotnet code style settings:
|
||||
[*.{cs,vb}]
|
||||
|
||||
# Sort using and Import directives with System.* appearing first
|
||||
dotnet_sort_system_directives_first = true
|
||||
dotnet_separate_import_directive_groups = false
|
||||
# Avoid "this." and "Me." if not necessary
|
||||
dotnet_style_qualification_for_field = false:refactoring
|
||||
dotnet_style_qualification_for_property = false:refactoring
|
||||
dotnet_style_qualification_for_method = false:refactoring
|
||||
dotnet_style_qualification_for_event = false:refactoring
|
||||
|
||||
# Use language keywords instead of framework type names for type references
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
|
||||
dotnet_style_predefined_type_for_member_access = true:suggestion
|
||||
|
||||
# Suggest more modern language features when available
|
||||
dotnet_style_object_initializer = true:suggestion
|
||||
dotnet_style_collection_initializer = true:suggestion
|
||||
dotnet_style_coalesce_expression = true:none
|
||||
dotnet_style_null_propagation = true:suggestion
|
||||
dotnet_style_explicit_tuple_names = true:suggestion
|
||||
|
||||
# Whitespace options
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = false:error
|
||||
|
||||
# IDE0055: Fix formatting
|
||||
# Workaround for https://github.com/dotnet/roslyn/issues/70570
|
||||
dotnet_diagnostic.IDE0055.severity = suggestion
|
||||
|
||||
# https://github.com/dotnet/roslyn-analyzers/issues/7436 - False positives from valid GetDeclaredSymbol calls
|
||||
dotnet_diagnostic.RS1039.severity = none
|
||||
|
||||
# CSharp code style settings:
|
||||
|
||||
# IDE0029: Use coalesce expression
|
||||
dotnet_diagnostic.IDE0029.severity = none
|
||||
|
||||
# IDE0040: Add accessibility modifiers
|
||||
dotnet_diagnostic.IDE0040.severity = warning
|
||||
|
||||
[*.cs]
|
||||
# Newline settings
|
||||
csharp_new_line_before_open_brace = all
|
||||
csharp_new_line_before_else = true
|
||||
csharp_new_line_before_catch = true
|
||||
csharp_new_line_before_finally = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
|
||||
# Indentation preferences
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = true
|
||||
csharp_indent_switch_labels = true
|
||||
csharp_indent_labels = flush_left
|
||||
|
||||
# Whitespace options
|
||||
csharp_style_allow_embedded_statements_on_same_line_experimental = true
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:error
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
|
||||
|
||||
# Prefer "var" everywhere
|
||||
csharp_style_var_for_built_in_types = false:warning
|
||||
csharp_style_var_when_type_is_apparent = false:warning
|
||||
csharp_style_var_elsewhere = false:warning
|
||||
|
||||
# Prefer method-like constructs to have a block body
|
||||
csharp_style_expression_bodied_methods = false:none
|
||||
csharp_style_expression_bodied_constructors = false:none
|
||||
csharp_style_expression_bodied_operators = false:none
|
||||
|
||||
# Prefer property-like constructs to have an expression-body
|
||||
csharp_style_expression_bodied_properties = true:none
|
||||
csharp_style_expression_bodied_indexers = true:none
|
||||
csharp_style_expression_bodied_accessors = true:none
|
||||
|
||||
# Suggest more modern language features when available
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
|
||||
csharp_style_inlined_variable_declaration = true:suggestion
|
||||
csharp_style_throw_expression = true:suggestion
|
||||
csharp_style_conditional_delegate_call = true:suggestion
|
||||
csharp_style_prefer_extended_property_pattern = true:suggestion
|
||||
|
||||
# Space preferences
|
||||
csharp_space_after_cast = false
|
||||
csharp_space_after_colon_in_inheritance_clause = true
|
||||
csharp_space_after_comma = true
|
||||
csharp_space_after_dot = false
|
||||
csharp_space_after_keywords_in_control_flow_statements = true
|
||||
csharp_space_after_semicolon_in_for_statement = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = do_not_ignore
|
||||
csharp_space_before_colon_in_inheritance_clause = true
|
||||
csharp_space_before_comma = false
|
||||
csharp_space_before_dot = false
|
||||
csharp_space_before_open_square_brackets = false
|
||||
csharp_space_before_semicolon_in_for_statement = false
|
||||
csharp_space_between_empty_square_brackets = false
|
||||
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_name_and_open_parenthesis = false
|
||||
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||
csharp_space_between_parentheses = false
|
||||
csharp_space_between_square_brackets = false
|
||||
|
||||
# Blocks are allowed
|
||||
csharp_prefer_braces = true:silent
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = true
|
||||
|
||||
# IDE0060: Remove unused parameter
|
||||
dotnet_diagnostic.IDE0060.severity = warning
|
||||
|
||||
[src/{Compilers,ExpressionEvaluator,Scripting}/**Test**/*.{cs,vb}]
|
||||
|
||||
# IDE0060: Remove unused parameter
|
||||
dotnet_diagnostic.IDE0060.severity = none
|
||||
|
||||
[src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures,VisualStudio}/**/*.{cs,vb}]
|
||||
|
||||
# IDE0011: Add braces
|
||||
csharp_prefer_braces = false:warning
|
||||
# NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201
|
||||
dotnet_diagnostic.IDE0011.severity = warning
|
||||
|
||||
# IDE0040: Add accessibility modifiers
|
||||
dotnet_diagnostic.IDE0040.severity = warning
|
||||
|
||||
# IDE0052: Remove unread private member
|
||||
dotnet_diagnostic.IDE0052.severity = warning
|
||||
|
||||
# IDE0059: Unnecessary assignment to a value
|
||||
dotnet_diagnostic.IDE0059.severity = warning
|
||||
|
||||
# CA1012: Abstract types should not have public constructors
|
||||
dotnet_diagnostic.CA1012.severity = warning
|
||||
|
||||
# CA1822: Make member static
|
||||
dotnet_diagnostic.CA1822.severity = warning
|
||||
|
||||
# Prefer "var" everywhere
|
||||
dotnet_diagnostic.IDE0007.severity = warning
|
||||
csharp_style_var_for_built_in_types = false:warning
|
||||
csharp_style_var_when_type_is_apparent = false:warning
|
||||
csharp_style_var_elsewhere = false:warning
|
||||
|
||||
# csharp_style_allow_embedded_statements_on_same_line_experimental
|
||||
dotnet_diagnostic.IDE2001.severity = warning
|
||||
|
||||
# csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental
|
||||
dotnet_diagnostic.IDE2004.severity = warning
|
||||
|
||||
# csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental
|
||||
dotnet_diagnostic.IDE2005.severity = warning
|
||||
|
||||
# csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental
|
||||
dotnet_diagnostic.IDE2006.severity = warning
|
||||
|
||||
[src/{VisualStudio}/**/*.{cs,vb}]
|
||||
# CA1822: Make member static
|
||||
# There is a risk of accidentally breaking an internal API that partners rely on though IVT.
|
||||
dotnet_code_quality.CA1822.api_surface = private
|
||||
|
||||
[**/{ExternalAccess}/**/*.{cs,vb}]
|
||||
|
||||
# RS0016: Only enable if API files are present
|
||||
dotnet_public_api_analyzer.require_api_files = true
|
||||
|
||||
dotnet_diagnostic.RS0051.severity = error
|
||||
dotnet_diagnostic.RS0052.severity = error
|
||||
dotnet_diagnostic.RS0053.severity = error
|
||||
dotnet_diagnostic.RS0054.severity = error
|
||||
dotnet_diagnostic.RS0055.severity = error
|
||||
dotnet_diagnostic.RS0056.severity = error
|
||||
dotnet_diagnostic.RS0057.severity = error
|
||||
dotnet_diagnostic.RS0058.severity = error
|
||||
dotnet_diagnostic.RS0059.severity = error
|
||||
dotnet_diagnostic.RS0060.severity = error
|
||||
dotnet_diagnostic.RS0061.severity = error
|
@ -14,7 +14,6 @@ public abstract class BaseEntity : IEntity
|
||||
public event IAssignableStateEnable.OnStateEnableAssignedEventHandler? OnStateEnableAssigned = null;
|
||||
public event IAssignable.OnUnassignedEventHandler? OnUnassigned = null;
|
||||
|
||||
|
||||
private IStateEnable _stateEnable = null!;
|
||||
|
||||
private bool _initialized = false;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
public interface ICoroutineYield
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
@ -10,12 +10,10 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
|
||||
|
||||
public event IBehaviour.OnPriorityChangedEventHandler? OnPriorityChanged = null;
|
||||
|
||||
|
||||
private IBehaviourController _behaviourController = null!;
|
||||
|
||||
private int _priority = 0;
|
||||
|
||||
|
||||
public IBehaviourController BehaviourController => _behaviourController;
|
||||
|
||||
public override bool IsActive => base.IsActive && BehaviourController.GameObject.StateEnable.Enabled;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
@ -32,7 +31,6 @@ public class BehaviourController : IBehaviourController
|
||||
|
||||
public IGameObject GameObject => _gameObject;
|
||||
|
||||
|
||||
public bool IsInitialized
|
||||
{
|
||||
get => _initialized;
|
||||
@ -67,7 +65,7 @@ public class BehaviourController : IBehaviourController
|
||||
|
||||
public T? GetBehaviour<T>()
|
||||
{
|
||||
foreach (var behaviourItem in behaviours)
|
||||
foreach (IBehaviour behaviourItem in behaviours)
|
||||
if (behaviourItem is T result)
|
||||
return result;
|
||||
|
||||
@ -77,7 +75,7 @@ public class BehaviourController : IBehaviourController
|
||||
public IList<T> GetBehaviours<T>()
|
||||
{
|
||||
List<T>? behaviours = null;
|
||||
foreach (var behaviourItem in this.behaviours)
|
||||
foreach (IBehaviour behaviourItem in this.behaviours)
|
||||
{
|
||||
if (behaviourItem is not T behaviour)
|
||||
continue;
|
||||
@ -92,7 +90,7 @@ public class BehaviourController : IBehaviourController
|
||||
public void GetBehaviours<T>(IList<T> results)
|
||||
{
|
||||
results.Clear();
|
||||
foreach (var behaviourItem in behaviours)
|
||||
foreach (IBehaviour behaviourItem in behaviours)
|
||||
{
|
||||
if (behaviourItem is not T behaviour)
|
||||
continue;
|
||||
@ -136,7 +134,6 @@ public class BehaviourController : IBehaviourController
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool Initialize()
|
||||
{
|
||||
if (IsInitialized)
|
||||
@ -210,7 +207,6 @@ public class BehaviourController : IBehaviourController
|
||||
behaviours.Add(behaviour);
|
||||
}
|
||||
|
||||
|
||||
private void OnPriorityChange(IBehaviour sender, int previousPriority)
|
||||
{
|
||||
behaviours.Remove(sender);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
@ -11,7 +10,7 @@ public class AssignException : Exception
|
||||
// public static AssignException FromStateEnable(IStateEnable? stateEnable)
|
||||
// => new AssignException($"{nameof(IGameObject.AssignStateEnable)} failed on type {stateEnable?.GetType().ToString() ?? "\"null\""}");
|
||||
public static AssignException From<T, T2>(T to, T2? value)
|
||||
=> new AssignException($"Assign operation has failed on T: {typeof(T).FullName}, value: {value?.GetType().ToString() ?? "\"null\""}");
|
||||
=> new($"Assign operation has failed on T: {typeof(T).FullName}, value: {value?.GetType().ToString() ?? "\"null\""}");
|
||||
// public static AssignException FromBehaviourController(IBehaviourController? behaviourController)
|
||||
// => new AssignException($"{nameof(IGameObject.AssignBehaviourController)} failed on type {behaviourController?.GetType().ToString() ?? "\"null\""}");
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ public class NotAssignedException : Exception
|
||||
public NotAssignedException(string? message) : base(message) { }
|
||||
|
||||
public static NotAssignedException From<T1, T2>(T1 to, T2? value) where T1 : IAssignable
|
||||
=> new NotAssignedException($"{typeof(T2).Name} has not been assigned to {typeof(T1).Name}");
|
||||
=> new($"{typeof(T2).Name} has not been assigned to {typeof(T1).Name}");
|
||||
|
||||
public static void Check<T1, T2>(T1 to, T2? value) where T1 : IAssignable
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
@ -102,7 +101,7 @@ public class GameManager : BaseEntity, IGameManager
|
||||
base.InitializeInternal();
|
||||
NotAssignedException.Check(this, StateEnable);
|
||||
|
||||
foreach (var gameObject in GameObjects)
|
||||
foreach (IGameObject gameObject in GameObjects)
|
||||
gameObject.Initialize();
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ public class Transform : ITransform
|
||||
public event ITransform.OnChildrenAddedEventHandler? OnChildrenAdded = null;
|
||||
public event ITransform.OnChildrenRemovedEventHandler? OnChildrenRemoved = null;
|
||||
|
||||
|
||||
private Vector2D _position = Vector2D.Zero;
|
||||
private Vector2D _scale = Vector2D.One;
|
||||
private float _rotation = 0f;
|
||||
@ -179,7 +178,7 @@ public class Transform : ITransform
|
||||
{
|
||||
// TODO No idea how logical this is to propagate this to the children the way I'm doing right now.
|
||||
// I was originally gonna just call `child.OnParentChanged?.Invoke(child, child.Parent);` but seems an unnecessary call too?
|
||||
foreach (var child in Children) // TODO CHECK ERRORS
|
||||
foreach (ITransform child in Children) // TODO CHECK ERRORS
|
||||
child.SetParent(this);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user