Struct Vec2

Namespace
TDMaker.Core
Assembly
TDMaker.Core.dll

A simulation-space vector independent of any engine.

public readonly struct Vec2 : IEquatable<Vec2>
Implements
Inherited Members

Constructors

Vec2(float, float)

Creates a vector.

public Vec2(float x, float y)

Parameters

x float
y float

Fields

X

The horizontal coordinate.

public readonly float X

Field Value

float

Y

The vertical coordinate.

public readonly float Y

Field Value

float

Properties

Length

The Euclidean length.

public float Length { get; }

Property Value

float

LengthSquared

The squared Euclidean length.

public float LengthSquared { get; }

Property Value

float

Normalized

Returns a unit vector, or zero for a zero vector.

public Vec2 Normalized { get; }

Property Value

Vec2

Zero

The origin.

public static Vec2 Zero { get; }

Property Value

Vec2

Methods

DistanceSquared(Vec2, Vec2, float)

Measures squared distance using a vertical range multiplier.

public static float DistanceSquared(Vec2 a, Vec2 b, float yScale = 1)

Parameters

a Vec2
b Vec2
yScale float

Returns

float

Equals(object)

Compares coordinates exactly.

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

Equals(Vec2)

Compares coordinates exactly.

public bool Equals(Vec2 other)

Parameters

other Vec2

Returns

bool

GetHashCode()

Returns a coordinate hash.

public override int GetHashCode()

Returns

int

Lerp(Vec2, Vec2, float)

Interpolates between two positions.

public static Vec2 Lerp(Vec2 a, Vec2 b, float t)

Parameters

a Vec2
b Vec2
t float

Returns

Vec2

MoveTowards(Vec2, Vec2, float)

Moves towards a destination without overshooting it.

public static Vec2 MoveTowards(Vec2 from, Vec2 to, float distance)

Parameters

from Vec2
to Vec2
distance float

Returns

Vec2

ToString()

Formats the vector for diagnostics.

public override string ToString()

Returns

string

Operators

operator +(Vec2, Vec2)

Adds two vectors.

public static Vec2 operator +(Vec2 a, Vec2 b)

Parameters

a Vec2
b Vec2

Returns

Vec2

operator /(Vec2, float)

Divides a vector by a scalar.

public static Vec2 operator /(Vec2 a, float s)

Parameters

a Vec2
s float

Returns

Vec2

operator *(Vec2, float)

Scales a vector.

public static Vec2 operator *(Vec2 a, float s)

Parameters

a Vec2
s float

Returns

Vec2

operator -(Vec2, Vec2)

Subtracts two vectors.

public static Vec2 operator -(Vec2 a, Vec2 b)

Parameters

a Vec2
b Vec2

Returns

Vec2