Vector2

csharp
public struct Vector2 : IEquatable<Vector2>, IFormattable

Namespace NodeWorld.Flux.

A point or a direction in 2D, as Unity's Vector2.

Constants

kEpsilon

csharp
public const float kEpsilon = 0.00001f

The tolerance of == and of normalized (0.00001).

Fields

x

csharp
public float x

The x component.

y

csharp
public float y

The y component.

Constructors

Vector2

csharp
public Vector2(float x, float y)

A vector of these components.

Properties

this[]

csharp
public float this[int index] { get; set; }

x, y by index 0 to 1.

zero

csharp
public static Vector2 zero { get; }

(0, 0).

one

csharp
public static Vector2 one { get; }

(1, 1).

up

csharp
public static Vector2 up { get; }

(0, 1): up.

down

csharp
public static Vector2 down { get; }

(0, -1): down.

left

csharp
public static Vector2 left { get; }

(-1, 0): left.

csharp
public static Vector2 right { get; }

(1, 0): right.

magnitude

csharp
public float magnitude { get; }

Length of the vector.

sqrMagnitude

csharp
public float sqrMagnitude { get; }

Squared length.

normalized

csharp
public Vector2 normalized { get; }

The vector at length 1 (zero when it is too short).

Methods

Normalize

csharp
public void Normalize()

Brings the vector to length 1 (zero when it is too short).

Set

csharp
public void Set(float newX, float newY)

Sets the two components.

Dot

csharp
public static float Dot(Vector2 lhs, Vector2 rhs)

Dot product.

Distance

csharp
public static float Distance(Vector2 a, Vector2 b)

Distance between two points.

Lerp

csharp
public static Vector2 Lerp(Vector2 a, Vector2 b, float t)

From a (t = 0) to b (t = 1); t is kept between 0 and 1.

LerpUnclamped

csharp
public static Vector2 LerpUnclamped(Vector2 a, Vector2 b, float t)

From a (t = 0) to b (t = 1); t is not limited.

Scale

csharp
public static Vector2 Scale(Vector2 a, Vector2 b)

a and b multiplied component by component.

Perpendicular

csharp
public static Vector2 Perpendicular(Vector2 inDirection)

inDirection turned 90 degrees counterclockwise.

Angle

csharp
public static float Angle(Vector2 from, Vector2 to)

Angle in degrees between two vectors, 0 to 180.

Equals

csharp
public bool Equals(Vector2 other)

The components are exactly equal.

csharp
public override bool Equals(object other)

other is a Vector2 with exactly the same components.

GetHashCode

csharp
public override int GetHashCode()

A hash of the components.

ToString

csharp
public override string ToString()

"(x, y)" with 2 decimals.

csharp
public string ToString(string format)

The same text with the numbers in format.

csharp
public string ToString(string format, IFormatProvider formatProvider)

The same text with the numbers in format (F2 when empty) and formatProvider (the invariant culture when null).

Operators

operator +

csharp
public static Vector2 operator +(Vector2 a, Vector2 b)

Sum.

operator -

csharp
public static Vector2 operator -(Vector2 a, Vector2 b)

Difference.

csharp
public static Vector2 operator -(Vector2 a)

The opposite vector.

operator *

csharp
public static Vector2 operator *(Vector2 a, float d)

Each component times d.

csharp
public static Vector2 operator *(float d, Vector2 a)

Each component times d.

operator /

csharp
public static Vector2 operator /(Vector2 a, float d)

Each component divided by d.

operator ==

csharp
public static bool operator ==(Vector2 lhs, Vector2 rhs)

Approximately equal: the squared distance is below 1e-10.

operator !=

csharp
public static bool operator !=(Vector2 lhs, Vector2 rhs)

Not approximately equal (see ==).