Skip to content

Commit

Permalink
Vector4 utilities. #473
Browse files Browse the repository at this point in the history
  • Loading branch information
czyzby committed Nov 4, 2023
1 parent 2adc950 commit 7a4444c
Show file tree
Hide file tree
Showing 4 changed files with 920 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ _See also: [the official libGDX changelog](https://github.com/libgdx/libgdx/blob
- **[UPDATE]** Updated to Kotlin Coroutines 1.7.3.
- **[UPDATE]** Updated to VisUI 1.5.3.
- **[UPDATE]** Updated to Dokka 1.9.10.
- **[FEATURE]** (`ktx-math`) New extension and factory function were introduced to `Vector4`, offering similar utilities to other vectors.
- `vec4` factory methods allow creating new `Vector4` instances with default and named parameters.
- `+=`, `-=`, `*=`, `/=` mutating operators are now supported.
- `+`, `-` (including unary `-`), `++`, `--`, `*`, `/` operators are now supported, returning new instances of vectors as a result.
- Vectors are now comparable by length, adding support for `<`, `>`, `<=`, `>=` operators.
- `Vector4` instances can now be deconstructed into 4 four values (X, Y, Z, W) using extension component methods.
- `dot` infix function allows calculating the dot product of 2 vectors.

#### 1.12.0-rc1

Expand Down
27 changes: 22 additions & 5 deletions math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ numbers.
#### `Vector2`

- `vec2` is a global factory function that can create `Vector2` instances with named parameters for extra readability.
- `+=`, `-=`, `*=` and `/=` can be used to add, subtract, multiply or divide current values according to the second
- `+=`, `-=`, `*=` and `/=` can be used to add, subtract, multiply (`scl`) or divide current values according to the second
vector or number. Use these operators to _mutate_ existing vectors.
- `+`, `-`, `*` and `/` can be used to add, subtract, multiply or divide vectors according to the second vector or
- `+`, `-`, `*` and `/` can be used to add, subtract, multiply (`scl`) or divide vectors according to the second vector or
number, resulting in a new vector. Use these operators to _create_ new instances of vectors.
- Unary `-` operator (a single minus before the vector) allows to negate both vector values, creating a new vector.
- `++` and `--` operators can be used to increment and decrement both x and y values of the vector, resulting in a new
Expand Down Expand Up @@ -123,20 +123,37 @@ var v2 = Vec2(1f, 2f).withLength(3f)

- `vec3` is a global factory function that can create `Vector3` instances with named parameters for extra readability.
It is also overloaded with a second variant that allows to convert `Vector2` instances to `Vector3`.
- `+=`, `-=`, `*=` and `/=` can be used to add, subtract, multiply or divide current values according to the second
- `+=`, `-=`, `*=` and `/=` can be used to add, subtract, multiply (`scl`) or divide current values according to the second
vector or number. Use these operators to _mutate_ existing vectors.
- `+`, `-`, `*` and `/` can be used to add, subtract, multiply or divide vectors according to the second vector or
- `+`, `-`, `*` and `/` can be used to add, subtract, multiply (`scl`) or divide vectors according to the second vector or
number, resulting in a new vector. Use these operators to _create_ new instances of vectors.
- Unary `-` operator (a single minus before the vector) allows to negate both vector values, creating a new vector.
- `++` and `--` operators can be used to increment and decrement x, y and z values of the vector, resulting in a new
vector. To avoid creating new vectors, prefer `+= 1` and `-= 1` instead.
- `Vector3` instances can be destructed to tree float variables in one step with `val (x, y, z) = vector3` syntax thanks
- `Vector3` instances can be destructed to three float variables in one step with `val (x, y, z) = vector3` syntax thanks
to `component1()`, `component2()` and `component3` operator methods.
- `Vector3` instances are now comparable - `<`, `>`, `<=`, `>=` operators can be used to determine which vector has greater
(or equal) overall length, similarly to how `Vector2` now works.
- `dot` infix function allows to calculate the dot product of 2 vectors.
- `x` infix function allows to calculate the cross product of 2 vectors.

#### `Vector4`

- `vec4` is a global factory function that can create `Vector4` instances with named parameters for extra readability.
It is also overloaded with a second variant that allows to convert `Vector2` and `Vector3` instances to `Vector4`.
- `+=`, `-=`, `*=` and `/=` can be used to add, subtract, multiply (`scl`) or divide current values according to the second
vector or number. Use these operators to _mutate_ existing vectors.
- `+`, `-`, `*` and `/` can be used to add, subtract, multiply (`scl`) or divide vectors according to the second vector or
number, resulting in a new vector. Use these operators to _create_ new instances of vectors.
- Unary `-` operator (a single minus before the vector) allows to negate both vector values, creating a new vector.
- `++` and `--` operators can be used to increment and decrement x, y, z, and w values of the vector, resulting in a new
vector. To avoid creating new vectors, prefer `+= 1` and `-= 1` instead.
- `Vector4` instances can be destructed to four float variables in one step with `val (x, y, z, w) = vector4` syntax thanks
to `component1()`, `component2()` and `component3` operator methods.
- `Vector3` instances are now comparable - `<`, `>`, `<=`, `>=` operators can be used to determine which vector has greater
(or equal) overall length.
- `dot` infix function allows to calculate the dot product of 2 vectors.

#### `Matrix3`

- `mat3` is a human-readable global factory function that allows to easily create `Matrix3` instances.
Expand Down
Loading

0 comments on commit 7a4444c

Please sign in to comment.