Position class

An ordered pair representation (point, position, offset).

It differs from the default implementations provided (math.Point and ui.Offset) as it's mutable. Also, it offers helpful converters and a some useful methods for manipulation. It always uses double values to store the coordinates.

Constructors

Position(double x, double y)
Basic constructor
Position.empty()
Creates a point at the origin
Position.fromInts(int x, int y)
Creates converting integers to double. [...]
Position.fromOffset(Offset offset)
Creates using an ui.Offset
Position.fromPoint(Point<num> point)
Creates using an math.Point
Position.fromPosition(Position position)
Creates using another Position; i.e., clones this position. [...]
Position.fromSize(Size size)
Creates using an ui.Size
Position.fromVector(Vector2 vector)
Creates using a b2d.Vector2

Properties

hashCode int
The hash code for this object. [...]
read-only, override
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
x double
Coordinates
read / write
y double
Coordinates
read / write

Methods

add(Position other) Position
Adds the coordinates from another vector. [...]
angle() double
Returns the angle of this vector from origin in radians.
angleDeg() double
Returns the angle of this vector from origin in degrees.
angleFrom(Position other) double
Returns the angle of this vector from another Position in radians.
angleFromDeg(Position other) double
Returns the angle of this vector from another Position in degrees.
clone() Position
distance(Position other) double
div(double scalar) Position
dotProduct(Position p) double
equals(Position p) bool
length() double
The length (or magnitude) of this vector.
limit(double maxLength) Position
Limits the length of this vector to the one provided, without changing direction. [...]
minus(Position other) Position
Substracts the coordinates from another vector. [...]
normalize() Position
Normalizes this vector, without changing direction.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
opposite() Position
rotate(double angle) Position
Rotate around origin; angle in radians.
rotateDeg(double angle) Position
Rotate around origin; angle in degrees.
rotateDelta(double radians) Position
Change current rotation by delta angle; angle in radians.
rotateDeltaDeg(double degrees) Position
Change current rotation by delta angle; angle in degrees.
scaleTo(double newLength) Position
Changes the length of this vector to the one provided, without chaning direction. [...]
times(double scalar) Position
toOffset() Offset
toPoint() Point<num>
toSize() Size
toString() String
Returns a string representation of this object.
override
toVector() Vector2

Operators

operator *(double scale) Position
Scale.
operator +(Position other) Position
Add two vectors.
operator -(Position other) Position
Subtract two vectors.
operator /(double scale) Position
Scale.
operator ==(dynamic other) bool
The equality operator. [...]
override
operator unary-() Position
Negate.

Static Methods

bounds(List<Position> pts) Rect
rectFrom(Position topLeft, Position size) Rect