Vector2i
A 2D vector using integer coordinates.
Vector2i.swift:19struct Vector2i
A 2-element structure that can be used to represent 2D grid coordinates or any other pair of integers.
It uses integer coordinates and is therefore preferable to Vector2
when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector2
this cannot be configured with an engine build option. Use integer or PackedInt64Array
if 64-bit values are needed.
Citizens in SwiftGodot
Conformances
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol IntScalable
protocol SelfVariantRepresentable
Structs and scalar types use their own layout for storage.
protocol Snappable
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
init(
) Constructs a default-initialized
Vector2i
with all components set to0
.init(from: Vector2i
) init(from: Vector2
) Constructs a new
Vector2i
from the givenVector2
by truncating components’ fractional parts (rounding towards zero). For a different behavior consider passing the result ofceil
,floor
orround
to this constructor instead.init(x: Int32, y: Int32
) Constructs a new
Vector2i
from the givenx
andy
.static let axisX: Int
Enumerated value for the X axis. Returned by
maxAxisIndex
andminAxisIndex
.static let axisY: Int
Enumerated value for the Y axis. Returned by
maxAxisIndex
andminAxisIndex
.static let down: Vector2i
Down unit vector. Y is down in 2D, so this vector points +Y.
static var godotType: Variant.GType
static let left: Vector2i
Left unit vector. Represents the direction of left.
static let max: Vector2i
Max vector, a vector with all components equal to
INT32_MAX
. Can be used as an integer equivalent ofVector2.INF
.static let min: Vector2i
Min vector, a vector with all components equal to
INT32_MIN
. Can be used as a negative integer equivalent ofVector2.INF
.static let one: Vector2i
One vector, a vector with all components set to
1
.static let right: Vector2i
Right unit vector. Represents the direction of right.
static let up: Vector2i
Up unit vector. Y is down in 2D, so this vector points -Y.
static let zero: Vector2i
Zero vector, a vector with all components set to
0
.static func != (lhs: Vector2i, rhs: Vector2i
) -> Bool Returns
true
if the vectors are not equal.static func % (lhs: Vector2i, rhs: Vector2i
) -> Vector2i Gets the remainder of each component of the
Vector2i
with the components of the givenVector2i
. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using@GlobalScope.posmod
instead if you want to handle negative numbers.static func % (lhs: Vector2i, rhs: Int64
) -> Vector2i Gets the remainder of each component of the
Vector2i
with the given integer. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using@GlobalScope.posmod
instead if you want to handle negative numbers.static func %= (left: inout `Self`, right: `Self`
) static func * (lhs: Vector2i, rhs: Vector2i
) -> Vector2i Multiplies each component of the
Vector2i
by the components of the givenVector2i
.static func * (lhs: Vector2i, rhs: Int64
) -> Vector2i Multiplies each component of the
Vector2i
by the given integer.static func * (lhs: Vector2i, rhs: Double
) -> Vector2 Multiplies each component of the
Vector2i
by the given float. Returns aVector2
.static func *= (left: inout `Self`, right: `Self`
) static func + (lhs: Vector2i, rhs: Vector2i
) -> Vector2i Adds each component of the
Vector2i
by the components of the givenVector2i
.static func += (left: inout `Self`, right: `Self`
) static func - (v: `Self`
) -> Vector2i Returns the negative value of the Vector2i. This is the same as writing Vector2i(-v.x, -v.y). This operation flips the direction of the vector while keeping the same magnitude.
static func - (lhs: Vector2i, rhs: Vector2i
) -> Vector2i Subtracts each component of the
Vector2i
by the components of the givenVector2i
.static func -= (left: inout `Self`, right: `Self`
) static func / (lhs: Vector2i, rhs: Vector2i
) -> Vector2i Divides each component of the
Vector2i
by the components of the givenVector2i
.static func / (lhs: Vector2i, rhs: Int64
) -> Vector2i Divides each component of the
Vector2i
by the given integer.static func / (lhs: Vector2i, rhs: Double
) -> Vector2 Divides each component of the
Vector2i
by the given float. Returns aVector2
.static func /= (left: inout `Self`, right: `Self`
) static func < (lhs: Vector2i, rhs: Vector2i
) -> Bool Compares two
Vector2i
vectors by first checking if the X value of the left vector is less than the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.static func <= (lhs: Vector2i, rhs: Vector2i
) -> Bool Compares two
Vector2i
vectors by first checking if the X value of the left vector is less than or equal to the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.static func == (lhs: Vector2i, rhs: Vector2i
) -> Bool Returns
true
if the vectors are equal.static func > (lhs: Vector2i, rhs: Vector2i
) -> Bool Compares two
Vector2i
vectors by first checking if the X value of the left vector is greater than the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.static func >= (lhs: Vector2i, rhs: Vector2i
) -> Bool Compares two
Vector2i
vectors by first checking if the X value of the left vector is greater than or equal to the X value of theright
vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
Instance members
var x: Int32
The vector’s X component. Also accessible by using the index position
[0]
.var y: Int32
The vector’s Y component. Also accessible by using the index position
[1]
.subscript(Int64
) -> Int64 func abs(
) -> Vector2i Returns a new vector with all components in absolute values (i.e. positive).
func aspect(
) -> Double Returns the aspect ratio of this vector, the ratio of
x
toy
.func clamp(min: Vector2i, max: Vector2i
) -> Vector2i Returns a new vector with all components clamped between the components of
min
andmax
, by running@GlobalScope.clamp
on each component.func clampi(min: Int64, max: Int64
) -> Vector2i Returns a new vector with all components clamped between
min
andmax
, by running@GlobalScope.clamp
on each component.func distanceSquaredTo(Vector2i
) -> Int64 Returns the squared distance between this vector and
to
.func distanceTo(Vector2i
) -> Double Returns the distance between this vector and
to
.func length(
) -> Double Returns the length (magnitude) of this vector.
func lengthSquared(
) -> Int64 Returns the squared length (squared magnitude) of this vector.
func max(with: Vector2i
) -> Vector2i Returns the component-wise maximum of this and
with
, equivalent toVector2i(maxi(x, with.x), maxi(y, with.y))
.func maxAxisIndex(
) -> Int64 Returns the axis of the vector’s highest value. See
AXIS_*
constants. If all components are equal, this method returns .x.func maxi(with: Int64
) -> Vector2i Returns the component-wise maximum of this and
with
, equivalent toVector2i(maxi(x, with), maxi(y, with))
.func min(with: Vector2i
) -> Vector2i Returns the component-wise minimum of this and
with
, equivalent toVector2i(mini(x, with.x), mini(y, with.y))
.func minAxisIndex(
) -> Int64 Returns the axis of the vector’s lowest value. See
AXIS_*
constants. If all components are equal, this method returns .y.func mini(with: Int64
) -> Vector2i Returns the component-wise minimum of this and
with
, equivalent toVector2i(mini(x, with), mini(y, with))
.func sign(
) -> Vector2i Returns a new vector with each component set to
1
if it’s positive,-1
if it’s negative, and0
if it’s zero. The result is identical to calling@GlobalScope.sign
on each component.func snapped(step: `Self`
) -> Vector2i func snappedi(step: Int64
) -> Vector2i Returns a new vector with each component snapped to the closest multiple of
step
.
Type features
init?(Variant
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.
static func * (lhs: Self, rhs: Int
) -> Self static func *= (lhs: inout Self, rhs: Int
) static func / (lhs: Self, rhs: Int
) -> Self static func /= (lhs: inout Self, rhs: Int
)