Table of Contents

Struct Vector

Namespace
Avalonia
Assembly
Avalonia.Base.dll

Defines a vector.

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

Constructors

Vector(double, double)

Initializes a new instance of the Vector structure.

public Vector(double x, double y)

Parameters

x double

The X component.

y double

The Y component.

Properties

Length

Length of the vector.

public double Length { get; }

Property Value

double

One

Returns the vector (1.0, 1.0).

public static Vector One { get; }

Property Value

Vector

SquaredLength

Squared Length of the vector.

public double SquaredLength { get; }

Property Value

double

UnitX

Returns the vector (1.0, 0.0).

public static Vector UnitX { get; }

Property Value

Vector

UnitY

Returns the vector (0.0, 1.0).

public static Vector UnitY { get; }

Property Value

Vector

X

Gets the X component.

public double X { get; }

Property Value

double

Y

Gets the Y component.

public double Y { get; }

Property Value

double

Zero

Returns the vector (0.0, 0.0).

public static Vector Zero { get; }

Property Value

Vector

Methods

Abs()

Returns a vector whose elements are the absolute values of each of the specified vector's elements.

public Vector Abs()

Returns

Vector

Add(Vector, Vector)

Adds the second to the first vector

public static Vector Add(Vector a, Vector b)

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

Vector

The summed vector.

Clamp(Vector, Vector, Vector)

Restricts a vector between a minimum and a maximum value.

public static Vector Clamp(Vector value, Vector min, Vector max)

Parameters

value Vector
min Vector
max Vector

Returns

Vector

Cross(Vector, Vector)

Returns the cross product of two vectors.

public static double Cross(Vector a, Vector b)

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

double

The cross product.

Deconstruct(out double, out double)

Deconstructs the vector into its X and Y components.

public void Deconstruct(out double x, out double y)

Parameters

x double

The X component.

y double

The Y component.

Distance(Vector, Vector)

Computes the Euclidean distance between the two given points.

public static double Distance(Vector value1, Vector value2)

Parameters

value1 Vector

The first point.

value2 Vector

The second point.

Returns

double

The Euclidean distance.

DistanceSquared(Vector, Vector)

Returns the Euclidean distance squared between two specified points

public static double DistanceSquared(Vector value1, Vector value2)

Parameters

value1 Vector

The first point.

value2 Vector

The second point.

Returns

double

The Euclidean distance squared.

Divide(Vector, Vector)

Divides the first vector by the second.

public static Vector Divide(Vector a, Vector b)

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

Vector

The scaled vector.

Divide(Vector, double)

Divides the vector by the given scalar.

public static Vector Divide(Vector vector, double scalar)

Parameters

vector Vector

The vector

scalar double

The scalar value

Returns

Vector

The scaled vector.

Dot(Vector, Vector)

Returns the dot product of two vectors.

public static double Dot(Vector a, Vector b)

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

double

The dot product.

Equals(Vector)

Check if two vectors are equal (bitwise).

public bool Equals(Vector other)

Parameters

other Vector

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Max(Vector, Vector)

Returns a vector whose elements are the maximum of each of the pairs of elements in two specified vectors

public static Vector Max(Vector left, Vector right)

Parameters

left Vector
right Vector

Returns

Vector

Min(Vector, Vector)

Returns a vector whose elements are the minimum of each of the pairs of elements in two specified vectors

public static Vector Min(Vector left, Vector right)

Parameters

left Vector
right Vector

Returns

Vector

Multiply(Vector, Vector)

Multiplies the first vector by the second.

public static Vector Multiply(Vector a, Vector b)

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

Vector

The scaled vector.

Multiply(Vector, double)

Multiplies the vector by the given scalar.

public static Vector Multiply(Vector vector, double scalar)

Parameters

vector Vector

The vector

scalar double

The scalar value

Returns

Vector

The scaled vector.

NearlyEquals(Vector)

Check if two vectors are nearly equal (numerically).

public bool NearlyEquals(Vector other)

Parameters

other Vector

The other vector.

Returns

bool

True if vectors are nearly equal.

Negate()

Returns a negated version of this vector.

public Vector Negate()

Returns

Vector

The negated vector.

Negate(Vector)

Negates the vector

public static Vector Negate(Vector vector)

Parameters

vector Vector

The vector to negate.

Returns

Vector

The scaled vector.

Normalize()

Returns a normalized version of this vector.

public Vector Normalize()

Returns

Vector

The normalized vector.

Normalize(Vector)

Normalizes the given vector.

public static Vector Normalize(Vector vector)

Parameters

vector Vector

The vector

Returns

Vector

The normalized vector.

Parse(string)

Parses a Vector string.

public static Vector Parse(string s)

Parameters

s string

The string.

Returns

Vector

The Vector.

Subtract(Vector, Vector)

Subtracts the second from the first vector

public static Vector Subtract(Vector a, Vector b)

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

Vector

The difference vector.

ToString()

Returns the string representation of the vector.

public override string ToString()

Returns

string

The string representation of the vector.

WithX(double)

Returns a new vector with the specified X component.

public Vector WithX(double x)

Parameters

x double

The X component.

Returns

Vector

The new vector.

WithY(double)

Returns a new vector with the specified Y component.

public Vector WithY(double y)

Parameters

y double

The Y component.

Returns

Vector

The new vector.

Operators

operator +(Vector, Vector)

Adds two vectors.

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

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

Vector

A vector that is the result of the addition.

operator /(Vector, double)

Scales a vector.

public static Vector operator /(Vector vector, double scale)

Parameters

vector Vector

The vector.

scale double

The divisor.

Returns

Vector

The scaled vector.

operator ==(Vector, Vector)

public static bool operator ==(Vector left, Vector right)

Parameters

left Vector
right Vector

Returns

bool

explicit operator Point(Vector)

Converts the Vector to a Point.

public static explicit operator Point(Vector a)

Parameters

a Vector

The vector.

Returns

Point

implicit operator Vector(Vector2)

public static implicit operator Vector(Vector2 v)

Parameters

v Vector2

Returns

Vector

operator !=(Vector, Vector)

public static bool operator !=(Vector left, Vector right)

Parameters

left Vector
right Vector

Returns

bool

operator *(Vector, Vector)

Calculates the dot product of two vectors.

public static double operator *(Vector a, Vector b)

Parameters

a Vector

First vector.

b Vector

Second vector.

Returns

double

The dot product.

operator *(Vector, double)

Scales a vector.

public static Vector operator *(Vector vector, double scale)

Parameters

vector Vector

The vector.

scale double

The scaling factor.

Returns

Vector

The scaled vector.

operator *(double, Vector)

Scales a vector.

public static Vector operator *(double scale, Vector vector)

Parameters

scale double

The scaling factor.

vector Vector

The vector.

Returns

Vector

The scaled vector.

operator -(Vector, Vector)

Subtracts two vectors.

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

Parameters

a Vector

The first vector.

b Vector

The second vector.

Returns

Vector

A vector that is the result of the subtraction.

operator -(Vector)

Negates a vector.

public static Vector operator -(Vector a)

Parameters

a Vector

The vector.

Returns

Vector

The negated vector.