Struct Vector
- Namespace
- VirtualLabAPI.Core.Numerics
- Assembly
- VirtualLabAPI.dll
This struct defines a two-dimensional vector of integer numbers. Operators \(a+b\), \(a-b\) and \(a|b\) (Scalar product) can be used. One operand on \(a*b\) and \(a/b\) can be an integer too. Implicit casting to System.Drawing.Point and System.Drawing.Size is supported.
[Serializable]
public struct Vector
- Inherited Members
Constructors
Vector(int, int)
Creates a Vector from two int values.
public Vector(int x, int y)
Parameters
Vector(Vector)
Copy constructor.
public Vector(Vector v)
Parameters
vVectorVector to be copied.
Fields
MaxValue
A constant containing the minimum allowed vector.
public static readonly Vector MaxValue
Field Value
MinValue
A constant containing the minimum allowed vector.
public static readonly Vector MinValue
Field Value
UnitVectorX
A constant containing the unit vector in x-direction.
public static readonly Vector UnitVectorX
Field Value
UnitVectorY
A constant containing the unit vector in y-direction.
public static readonly Vector UnitVectorY
Field Value
X
x-value of the Vector object.
[NonSerialized]
public int X
Field Value
Y
y-value of the Vector object.
[NonSerialized]
public int Y
Field Value
ZeroVector
A constant containing the zero vector (0, 0).
public static readonly Vector ZeroVector
Field Value
Methods
Equals(object)
This function compares the values of this object and the object given as parameter for equality.
public override bool Equals(object obj)
Parameters
objobjectVector to be compared.
Returns
- bool
Returns true if both object pointers are equal.
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
Max(Vector)
Returns the largest component of a Vector.
public static int Max(Vector a)
Parameters
aVectorThe vector to check.
Returns
- int
The component of the vector having the largest value.
Parse(string)
Converts a string generated by the ToString method back into a Vector object.
public static Vector Parse(string stringToParse)
Parameters
stringToParsestringThe string to be parsed.
Returns
- Vector
A Vector object.
ToString()
Converts a Vector into a string of format (X; Y).
public override string ToString()
Returns
- string
String containing the Vector information.
Operators
operator +(Vector, Vector)
Adds two Vector objects.
public static Vector operator +(Vector a, Vector b)
Parameters
Returns
- Vector
Returns the sum of the two \markAsCode{Vector} objects.
operator |(Vector, Vector)
Calculates the scalar product of two Vector objects.
public static int operator |(Vector a, Vector b)
Parameters
Returns
- int
Scalar product of the two Vector objects.
operator /(int, Vector)
Performs a component-wise division of an int value and a Vector object.
The result is defined as new Vector(number / vector.X, number / vector.Y).
public static Vector operator /(int number, Vector vector)
Parameters
numberintThe integer value to divide by the components of the Vector object.
vectorVectorThe Vector object used as divisor.
Returns
- Vector
Returns the quotient of the integer value and the Vector object.
operator /(Vector, int)
Performs a component-wise division of a Vector object and an int value.
public static Vector operator /(Vector vector, int divisor)
Parameters
vectorVectorThe Vector object to divide by the integer value.
divisorintThe integer value used as divisor.
Returns
- Vector
Returns the quotient of the Vector object and the integer value.
operator /(Vector, Vector)
Performs a component-wise division of two Vector objects.
public static Vector operator /(Vector a, Vector b)
Parameters
aVectorThe first Vector object to divide by parameter b.
bVectorThe second Vector object used as divisor.
Returns
- Vector
Returns the quotient of the two Vector objects.
operator ==(Vector, Vector)
Compares two Vector for equality. The comparison will be done by comparing the values of the two x- and y-components, respectively.
public static bool operator ==(Vector vector1, Vector vector2)
Parameters
Returns
- bool
Returns true if the two objects are equal.
explicit operator Vector(VectorD)
public static explicit operator Vector(VectorD vector)
Parameters
vectorVectorDVectorD object to be converted.
Returns
- Vector
Converted Vector.
operator !=(Vector, Vector)
Compares two Vector for inequality. The comparison will be done by comparing the values of the two x- and y-components, respectively.
public static bool operator !=(Vector vector1, Vector vector2)
Parameters
Returns
- bool
Returns true if the two objects are unequal.
operator *(int, Vector)
Multiplies a Vector object with an int value.
public static Vector operator *(int factor, Vector vector)
Parameters
Returns
- Vector
Returns the product of the Vector object and the integer value.
operator *(Vector, int)
Multiplies a Vector object by an int value.
public static Vector operator *(Vector vector, int factor)
Parameters
Returns
- Vector
Returns the product of the Vector object and the integer value.
operator *(Vector, Vector)
Multiplies two Vector objects.
public static Vector operator *(Vector a, Vector b)
Parameters
Returns
- Vector
Returns the product of the two Vector objects.
operator -(Vector, Vector)
Subtracts two Vector objects.
public static Vector operator -(Vector a, Vector b)
Parameters
Returns
- Vector
Returns the difference of the two Vector objects.