Vector2 class
2D column vector.
- Implemented types
- Implementers
- Available extensions
Constructors
- Vector2(double x, double y)
-
Construct a new vector with the specified values.
factory
- Vector2.all(double value)
-
Splat
value
into all lanes of the vector.factory -
Vector2.array(List<
double> array, [int offset = 0]) -
Initialized with values from
array
starting atoffset
.factory - Vector2.copy(Vector2 other)
-
Copy of
other
.factory - Vector2.fromBuffer(ByteBuffer buffer, int offset)
-
Constructs Vector2 with a storage that views given
buffer
starting atoffset
.offset
has to be multiple of Float64List.bytesPerElement. - Vector2.fromFloat64List(Float64List _v2storage)
- Constructs Vector2 with a given Float64List as storage.
- Vector2.random([Random? rng])
-
Generate random vector in the range (0, 0) to (1, 1). You can
optionally pass your own random number generator.
factory
- Vector2.zero()
- Zero vector.
Properties
- g ↔ double
-
getter/setter pair
- gg → Vector2
-
no setter
- ggg → Vector3
-
no setter
- gggg → Vector4
-
no setter
- gggr → Vector4
-
no setter
- ggr → Vector3
-
no setter
- ggrg → Vector4
-
no setter
- ggrr → Vector4
-
no setter
- gr ↔ Vector2
-
getter/setter pair
- grg → Vector3
-
no setter
- grgg → Vector4
-
no setter
- grgr → Vector4
-
no setter
- grr → Vector3
-
no setter
- grrg → Vector4
-
no setter
- grrr → Vector4
-
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- isInfinite → bool
-
True if any component is infinite.
no setter
- isNaN → bool
-
True if any component is NaN.
no setter
- length ↔ double
-
Length.
getter/setter pair
- length2 → double
-
Length squared.
no setter
- r ↔ double
-
getter/setter pair
- rg ↔ Vector2
-
getter/setter pair
- rgg → Vector3
-
no setter
- rggg → Vector4
-
no setter
- rggr → Vector4
-
no setter
- rgr → Vector3
-
no setter
- rgrg → Vector4
-
no setter
- rgrr → Vector4
-
no setter
- rr → Vector2
-
no setter
- rrg → Vector3
-
no setter
- rrgg → Vector4
-
no setter
- rrgr → Vector4
-
no setter
- rrr → Vector3
-
no setter
- rrrg → Vector4
-
no setter
- rrrr → Vector4
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- s ↔ double
-
getter/setter pair
- ss → Vector2
-
no setter
- sss → Vector3
-
no setter
- ssss → Vector4
-
no setter
- ssst → Vector4
-
no setter
- sst → Vector3
-
no setter
- ssts → Vector4
-
no setter
- sstt → Vector4
-
no setter
- st ↔ Vector2
-
getter/setter pair
- storage → Float64List
-
The components of the vector.
no setteroverride
- sts → Vector3
-
no setter
- stss → Vector4
-
no setter
- stst → Vector4
-
no setter
- stt → Vector3
-
no setter
- stts → Vector4
-
no setter
- sttt → Vector4
-
no setter
- t ↔ double
-
getter/setter pair
- ts ↔ Vector2
-
getter/setter pair
- tss → Vector3
-
no setter
- tsss → Vector4
-
no setter
- tsst → Vector4
-
no setter
- tst → Vector3
-
no setter
- tsts → Vector4
-
no setter
- tstt → Vector4
-
no setter
- tt → Vector2
-
no setter
- tts → Vector3
-
no setter
- ttss → Vector4
-
no setter
- ttst → Vector4
-
no setter
- ttt → Vector3
-
no setter
- ttts → Vector4
-
no setter
- tttt → Vector4
-
no setter
- x ↔ double
-
getter/setter pair
- xx → Vector2
-
no setter
- xxx → Vector3
-
no setter
- xxxx → Vector4
-
no setter
- xxxy → Vector4
-
no setter
- xxy → Vector3
-
no setter
- xxyx → Vector4
-
no setter
- xxyy → Vector4
-
no setter
- xy ↔ Vector2
-
getter/setter pair
- xyx → Vector3
-
no setter
- xyxx → Vector4
-
no setter
- xyxy → Vector4
-
no setter
- xyy → Vector3
-
no setter
- xyyx → Vector4
-
no setter
- xyyy → Vector4
-
no setter
- y ↔ double
-
getter/setter pair
- yx ↔ Vector2
-
getter/setter pair
- yxx → Vector3
-
no setter
- yxxx → Vector4
-
no setter
- yxxy → Vector4
-
no setter
- yxy → Vector3
-
no setter
- yxyx → Vector4
-
no setter
- yxyy → Vector4
-
no setter
- yy → Vector2
-
no setter
- yyx → Vector3
-
no setter
- yyxx → Vector4
-
no setter
- yyxy → Vector4
-
no setter
- yyy → Vector3
-
no setter
- yyyx → Vector4
-
no setter
- yyyy → Vector4
-
no setter
Methods
-
absolute(
) → void - Absolute value.
-
absoluteError(
Vector2 correct) → double -
Absolute error between this and
correct
-
add(
Vector2 arg) → void -
Add
arg
to this. -
addScaled(
Vector2 arg, double factor) → void -
Add
arg
scaled byfactor
to this. -
angleTo(
Vector2 other) → double -
Returns the angle between this vector and
other
in radians. -
angleToSigned(
Vector2 other) → double -
Returns the signed angle between this and
other
in radians. -
ceil(
) → void - Ceil entries in this.
-
clamp(
Vector2 min, Vector2 max) → void -
Available on Vector2, provided by the Vector2Extension extension
Clamps this vector so that it is within or equals to the bounds defined bymin
andmax
. -
clamp(
Vector2 min, Vector2 max) → void -
Clamp each entry n in this in the range [min
n
]-[maxn
]. -
clampLength(
double min, double max) → void -
Available on Vector2, provided by the Vector2Extension extension
Clamps the length of this vector. -
clampScalar(
double min, double max) → void -
Clamp entries this in the range
min
-max
. -
clone(
) → Vector2 - Clone of this.
-
copyFromArray(
List< double> array, [int offset = 0]) → void -
Copies elements from
array
into this starting atoffset
. -
copyInto(
Vector2 arg) → Vector2 -
Copy this into
arg
. Returnsarg
. -
copyIntoArray(
List< double> array, [int offset = 0]) → void -
Copies this into
array
starting atoffset
. -
cross(
Vector2 other) → double - Cross product.
-
distanceTo(
Vector2 arg) → double -
Distance from this to
arg
-
distanceToSquared(
Vector2 arg) → double -
Squared distance from this to
arg
-
divide(
Vector2 arg) → void -
Divide entries in this with entries in
arg
. -
dot(
Vector2 other) → double - Inner product.
-
floor(
) → void - Floor entries in this.
-
invert(
) → void -
Available on Vector2, provided by the Vector2Extension extension
Inverts the vector. -
inverted(
) → Vector2 -
Available on Vector2, provided by the Vector2Extension extension
Returns the inverse of this vector. -
isIdentity(
) → bool -
Available on Vector2, provided by the Vector2Extension extension
Whether the Vector2 is the identity vector or not -
isZero(
) → bool -
Available on Vector2, provided by the Vector2Extension extension
Whether the Vector2 is the zero vector or not -
lerp(
Vector2 to, double t) → void -
Available on Vector2, provided by the Vector2Extension extension
Linearly interpolate towards another Vector2 -
moveToTarget(
Vector2 target, double ds) → void -
Available on Vector2, provided by the Vector2Extension extension
Smoothly moves this Vector2 in the directiontarget
by a displacement given by a distanceds
in that direction. -
multiply(
Vector2 arg) → void -
Multiply entries in this with entries in
arg
. -
negate(
) → void - Negate.
-
normalize(
) → double - Normalize this.
-
normalized(
) → Vector2 - Normalized copy of this.
-
normalizeInto(
Vector2 out) → Vector2 -
Normalize vector into
out
. -
normalizeLength(
) → double - Normalize this. Returns length of vector before normalization. DEPRECATED: Use normalize.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
postmultiply(
Matrix2 arg) → void -
Transforms this into the product of this as a row vector,
postmultiplied by matrix,
arg
. Ifarg
is a rotation matrix, this is a computational shortcut for applying, the inverse of the transformation. -
projection(
Vector2 other, {Vector2? out}) → Vector2 -
Available on Vector2, provided by the Vector2Extension extension
Project this ontoother
. -
reflect(
Vector2 normal) → void - Reflect this.
-
reflected(
Vector2 normal) → Vector2 - Reflected copy of this.
-
relativeError(
Vector2 correct) → double -
Relative error between this and
correct
-
rotate(
double angle, {Vector2? center}) → void -
Available on Vector2, provided by the Vector2Extension extension
Rotates the Vector2 withangle
in radians rotates aroundcenter
if it is defined In a screen coordinate system (where the y-axis is flipped) it rotates in a clockwise fashion In a normal coordinate system it rotates in a counter-clockwise fashion -
round(
) → void - Round entries in this.
-
roundToZero(
) → void - Round entries in this towards zero.
-
scale(
double arg) → void -
Scale this by
arg
. -
scaled(
double arg) → Vector2 -
Return a copy of this scaled by
arg
. -
scaleOrthogonalInto(
double scale, Vector2 out) → Vector2 -
Rotate this by 90 degrees then scale it. Store result in
out
. Returnout
. -
scaleTo(
double newLength) → void -
Available on Vector2, provided by the Vector2Extension extension
Changes the length of the vector to the length provided, without changing direction. -
screenAngle(
) → double -
Available on Vector2, provided by the Vector2Extension extension
Signed angle in a coordinate system where the Y-axis is flipped. -
setAll(
double value) → void -
Available on Vector2, provided by the Vector2Extension extension
Sets both x and y tovalue
. -
setFrom(
Vector2 other) → void -
Set the values by copying them from
other
. -
setValues(
double x_, double y_) → void - Set the values of the vector.
-
setZero(
) → void - Zero the vector.
-
splat(
double arg) → void -
Splat
arg
into all lanes of the vector. -
sub(
Vector2 arg) → void -
Subtract
arg
from this. -
taxicabDistanceTo(
Vector2 other) → double -
Available on Vector2, provided by the Vector2Extension extension
Distance toother
vector, using the taxicab (L1) geometry. -
toOffset(
) → Offset -
Available on Vector2, provided by the Vector2Extension extension
Creates an Offset from the Vector2 -
toPoint(
) → Point< num> -
Available on Vector2, provided by the Vector2Extension extension
Creates a Point from the Vector2 -
toPositionedRect(
Vector2 size) → Rect -
Available on Vector2, provided by the Vector2Extension extension
Creates a Rect starting from (x, y) and having the size of the argument Vector2 -
toRect(
) → Rect -
Available on Vector2, provided by the Vector2Extension extension
Creates a Rect starting in origin and going the Vector2 -
toSize(
) → Size -
Available on Vector2, provided by the Vector2Extension extension
Creates a Size from the Vector2 -
toString(
) → String -
Returns a printable string
override
-
toStringWithMaxPrecision(
int maxPrecision) → String -
Available on Vector2, provided by the Vector2Extension extension
Stringifies the Vector2 with a maximum precision ofmaxPrecision
. -
translate(
double x, double y) → void -
Available on Vector2, provided by the Vector2Extension extension
Translates this Vector2 byx
andy
. -
translated(
double x, double y) → Vector2 -
Available on Vector2, provided by the Vector2Extension extension
Creates a new Vector2 that is the current Vector2 translated byx
andy
.
Operators
-
operator %(
Vector2 mod) → Vector2 -
Available on Vector2, provided by the Vector2Extension extension
Modulo/Remainder -
operator &(
Vector2 size) → Rect -
Available on Vector2, provided by the Vector2Extension extension
A rectangle constructor operator. -
operator *(
double scale) → Vector2 - Scale.
-
operator +(
Vector2 other) → Vector2 - Add two vectors.
-
operator -(
Vector2 other) → Vector2 - Subtract two vectors.
-
operator /(
double scale) → Vector2 - Scale.
-
operator ==(
Object other) → bool -
Check if two vectors are the same.
override
-
operator [](
int i) → double -
Access the component of the vector at the index
i
. -
operator []=(
int i, double v) → void -
Set the component of the vector at the index
i
. -
operator unary-(
) → Vector2 - Negate.
Static Methods
-
max(
Vector2 a, Vector2 b, Vector2 result) → void -
Set the values of
result
to the maximum ofa
andb
for each line. -
min(
Vector2 a, Vector2 b, Vector2 result) → void -
Set the values of
result
to the minimum ofa
andb
for each line. -
mix(
Vector2 min, Vector2 max, double a, Vector2 result) → void -
Interpolate between
min
andmax
with the amount ofa
using a linear interpolation and store the values inresult
.