Vector extensions - Team-Swamp/IceBites GitHub Wiki

Overview

Provides versatile extensions for Vector2 and Vector3, enhancing functionality for various operations.

A importend note, the following examples and explanmations are for both Vector2 and Vector3 except the Z axis.

Writen by - Bas

Useage

Every method is public.

When a '*' is added, it means it's only for Vector3.

When a '?' is added, it means that it's optional.

Set

Set method Return Description
SetX(float) This Vector3 / Vector2 Change the X vector of this Vector3 / Vector2
SetY(float) This Vector3 / Vector2 Change the Y vector of this Vector3 / Vector2
SetZ(float) This Vector3 Change the Z vector of this Vector3

Add

Add method Return Description
Add(Vector3 / Vector2) This Vector3 / Vector2 Add the Axis of two Vector3 / Vector2 into one.
AddX(Vector3 / Vector2) This Vector3 / Vector2 Add the X Axis of two Vector3 / Vector2 into one
AddY(Vector3 / Vector2) This Vector3 / Vector2 Add the Y Axis of two Vector3 / Vector2 into one
AddZ(Vector3) This Vector3 Add the Z Axis of two Vector3 into one
Add(float, float, *float) This Vector3 / Vector2 Add the specified values to the Axis of this Vector3 / Vector2
AddX(float) This Vector3 / Vector2 Add the specified value to the X Axis of this Vector3 / Vector2
AddY(float) This Vector3 / Vector2 Add the specified value to the Y Axis of this Vector3 / Vector2
AddZ(float) This Vector3 Add the specified value to the Z Axis of this Vector3

Subtract

Subtract method Return Description
Subtract(Vector3 / Vector2) This Vector3 / Vector2 Subtract the Axis of the second Vector3 / Vector2 from the first Vector3 / Vector2and return the result
SubtractX(Vector3 / Vector2) This Vector3 / Vector2 Subtract the X Axis of the second Vector3 / Vector2 from the first Vector3 and return the result
SubtractY(Vector3 / Vector2) This Vector3 / Vector2 Subtract the Y Axis of the second Vector3 / Vector2 from the first Vector3 and return the result
SubtractZ(Vector3) This Vector3 Subtract the Z Axis of the second Vector3 from the first Vector3 and return the result
Subtract(float, float, *float) This Vector3 / Vector2 Subtract the specified values from the Axis of this Vector3 / Vector2
SubtractX(float) This Vector3 / Vector2 Subtract the specified value from the X Axis of this Vector3 / Vector2
SubtractY(float) This Vector3 / Vector2 Subtract the specified value from the Y Axis of this Vector3 / Vector2
SubtractZ(float) This Vector3 Subtract the specified value from the Z Axis of this Vector3

Multiply

Multiply method Return Description
Multiply(Vector3 / Vector2) This Vector3 / Vector2 Multiply the Axis of this Vector3 / Vector2 with the corresponding Axis of another Vector3 / Vector2 and return the result
MultiplyX(Vector3 / Vector2) This Vector3 / Vector2 Multiply the X Axis of this Vector3 / Vector2 with the X Axis of another Vector3 and return the result
MultiplyY(Vector3 / Vector2) This Vector3 / Vector2 Multiply the Y Axis of this Vector3 / Vector2 with the Y Axis of another Vector3 and return the result
MultiplyZ(Vector3) This Vector3 Multiply the Z Axis of this Vector3 with the Z Axis of another Vector3 and return the result
Multiply(float, float, *float) This Vector3 / Vector2 Multiply the specified values with the Axis of this Vector3 / Vector2
MultiplyX(float) This Vector3 / Vector2 Multiply the specified value with the X Axis of this Vector3 / Vector2
MultiplyY(float) This Vector3 / Vector2 Multiply the specified value from the Y Axis of this Vector3 / Vector2
MultiplyZ(float) This Vector3 Multiply the specified value from the Z Axis of this Vector3

Divide

Divide method Return Description
Divide(Vector3 / Vector2) This Vector3 / Vector2 Divide the Axis of this Vector3 / Vector2 by the corresponding Axis of another Vector3 / Vector2 and return the result
DivideX(Vector3 / Vector2) This Vector3 / Vector2 Divide the X Axis of this Vector3 / Vector2 by the X Axis of another Vector3 / Vector2 and return the result
DivideY(Vector3 / Vector2) This Vector3 / Vector2 Divide the X Axis of this Vector3 / Vector2 by the X Axis of another Vector3 / Vector2 and return the result
DivideZ(Vector3) This Vector3 Divide the X Axis of this Vector3 by the X Axis of another Vector3 and return the result
Dividey(float, float, *float) This Vector3 / Vector2 Divide the specified values by the Axis of this Vector3 / Vector2
DivideX(float) This Vector3 / Vector2 Divide the specified value from the X Axis of this Vector3 / Vector2
DivideY(float) This Vector3 / Vector2 Divide the specified value from the Y Axis of this Vector3 / Vector2
DivideZ(float) This Vector3 Divide the specified value from the Z Axis of this Vector3

Compare

Compare method Return Description
Compare(Vector3 / Vector2, ?float) Bool Compare two Vector3 / Vector2 with an optional margin for floating-point precision
CompareX(Vector3 / Vector2, ?float) Bool Compare the X axis of two Vector3 / Vector2 with an optional margin for floating-point precision
CompareY(Vector3 / Vector2, ?float) Bool Compare the Y axis of two Vector3 / Vector2 with an optional margin for floating-point precision
CompareZ(Vector3, ?float) Bool Compare the Z axis of two Vector3 / Vector2 with an optional margin for floating-point precision
CompareX(float, ?float) Bool Compare a float value with the X Axis of this Vector3 / Vector2 with an optional margin for floating-point precision
CompareY(float, ?float) Bool Compare a float value with the Y Axis of this Vector3 / Vector2 with an optional margin for floating-point precision
CompareZ(float, ?float) Bool Compare a float value with the Z Axis of this Vector3 / Vector2 with an optional margin for floating-point precision

Randomize

Randomize method Return Description
Randomize(Vector2, Vector2, Vector2) This Vector3 / Vector2 Randomize the X & Y (& Z) axis of this Vector3 / Vector2 within specified ranges
Randomize(Vector2) This Vector3 / Vector2 Randomize the X & Y (& Z) axis of this Vector3 / Vector2 within the specified range
RandomizeUniform(Vector2) This Vector3 / Vector2 Randomize all axis of this Vector3 / Vector2 with the same random number within the specified range
RandomizeX(Vector2) This Vector3 / Vector2 Randomize the X axis of this Vector3 / Vector2 within a specified range
RandomizeY(Vector2) This Vector3 / Vector2 Randomize the Y axis of this Vector3 / Vector2 within a specified range
RandomizeZ(Vector2) This Vector3 / Vector2 Randomize the Z axis of this Vector3 within a specified range

Invert

Invert method Return Description
Invert() This Vector3 / Vector2 Invert all axis of this Vector3 / Vector2
InvertX() This Vector3 / Vector2 Invert the X axis of this Vector3 / Vector2
InvertY() This Vector3 / Vector2 Invert the Y axis of this Vector3 / Vector2
InvertZ() This Vector3 / Vector2 Invert the X axis of this Vector3

Midpoint

Midpoint method Return Description
Midpoint(Vector3 / Vector2) New Vector3 / Vector2 Calculate the midpoint between two Vector3 / Vector2
WeightedAverage(Vector3 / Vector2, float) New Vector3 / Vector2 Calculate the weighted average of two Vector3 / Vector2 based on specified weight

IsWithinRange

IsWithinRange method Return Description
IsWithinRange(Vector3 / Vector2, float) Bool Checks if this Vector3 / Vector2 is within the specified range of another Vector3 / Vector2
IsXWithinRange(Vector3 / Vector2, float) Bool Checks if the X Axis of this Vector3 / Vector2 is within the specified range of the X Axis of another Vector3 / Vector2
IsYWithinRange(Vector3 / Vector2, float) Bool Checks if the Y Axis of this Vector3 / Vector2 is within the specified range of the X Axis of another Vector3 / Vector2
IsZWithinRange(Vector3, float) Bool Checks if the Z Axis of this Vector3 is within the specified range of the X Axis of another Vector3

Source

You want to see how it works VectorExtensions.cs.