Pos class final Grids
An immutable 2D fixed-point vector.
This class could be used to represent a position in a 2D space, or a size.
Equality
Two points are considered equal if their x and y values are equal.
Example
Creating a position:
final pos = Pos(10, 20);
Using pattern matching to extract the x and y values in one statement:
final Pos(:x, :y) = pos;
- Implementers
- Annotations
-
- @immutable
Constructors
- Pos(int x, int y)
-
Creates a new position with the given x and y offsets.
const
- Pos.floor(double dx, double dy)
-
Creates a new position by flooring the given
dx
anddy
values.factory -
Pos.fromList(List<
int> list, [int start = 0]) -
Creates a new position from two elements of a list of integers.
factory
-
Pos.fromListUnsafe(List<
int> list, [int start = 0]) -
Creates a new position from two elements of a list of integers.
factory
- Pos.fromRowMajor(int index, {required int width})
-
Creates a position representing
index
in a grid ofwidth
columns.factory - Pos.fromXY((int, int) xy)
-
Creates a new position by destructuring a two-element tuple.
factory
- Pos.truncate(double dx, double dy)
-
Creates a new position by truncating the given
dx
anddy
values.factory
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- normalizedApproximate → Pos
-
Returns an approximate normalized vector represented by
this
.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- x → int
-
The x, or horizontal offset of this position.
final
- xy → (int, int)
-
this
as a tuple of two integers.no setter - y → int
-
The y, or vertical offset of this position.
final
Methods
-
abs(
) → Pos -
Returns a new position with the absolute value of
this
position. -
clamp(
Pos min, Pos max) → Pos -
Returns a new position with the offsets of
this
position clamped. -
cross(
Pos other) → int -
Returns the cross product of
this
andother
. -
distanceTo(
Pos other, {Distance using = distanceSquared}) → int -
Returns the distance between
this
andother
. -
dot(
Pos other) → int -
Returns the dot product of
this
andother
. -
inflate(
Pos delta) → Rect -
Returns
this
as a Rect.center of a rectangle expanded bydelta
. -
lineTo(
Pos other, {Path using = lineBresenham, bool exclusive = false}) → Iterable< Pos> -
Returns an iterable of positions that draws a line from
this
toother
. -
map(
int map(int offset)) → Pos -
Returns a new position with the
map
function applied to each offset. -
max(
Pos other) → Pos -
Returns a new position with offsets no less than
other
. -
midpoints(
Pos other) → List< Pos> -
Returns the middle positions between
this
andother
. -
min(
Pos other) → Pos -
Returns a new position with offsets no greater than
other
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pathTo(
Pos other, {Path using = lineBresenham, bool exclusive = false}) → Iterable< Pos> -
Returns an iterable of positions that draws a path from
this
toother
. -
pow(
int exponent) → Pos -
Returns a new position with offsets of
this
to the power ofexponent
. -
rotate180(
) → Pos - Returns this position rotated by 180 degrees.
-
rotate45(
[int steps = 1]) → Pos -
Returns this position rotated by 45 degrees
steps
times clockwise. -
rotate90(
[int steps = 1]) → Pos -
Returns this position rotated by 90 degrees
steps
times clockwise. -
scale(
Pos other) → Pos -
Returns a new position with the offsets of
this
scaled byother
. -
toList(
[List< int> ? output, int index = 0]) → List<int> -
Returns
this
as a list of two integers. -
toListUnsafe(
[List< int> ? output, int index = 0]) → List<int> -
Returns
this
as a list of two integers. -
toRect(
[Pos size = const Pos(1, 1)]) → Rect -
Returns
this
as a rectangle with a width and height of1
. -
toRowMajor(
{required int width}) → int -
Returns a row-major index of this position in a grid of
width
columns. -
toSize(
[Pos origin = Pos.zero]) → Rect -
Returns
this
as a sized rectangle with the origin atorigin
. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator %(
int scalar) → Pos -
Returns a new position with
this
position remainder divided byscalar
. -
operator &(
Pos other) → Pos -
Returns a new position with
this
position logical-ANDed withother
. -
operator *(
int scalar) → Pos -
Returns a new position with
this
position multiplied byscalar
. -
operator +(
Pos other) → Pos -
Returns a new position with
other
's offsets added tothis
. -
operator -(
Pos other) → Pos -
Returns a new position with
other
's offsets subtracted fromthis
. -
operator <<(
int shifts) → Pos -
Returns a new position with
this
position bit-shifted left byshifts
. -
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >>(
int shifts) → Pos -
Returns a new position with
this
position bit-shifted right byshifts
. -
operator ^(
Pos other) → Pos -
Returns a new position with
this
position logical-XORed withother
. -
operator unary-(
) → Pos -
Returns a new position with
this
position negated. -
operator |(
Pos other) → Pos -
Returns a new position with
this
position logical-ORed withother
. -
operator ~(
) → Pos -
Returns a new position with
this
position bit-wise negated. -
operator ~/(
int scalar) → Pos -
Returns a new position with
this
position floor divided byscalar
.
Static Methods
-
byDistanceTo(
Pos target, {Distance using = distanceSquared}) → Comparator< Pos> -
Returns a comparator that sorts positions by distance to
target
. -
byMagnitude(
[Distance formula = distanceSquared]) → Comparator< Pos> - Returns a comparator that sorts positions by distance from the origin.
Constants
-
byColumnMajor
→ const Comparator<
Pos> - A comparator that sorts positions by column-major order.
-
byRowMajor
→ const Comparator<
Pos> - A comparator that sorts positions by row-major order.
- zero → const Pos
- A position with x and y offsets set to zero, often used as the origin.