int LengthSquared { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The LengthSquared property of the Vector3Int struct provides the squared length of the integer vector. This property is useful for performance optimization when comparing distances, as it avoids the computational cost of calculating the square root, which is required for the actual length. It is particularly beneficial when only the relative distances are needed, and the exact length is not necessary.

Usage

Use the LengthSquared property when you need to compare the magnitudes of vectors without needing the exact length. This is especially useful in scenarios where performance is critical, such as in game development or real-time simulations.

Example

Vector3Int vector = new Vector3Int(3, 4, 5);
int squaredLength = vector.LengthSquared;
// squaredLength will be 50, as it is calculated as 3*3 + 4*4 + 5*5