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
Properties
Length
Length of the vector.
public double Length { get; }
Property Value
One
Returns the vector (1.0, 1.0).
public static Vector One { get; }
Property Value
SquaredLength
Squared Length of the vector.
public double SquaredLength { get; }
Property Value
UnitX
Returns the vector (1.0, 0.0).
public static Vector UnitX { get; }
Property Value
UnitY
Returns the vector (0.0, 1.0).
public static Vector UnitY { get; }
Property Value
X
Gets the X component.
public double X { get; }
Property Value
Y
Gets the Y component.
public double Y { get; }
Property Value
Zero
Returns the vector (0.0, 0.0).
public static Vector Zero { get; }
Property Value
Methods
Abs()
Returns a vector whose elements are the absolute values of each of the specified vector's elements.
public Vector Abs()
Returns
Add(Vector, Vector)
Adds the second to the first vector
public static Vector Add(Vector a, Vector b)
Parameters
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
Returns
Cross(Vector, Vector)
Returns the cross product of two vectors.
public static double Cross(Vector a, Vector b)
Parameters
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
Distance(Vector, Vector)
Computes the Euclidean distance between the two given points.
public static double Distance(Vector value1, Vector value2)
Parameters
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
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
Returns
- Vector
The scaled vector.
Divide(Vector, double)
Divides the vector by the given scalar.
public static Vector Divide(Vector vector, double scalar)
Parameters
Returns
- Vector
The scaled vector.
Dot(Vector, Vector)
Returns the dot product of two vectors.
public static double Dot(Vector a, Vector b)
Parameters
Returns
- double
The dot product.
Equals(Vector)
Check if two vectors are equal (bitwise).
public bool Equals(Vector other)
Parameters
other
Vector
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
GetHashCode()
public override int GetHashCode()
Returns
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
Returns
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
Returns
Multiply(Vector, Vector)
Multiplies the first vector by the second.
public static Vector Multiply(Vector a, Vector b)
Parameters
Returns
- Vector
The scaled vector.
Multiply(Vector, double)
Multiplies the vector by the given scalar.
public static Vector Multiply(Vector vector, double scalar)
Parameters
Returns
- Vector
The scaled vector.
NearlyEquals(Vector)
Check if two vectors are nearly equal (numerically).
public bool NearlyEquals(Vector other)
Parameters
other
VectorThe 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
VectorThe 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
VectorThe vector
Returns
- Vector
The normalized vector.
Parse(string)
Parses a Vector string.
public static Vector Parse(string s)
Parameters
s
stringThe string.
Returns
Subtract(Vector, Vector)
Subtracts the second from the first vector
public static Vector Subtract(Vector a, Vector b)
Parameters
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
doubleThe 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
doubleThe Y component.
Returns
- Vector
The new vector.
Operators
operator +(Vector, Vector)
Adds two vectors.
public static Vector operator +(Vector a, Vector b)
Parameters
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
Returns
- Vector
The scaled vector.
operator ==(Vector, Vector)
public static bool operator ==(Vector left, Vector right)
Parameters
Returns
explicit operator Point(Vector)
public static explicit operator Point(Vector a)
Parameters
a
VectorThe vector.
Returns
implicit operator Vector(Vector2)
public static implicit operator Vector(Vector2 v)
Parameters
v
Vector2
Returns
operator !=(Vector, Vector)
public static bool operator !=(Vector left, Vector right)
Parameters
Returns
operator *(Vector, Vector)
Calculates the dot product of two vectors.
public static double operator *(Vector a, Vector b)
Parameters
Returns
- double
The dot product.
operator *(Vector, double)
Scales a vector.
public static Vector operator *(Vector vector, double scale)
Parameters
Returns
- Vector
The scaled vector.
operator *(double, Vector)
Scales a vector.
public static Vector operator *(double scale, Vector vector)
Parameters
Returns
- Vector
The scaled vector.
operator -(Vector, Vector)
Subtracts two vectors.
public static Vector operator -(Vector a, Vector b)
Parameters
Returns
- Vector
A vector that is the result of the subtraction.
operator -(Vector)
Negates a vector.
public static Vector operator -(Vector a)
Parameters
a
VectorThe vector.
Returns
- Vector
The negated vector.