Vector2
Sandbox.System
Derives from ValueType
Implements IEquatable<Vector2>

Constructors

Vector2( float x, float y, )

Initializes a 2D vector with given components.

Vector2( float all, )

Initializes the vector with all components set to the given value.

Initializes the 2D vector with components from given 3D vector, discarding the Z component.

Vector2( Vector2 v, )

Fields

static readonly Vector2 Down

Returns a 2D vector with Y set to -1. This represents the downwards direction in 2D space.

static readonly Vector2 Left

Returns a 2D vector with X set to 1. This represents the left hand direction in 2D space.

static readonly Vector2 One

Returns a 2D vector with every component set to 1

static readonly Vector2 Up

Returns a 2D vector with Y set to 1. This represents the upwards direction in 2D space.

static readonly Vector2 Zero

Returns a 2D vector with every component set to 0

Properties

static Vector2 Random { get; }

Returns a vector with each axis's value randomly set to values between -1 and 1

float Degrees { get; }

Return the angle of this vector in degrees, always between 0 and 360

bool IsNearZeroLength { get; }

Returns true if the squared length is less than 1e-8 (which is really near zero)

float Length { get; }

Returns the magnitude of the vector

float LengthSquared { get; }

This is faster than Length, so is better to use in certain circumstances

Vector2 Normal { get; }

Return the same vector but with a length of one

Returns a vector that runs perpendicular to this one

float x { get; set; }

X component of this Vector.

float y { get; set; }

Y component of this Vector.

Methods

static float Distance( in Vector2 a, in Vector2 b, )

Returns distance between the 2 given vectors.

static float DistanceBetween( Vector2 a, Vector2 b, )

Returns distance between the 2 given vectors.

static float DistanceBetweenSquared( Vector2 a, Vector2 b, )

Returns squared distance between the 2 given vectors. This is faster than DistanceBetween, and can be used for things like comparing distances, as long as only squared values are used.

static float DistanceSquared( in Vector2 a, in Vector2 b, )

Returns squared distance between the 2 given vectors. This is faster than DistanceBetween, and can be used for things like comparing distances, as long as only squared values are used.

static double Dot( Vector2 a, Vector2 b, )

Returns dot product between the 2 given vectors.

static Vector2 FromDegrees( float degrees, )

Returns a point on a circle at given rotation from X axis, counter clockwise.

static Vector2 FromRadians( float radians, )

Returns a point on a circle at given rotation from X axis, counter clockwise.

static Vector2 Lerp( Vector2 a, Vector2 b, float t, bool clamp = true, )

Linearly interpolate from point a to point b.

static Vector2 Lerp( Vector2 a, Vector2 b, Vector2 t, bool clamp = true, )

Linearly interpolate from point a to point b with separate fraction for each axis.

static Vector2 Max( Vector2 a, Vector2 b, )

Returns a vector that has the maximum values on each axis between the 2 given vectors.

static Vector2 Min( Vector2 a, Vector2 b, )

Returns a vector that has the minimum values on each axis between the 2 given vectors.

static Vector2 Parse( string str, )

Given a string, try to convert this into a vector4. Example formatting is "x,y", "[x,y]", "x y", etc.

static Vector2 Read( BinaryReader reader, )

Read a vector2 from given binary reader.

bool AlmostEqual( Vector2 v, float delta = 0.0001, )

Returns true if we're nearly equal to the passed vector.

Vector2 Clamp( Vector2 otherMin, Vector2 otherMax, )

Returns a vector each axis of which is clamped to between the 2 given vectors. Basically clamps a point to a square.

Vector2 Clamp( float min, float max, )

Returns a vector each axis of which is clamped to given min and max values.

Returns a vector that has the maximum values on each axis between this vector and given vector.

Returns a vector that has the minimum values on each axis between this vector and given vector.

float Distance( Vector2 target, )

Returns distance between this and given vectors.

float DistanceSquared( Vector2 target, )

Returns squared distance between the 2 given vectors. This is faster than Distance, and can be used for things like comparing distances, as long as only squared values are used.

Vector2 LerpTo( Vector2 target, float t, bool clamp = true, )

Linearly interpolate from this vector to given vector.

Vector2 LerpTo( Vector2 target, Vector2 t, bool clamp = true, )

Linearly interpolate from this vector to given vector with separate fraction for each axis.

Vector2 SnapToGrid( float gridSize, bool sx = true, bool sy = true, )

Snap to grid along all 3 axes.

Vector2 WithX( float x, )

Return this vector with given X.

Vector2 WithY( float y, )

Return this vector with given Y.

void Write( BinaryWriter writer, )

Write this vector2 to a System.IO.BinaryWriter.

override bool Equals( object obj, )
Overrides ValueType.Equals
override bool Equals( Vector2 o, )
Overrides ValueType.Equals
override int GetHashCode( )
Overrides ValueType.GetHashCode
override string ToString( )
Overrides ValueType.ToString

Operators

Vector2 +( Vector2 c1, Vector2 c2,  )
Vector2 /( Vector2 c1, Vector2 c2,  )
Vector2 /( Vector2 c1, float c2,  )
bool ==( Vector2 left, Vector2 right,  )
bool !=( Vector2 left, Vector2 right,  )
Vector2 *( Vector2 c1, float f,  )
Vector2 *( float f, Vector2 c1,  )
Vector2 *( Vector2 c1, Vector2 c2,  )
Vector2 -( Vector2 c1, Vector2 c2,  )
Vector2 -( Vector2 c1,  )
implicit Vector2 =( Vector2 value,  )
implicit Vector2 =( Vector2 value,  )
implicit Vector2 =( Vector3 value,  )
implicit Vector4 =( Vector2 value,  )
implicit Vector2 =( double value,  )