Vec class

Represents a vector in 2D space.

Mixed-in types
Annotations
  • @JsonSerializable(useDynamics: true)

Constructors

Vec.new(double x, double y)
Creates a Vec with the given x and y.
const
Vec.fromJson(dynamic json)
Creates a Vec from the given json map.
factory
Vec.fromSize(SizeC size)
Creates a Vec from the given size.

Properties

hashCode int
The hash code for this object.
no setterinherited
length double
The length is the distance from the origin to this Vec.
no setter
negated Vec
A negated vector that inverts the direction of this Vec.
no setter
normalized Vec
The normalized vector is a vector with the same direction as this Vec but with a length of 1.
no setter
perpendicular Vec
A vector that is perpendicular to this Vec.
no setter
props List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
x double
X value: Typically the position on the horizontal x axis in 2D space.
final
y double
Y value: Typically the position on the vertical y axis in 2D space.
final

Methods

add(Vec other) Vec
Returns the summation of this Vec instance with the given other.
addSize(SizeC other) Vec
Returns the summation of this Vec instance with the given other SizeC for convenience.
distanceTo(Vec other) double
Returns the distance to other. Note that this is an expensive function call due to the use of sqrt. To compare distances efficiently, use distanceToSq.
distanceToSq(Vec other) double
Returns the squared distance to other.
divide(double scalar) Vec
Returns the division of this Vec instance with the given scalar. Both axes are divided by the scalar.
dot(Vec other) double
Returns the dot-product of this Vec instance with the given other.
multiply(double scalar) Vec
Returns the multiplication of this Vec instance with the given scalar. Both axes are multiplied by the scalar.
multiplyVec(Vec other) Vec
Returns the multiplication of this Vec instance with the given other. Each axis is multiplied separately.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
subtract(Vec other) Vec
Returns the subtraction of this Vec instance with the given other.
subtractSize(SizeC other) Vec
Returns the subtraction of this Vec instance with the given other. SizeC for convenience.
toJson() → dynamic
Returns a serializable map representation of the object.
override
toSize() SizeC
Converts this instance of Vec into a SizeC for convenience.
toString() String
A string representation of this object.
override
translate(double x, double y) Vec
Returns the translation of this Vec instance by the given x and y. The x and y values are added to the existing values respectively.

Operators

operator &(SizeC size) RectC
Combines this Vec with the provided size to create a RectC with the same origin as this Vec and the size of size.
operator *(double scalar) Vec
Returns the multiplication of this Vec instance with the given scalar. Both axes are multiplied by the scalar.
operator +(Vec other) Vec
Returns the summation of this Vec instance with the given other. Each axis is summed separately.
operator -(Vec other) Vec
Returns the subtraction of the given other from this Vec instance. Each axis is subtracted separately.
operator /(double scalar) Vec
Returns the division of this Vec instance with the given scalar. Both axes are divided by the scalar.
operator ==(Object other) bool
The equality operator.
inherited

Static Properties

zero Vec
A helper constant for a zero vector.
getter/setter pair