perf: Drastically Improved Memory Usage
TIL, records are not value types and are actually just reference types. So I was pretty much allocating from heap every time I used any of my data types (Like Vector2D). Needless to say, they are all now readonly structs as I originally intended them to be.
This commit is contained in:
@@ -6,12 +6,15 @@ using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D.Primitives;
|
||||
|
||||
public record Line(Vector2D From, Vector2D To)
|
||||
public readonly struct Line(Vector2D From, Vector2D To)
|
||||
{
|
||||
public Line Reversed => new(To, From);
|
||||
public Vector2D Direction => From.FromTo(To).Normalize();
|
||||
public float Length => From.FromTo(To).Length();
|
||||
public float LengthSquared => From.FromTo(To).LengthSquared();
|
||||
public readonly Vector2D From { get; init; } = From;
|
||||
public readonly Vector2D To { get; init; } = To;
|
||||
|
||||
public readonly Line Reversed => new(To, From);
|
||||
public readonly Vector2D Direction => From.FromTo(To).Normalize();
|
||||
public readonly float Length => From.FromTo(To).Length();
|
||||
public readonly float LengthSquared => From.FromTo(To).LengthSquared();
|
||||
|
||||
public static LineEquation GetLineEquation(Line line)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user