Direction extension type Graphs Grids

A direction in a 2D space.

This class represents a direction in a 2D space, with a fixed distance of 1 unit. The direction can be one of the four cardinal directions, or one of four ordinal directions, or all eight values.

on
Implemented types

Properties

hashCode int
The hash code for this object.
no setterinherited
isCardinal bool
Whether this direction is a cardinal, or horizontal/vertical direction.
no setter
isOrdinal bool
Whether this direction is an ordinal, or diagonal direction.
no setter
normalizedApproximate Pos
Returns an approximate normalized vector represented by this.
no setterinherited
opposite Direction
The direction that is 180° opposite to this direction.
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.
finalinherited
xy → (int, int)
this as a tuple of two integers.
no setterinherited
y int
The y, or vertical offset of this position.
finalinherited

Methods

abs() Pos
Returns a new position with the absolute value of this position.
inherited
clamp(Pos min, Pos max) Pos
Returns a new position with the offsets of this position clamped.
inherited
cross(Pos other) int
Returns the cross product of this and other.
inherited
distanceTo(Pos other, {Distance using = distanceSquared}) int
Returns the distance between this and other.
inherited
dot(Pos other) int
Returns the dot product of this and other.
inherited
inflate(Pos delta) Rect
Returns this as a Rect.center of a rectangle expanded by delta.
inherited
lineTo(Pos other, {Path using = lineBresenham, bool exclusive = false}) Iterable<Pos>
Returns an iterable of positions that draws a line from this to other.
inherited
map(int map(int offset)) Pos
Returns a new position with the map function applied to each offset.
inherited
max(Pos other) Pos
Returns a new position with offsets no less than other.
inherited
midpoints(Pos other) List<Pos>
Returns the middle positions between this and other.
inherited
min(Pos other) Pos
Returns a new position with offsets no greater than other.
inherited
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 to other.
inherited
pow(int exponent) Pos
Returns a new position with offsets of this to the power of exponent.
inherited
rotate180() Direction
Returns this position rotated by 180 degrees.
override
rotate45([int steps = 1]) Pos
Returns this position rotated by 45 degrees steps times clockwise.
inherited
rotate90([int steps = 1]) Direction
Returns this position rotated by 90 degrees steps times clockwise.
override
scale(Pos other) Pos
Returns a new position with the offsets of this scaled by other.
inherited
toList([List<int>? output, int index = 0]) List<int>
Returns this as a list of two integers.
inherited
toListUnsafe([List<int>? output, int index = 0]) List<int>
Returns this as a list of two integers.
inherited
toRect([Pos size = const Pos(1, 1)]) Rect
Returns this as a rectangle with a width and height of 1.
inherited
toRowMajor({required int width}) int
Returns a row-major index of this position in a grid of width columns.
inherited
toSize([Pos origin = Pos.zero]) Rect
Returns this as a sized rectangle with the origin at origin.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator %(int scalar) Pos
Returns a new position with this position remainder divided by scalar.
inherited
operator &(Pos other) Pos
Returns a new position with this position logical-ANDed with other.
inherited
operator *(int scalar) Pos
Returns a new position with this position multiplied by scalar.
inherited
operator +(Pos other) Pos
Returns a new position with other's offsets added to this.
inherited
operator -(Pos other) Pos
Returns a new position with other's offsets subtracted from this.
inherited
operator <<(int shifts) Pos
Returns a new position with this position bit-shifted left by shifts.
inherited
operator ==(Object other) bool
The equality operator.
inherited
operator >>(int shifts) Pos
Returns a new position with this position bit-shifted right by shifts.
inherited
operator ^(Pos other) Pos
Returns a new position with this position logical-XORed with other.
inherited
operator unary-() Direction
Returns a new position with this position negated.
override
operator |(Pos other) Pos
Returns a new position with this position logical-ORed with other.
inherited
operator ~() Pos
Returns a new position with this position bit-wise negated.
inherited
operator ~/(int scalar) Pos
Returns a new position with this position floor divided by scalar.
inherited

Constants

all → const List<Direction>
All eight cardinal and ordinal directions, in clockwise order.
byClockwise → const Comparator<Direction>
A comparator that sorts directions in clockwise order.
byCounterClockwise → const Comparator<Direction>
A comparator that sorts directions in counter-clockwise order.
cardinal → const List<Direction>
Horizontal or vertical directions: north, east, south, west.
down → const Direction
Alias for south.
downLeft → const Direction
Alias for southWest.
downRight → const Direction
Alias for southEast.
east → const Direction
Direction 'east', or right, represented as (1, 0).
left → const Direction
Alias for west.
north → const Direction
Direction 'north', or up, represented as (0, -1).
northEast → const Direction
Direction 'north-east', or upRight, represented as (1, -1).
northWest → const Direction
Direction 'north-west', or upLeft, represented as (-1, -1).
ordinal → const List<Direction>
Diagonal directions: northEast, southEast, southWest, northWest.
Alias for east.
south → const Direction
Direction 'south', or down, represented as (0, 1).
southEast → const Direction
Direction 'south-east', or downRight represented as (1, 1).
southWest → const Direction
Direction 'south-west', or downLeft, represented as (-1, 1).
up → const Direction
Alias for north.
upLeft → const Direction
Alias for northWest.
upRight → const Direction
Alias for northEast.
values → const List<Direction>
All eight cardinal and ordinal directions, in clockwise order.
west → const Direction
Direction 'west', or left, represented as (-1, 0).