Vector2
public struct Vector2 : IEquatable<Vector2>, IFormattableNamespace NodeWorld.Flux.
A point or a direction in 2D, as Unity's Vector2.
Constants
kEpsilon
public const float kEpsilon = 0.00001fThe tolerance of == and of normalized (0.00001).
Fields
x
public float xThe x component.
y
public float yThe y component.
Constructors
Vector2
public Vector2(float x, float y)A vector of these components.
Properties
this[]
public float this[int index] { get; set; }x, y by index 0 to 1.
zero
public static Vector2 zero { get; }(0, 0).
one
public static Vector2 one { get; }(1, 1).
up
public static Vector2 up { get; }(0, 1): up.
down
public static Vector2 down { get; }(0, -1): down.
left
public static Vector2 left { get; }(-1, 0): left.
right
public static Vector2 right { get; }(1, 0): right.
magnitude
public float magnitude { get; }Length of the vector.
sqrMagnitude
public float sqrMagnitude { get; }Squared length.
normalized
public Vector2 normalized { get; }The vector at length 1 (zero when it is too short).
Methods
Normalize
public void Normalize()Brings the vector to length 1 (zero when it is too short).
Set
public void Set(float newX, float newY)Sets the two components.
Dot
public static float Dot(Vector2 lhs, Vector2 rhs)Dot product.
Distance
public static float Distance(Vector2 a, Vector2 b)Distance between two points.
Lerp
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
public static Vector2 LerpUnclamped(Vector2 a, Vector2 b, float t)From a (t = 0) to b (t = 1); t is not limited.
Scale
public static Vector2 Scale(Vector2 a, Vector2 b)a and b multiplied component by component.
Perpendicular
public static Vector2 Perpendicular(Vector2 inDirection)inDirection turned 90 degrees counterclockwise.
Angle
public static float Angle(Vector2 from, Vector2 to)Angle in degrees between two vectors, 0 to 180.
Equals
public bool Equals(Vector2 other)The components are exactly equal.
public override bool Equals(object other)other is a Vector2 with exactly the same components.
GetHashCode
public override int GetHashCode()A hash of the components.
ToString
public override string ToString()"(x, y)" with 2 decimals.
public string ToString(string format)The same text with the numbers in format.
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 +
public static Vector2 operator +(Vector2 a, Vector2 b)Sum.
operator -
public static Vector2 operator -(Vector2 a, Vector2 b)Difference.
public static Vector2 operator -(Vector2 a)The opposite vector.
operator *
public static Vector2 operator *(Vector2 a, float d)Each component times d.
public static Vector2 operator *(float d, Vector2 a)Each component times d.
operator /
public static Vector2 operator /(Vector2 a, float d)Each component divided by d.
operator ==
public static bool operator ==(Vector2 lhs, Vector2 rhs)Approximately equal: the squared distance is below 1e-10.
operator !=
public static bool operator !=(Vector2 lhs, Vector2 rhs)Not approximately equal (see ==).
