Vector3i
A 3D vector using integer coordinates.
Vector3i.swift:19struct Vector3i
A 3-element structure that can be used to represent 3D grid coordinates or any other triplet of integers.
It uses integer coordinates and is therefore preferable to Vector3
when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector3
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
Vector3i
with all components set to0
.init(from: Vector3i
) init(from: Vector3
) Constructs a new
Vector3i
from the givenVector3
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, z: Int32
) Returns a
Vector3i
with the given components.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 axisZ: Int
Enumerated value for the Z axis. Returned by
maxAxisIndex
andminAxisIndex
.static let back: Vector3i
Back unit vector. Represents the local direction of back, and the global direction of south.
static let down: Vector3i
Down unit vector.
static let forward: Vector3i
Forward unit vector. Represents the local direction of forward, and the global direction of north.
static var godotType: Variant.GType
static let left: Vector3i
Left unit vector. Represents the local direction of left, and the global direction of west.
static let max: Vector3i
Max vector, a vector with all components equal to
INT32_MAX
. Can be used as an integer equivalent ofVector3.INF
.static let min: Vector3i
Min vector, a vector with all components equal to
INT32_MIN
. Can be used as a negative integer equivalent ofVector3.INF
.static let one: Vector3i
One vector, a vector with all components set to
1
.static let right: Vector3i
Right unit vector. Represents the local direction of right, and the global direction of east.
static let up: Vector3i
Up unit vector.
static let zero: Vector3i
Zero vector, a vector with all components set to
0
.static func != (lhs: Vector3i, rhs: Vector3i
) -> Bool Returns
true
if the vectors are not equal.static func % (lhs: Vector3i, rhs: Vector3i
) -> Vector3i Gets the remainder of each component of the
Vector3i
with the components of the givenVector3i
. 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: Vector3i, rhs: Int64
) -> Vector3i Gets the remainder of each component of the
Vector3i
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: Vector3i, rhs: Vector3i
) -> Vector3i Multiplies each component of the
Vector3i
by the components of the givenVector3i
.static func * (lhs: Vector3i, rhs: Int64
) -> Vector3i Multiplies each component of the
Vector3i
by the given integer.static func * (lhs: Vector3i, rhs: Double
) -> Vector3 Multiplies each component of the
Vector3i
by the given float. Returns aVector3
.static func *= (left: inout `Self`, right: `Self`
) static func + (lhs: Vector3i, rhs: Vector3i
) -> Vector3i Adds each component of the
Vector3i
by the components of the givenVector3i
.static func += (left: inout `Self`, right: `Self`
) static func - (v: `Self`
) -> Vector3i Returns the negative value of the Vector3i. This is the same as writing Vector3i(-v.x, -v.y, -v.z). This operation flips the direction of the vector while keeping the same magnitude.
static func - (lhs: Vector3i, rhs: Vector3i
) -> Vector3i Subtracts each component of the
Vector3i
by the components of the givenVector3i
.static func -= (left: inout `Self`, right: `Self`
) static func / (lhs: Vector3i, rhs: Vector3i
) -> Vector3i Divides each component of the
Vector3i
by the components of the givenVector3i
.static func / (lhs: Vector3i, rhs: Int64
) -> Vector3i Divides each component of the
Vector3i
by the given integer.static func / (lhs: Vector3i, rhs: Double
) -> Vector3 Divides each component of the
Vector3i
by the given float. Returns aVector3
.static func /= (left: inout `Self`, right: `Self`
) static func < (lhs: Vector3i, rhs: Vector3i
) -> Bool Compares two
Vector3i
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, and then with the Z values. This operator is useful for sorting vectors.static func <= (lhs: Vector3i, rhs: Vector3i
) -> Bool Compares two
Vector3i
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, and then with the Z values. This operator is useful for sorting vectors.static func == (lhs: Vector3i, rhs: Vector3i
) -> Bool Returns
true
if the vectors are equal.static func > (lhs: Vector3i, rhs: Vector3i
) -> Bool Compares two
Vector3i
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, and then with the Z values. This operator is useful for sorting vectors.static func >= (lhs: Vector3i, rhs: Vector3i
) -> Bool Compares two
Vector3i
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, and then with the Z values. 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]
.var z: Int32
The vector’s Z component. Also accessible by using the index position
[2]
.subscript(Int64
) -> Int64 func abs(
) -> Vector3i Returns a new vector with all components in absolute values (i.e. positive).
func clamp(min: Vector3i, max: Vector3i
) -> Vector3i 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
) -> Vector3i Returns a new vector with all components clamped between
min
andmax
, by running@GlobalScope.clamp
on each component.func distanceSquaredTo(Vector3i
) -> Int64 Returns the squared distance between this vector and
to
.func distanceTo(Vector3i
) -> 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: Vector3i
) -> Vector3i Returns the component-wise maximum of this and
with
, equivalent toVector3i(maxi(x, with.x), maxi(y, with.y), maxi(z, with.z))
.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
) -> Vector3i Returns the component-wise maximum of this and
with
, equivalent toVector3i(maxi(x, with), maxi(y, with), maxi(z, with))
.func min(with: Vector3i
) -> Vector3i Returns the component-wise minimum of this and
with
, equivalent toVector3i(mini(x, with.x), mini(y, with.y), mini(z, with.z))
.func minAxisIndex(
) -> Int64 Returns the axis of the vector’s lowest value. See
AXIS_*
constants. If all components are equal, this method returns .z.func mini(with: Int64
) -> Vector3i Returns the component-wise minimum of this and
with
, equivalent toVector3i(mini(x, with), mini(y, with), mini(z, with))
.func sign(
) -> Vector3i 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`
) -> Vector3i func snappedi(step: Int64
) -> Vector3i 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
)