Vector2 class
A mutable 2-D vector.
Constructors
- Vector2(double x, double y)
- Create a vector from components.
- Vector2.copy(Vector2 other)
- Copy constructor.
- Vector2.fromOffset(Offset o)
- Create from a Dart Offset.
- Vector2.zero()
- The zero vector.
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- length → double
-
Euclidean length.
no setter
- lengthSquared → double
-
Squared length (avoids sqrt).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- x ↔ double
-
X component.
getter/setter pair
- y ↔ double
-
Y component.
getter/setter pair
Methods
-
add(
Vector2 other) → void -
Add
otherin-place. -
addScaled(
Vector2 other, double scalar) → void -
this += other * scalar— the most common physics operation. -
cross(
Vector2 other) → double - 2-D cross product (returns scalar Z component).
-
distanceTo(
Vector2 other) → double -
Distance to
other. -
distanceToSquared(
Vector2 other) → double -
Distance squared to
other. -
dot(
Vector2 other) → double - Dot product.
-
negate(
) → void - Negate both components.
-
normalize(
) → double - Normalise in-place. Returns the original length.
-
normalized(
) → Vector2 -
Return a normalised copy without mutating
this. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
perpendicular(
) → Vector2 -
Return a new perpendicular Vec2 without mutating
this. -
scale(
double scalar) → void -
Multiply both components by
scalar. -
setFrom(
Vector2 other) → void -
Set to
other. -
setToPerpendicular(
) → void - Set to the right-perpendicular of the current value: (-y, x).
-
setValues(
double nx, double ny) → void -
Set to (
nx,ny). -
setZero(
) → void - Set to zero.
-
sub(
Vector2 other) → void -
Subtract
otherin-place. -
subScaled(
Vector2 other, double scalar) → void -
this -= other * scalar. -
toOffset(
) → Offset - Convert to an immutable Offset (for Canvas APIs).
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator *(
double s) → Vector2 -
operator +(
Vector2 other) → Vector2 - Create an operator-based copy.
-
operator -(
Vector2 other) → Vector2 -
operator /(
double s) → Vector2 -
operator ==(
Object other) → bool -
The equality operator.
override
-
operator unary-(
) → Vector2