math.vector2
2D vector struct.
- struct Vector2(T) if (isNumeric!(T));
2D vector or point.
- T x;
X component of the vector.
- T y;
Y component of the vector.
- const pure Vector2 opNeg();
Negation.
- const pure bool opEquals(ref const Vector2 v);
Equality with a vector.
- const pure Vector2 opBinary(string op)(const Vector2 v);
Addition/subtraction with a vector.
- const pure Vector2 opBinary(string op, U)(const U m);
Multiplication/division with a scalar.
- const pure Vector2 opBinaryRight(string op, U)(const U m);
Multiplication/division with a scalar.
- pure void opOpAssign(string op)(const Vector2 v);
Addition/subtraction with a vector.
- void opOpAssign(string op, U)(const U m);
Multiplication/division with a scalar.
- const pure F angle(F = T)();
- pure void angle(F)(const F angle);
- pure void rotate(F)(const F angle);
Rotate by specified angle, in radians.
- const pure nothrow Vector2!(T) rotated(F)(const F angle);
- const pure nothrow T lengthSquared();
Get squared length of the vector.
- const pure nothrow T length();
- pure nothrow void length(T length);
Set length of the vector, resizing it but preserving its direction.
- const pure nothrow T dotProduct(const Vector2 v);
Dot (scalar) product with another vector.
Parameters:Returns:Vector2 v Vector to get dot product with. Dot product of this and the other vector.- const pure nothrow Vector2 normal();
- pure nothrow void normalize();
Turns this into a unit vector.
- const pure nothrow Vector2 normalized();
Get unit vector of this vector. Result is undefined if this is a zero vector.
- pure nothrow void setZero();
Turn this vector into a zero vector.
- const pure nothrow bool isZero();
Is this a zero vector?
- const pure nothrow Vector2!(T) to(T)();
Convert a Vector2 of one type to other.
Examples:Vector2u v_uint = Vector2u(4, 2); //convert to Vector2f Vector2f V_float = v_uint.to!float
- Vector2!(T) randomPosition(T)(Vector2!(T) center, T radius);
Return a random position in a circle.
Parameters:Returns:center Center of the circle. radius Radius of the circle. Random position in the specified circle.- Vector2!(T) randomDirection(T)();
Get a unit vector with a random direction.
- pure Vector2!(Unqual!(T)) angleToVector(T)(T angle);
Get a unit vector in direction of specified angle.
- alias Vector2b;
Vector2 of bytes.
- alias Vector2ub;
Vector2 of ubytes.
- alias Vector2s;
Vector2 of shorts.
- alias Vector2us;
Vector2 of ushorts.
- alias Vector2i;
Vector2 of ints.
- alias Vector2u;
Vector2 of uints.
- alias Vector2f;
Vector2 of floats.
- alias Vector2d;
Vector2 of doubles.