Table of Contents

Struct Vector

Namespace
Xui.Core.Math2D
Assembly
Core.dll

Represents a 2D vector with X and Y components, commonly used for geometric operations, layout math, and movement in 2D space.

public struct Vector
Inherited Members

Constructors

Vector(NFloat, NFloat)

Initializes a new instance of the Vector struct with the specified X and Y components.

public Vector(NFloat x, NFloat y)

Parameters

x NFloat

The horizontal component of the vector.

y NFloat

The vertical component of the vector.

Fields

Down

A unit vector pointing down (0, 1).

public static readonly Vector Down

Field Value

Vector

Left

A unit vector pointing left (-1, 0).

public static readonly Vector Left

Field Value

Vector

One

A unit vector (1, 1).

public static readonly Vector One

Field Value

Vector

Right

A unit vector pointing right (1, 0).

public static readonly Vector Right

Field Value

Vector

Up

A unit vector pointing up (0, -1).

public static readonly Vector Up

Field Value

Vector

X

The horizontal component of the vector.

public NFloat X

Field Value

NFloat

Y

The vertical component of the vector.

public NFloat Y

Field Value

NFloat

Zero

A zero vector (0, 0).

public static readonly Vector Zero

Field Value

Vector

Properties

ArcAngle

Gets the angle in radians between the vector and the positive X-axis, measured counter-clockwise in the range [-π, π].

public NFloat ArcAngle { get; }

Property Value

NFloat

The angle in radians between this vector and the X-axis.

Remarks

This is equivalent to calling Atan2(Y, X) and is commonly used to compute polar angles from directional vectors, such as when determining the angular position of a point on a circle or ellipse.

Magnitude

Returns the magnitude (length) of the vector.

public NFloat Magnitude { get; }

Property Value

NFloat

MagnitudeSquared

Returns the squared magnitude (length squared) of the vector. This avoids the square root computation used in Magnitude.

public NFloat MagnitudeSquared { get; }

Property Value

NFloat

Normalized

Returns a normalized (unit length) version of this vector.

public Vector Normalized { get; }

Property Value

Vector

PerpendicularCCW

Returns the vector rotated 90° counter-clockwise (CCW).

public Vector PerpendicularCCW { get; }

Property Value

Vector

PerpendicularCW

Returns the vector rotated 90° clockwise (CW).

public Vector PerpendicularCW { get; }

Property Value

Vector

Methods

Angle(NFloat)

Returns a unit vector rotated clockwise from the upward direction (0, 1) by the given angle (in radians).

public static Vector Angle(NFloat radians)

Parameters

radians NFloat

Returns

Vector

Angle(Vector)

Returns the clockwise angle (in radians) from the upward direction (0, 1) to the given vector.

public static NFloat Angle(Vector v)

Parameters

v Vector

Returns

NFloat

Angle(Vector, Vector)

Returns the signed angle (in radians) from lhs to rhs, clockwise from upward.

public static NFloat Angle(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

NFloat

Clamp(NFloat)

Returns a new vector with its magnitude limited to the specified maximum.

public Vector Clamp(NFloat max)

Parameters

max NFloat

Returns

Vector

Cross(Vector, Vector)

Returns the 2D cross product (scalar) of two vectors.

public static NFloat Cross(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

NFloat

Dot(Vector, Vector)

Returns the dot product of two vectors.

public static NFloat Dot(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

NFloat

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Equals(Vector)

Returns true if this vector is equal to another vector.

public bool Equals(Vector other)

Parameters

other Vector

Returns

bool

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Lerp(Vector, Vector, NFloat)

Linearly interpolates between two vectors by step.

public static Vector Lerp(Vector start, Vector end, NFloat step)

Parameters

start Vector
end Vector
step NFloat

Returns

Vector

Project(Vector, Vector)

Projects lhs onto rhs.

public static Vector Project(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

Vector

Rotate(NFloat)

Rotates the vector counterclockwise by the given angle (in degrees).

public Vector Rotate(NFloat degrees)

Parameters

degrees NFloat

Returns

Vector

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator +(Vector, Vector)

Adds two vectors.

public static Vector operator +(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

Vector

operator /(Vector, NFloat)

Divides a vector by a scalar.

public static Vector operator /(Vector v, NFloat f)

Parameters

v Vector
f NFloat

Returns

Vector

operator ==(Vector, Vector)

Returns true if the two vectors have equal components.

public static bool operator ==(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

bool

implicit operator Vector((NFloat, NFloat))

Implicitly converts a tuple to a Vector.

public static implicit operator Vector((NFloat, NFloat) tuple)

Parameters

tuple (NFloat horizontal, NFloat vertical)

Returns

Vector

implicit operator Vector(Point)

Implicitly converts a Point to a Vector.

public static implicit operator Vector(Point point)

Parameters

point Point

Returns

Vector

operator !=(Vector, Vector)

Returns true if any component of the two vectors is different.

public static bool operator !=(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

bool

operator *(NFloat, Vector)

Multiplies a scalar by a vector.

public static Vector operator *(NFloat f, Vector v)

Parameters

f NFloat
v Vector

Returns

Vector

operator *(Vector, NFloat)

Multiplies a vector by a scalar.

public static Vector operator *(Vector v, NFloat f)

Parameters

v Vector
f NFloat

Returns

Vector

operator -(Vector, Vector)

Subtracts one vector from another.

public static Vector operator -(Vector lhs, Vector rhs)

Parameters

lhs Vector
rhs Vector

Returns

Vector