int LengthSquared { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The LengthSquared property of the Vector2Int struct provides the squared length of the integer vector. This property is useful for performance optimization as it avoids the computational cost of calculating the square root, which is required for the actual length. It is particularly beneficial when comparing distances, as long as the comparison is done using squared values.

Usage

Use the LengthSquared property when you need to compare the magnitude 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

Vector2Int vector = new Vector2Int(3, 4);
int squaredLength = vector.LengthSquared;
// squaredLength will be 25, as 3*3 + 4*4 = 9 + 16 = 25