
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
dev.romainguy:kotlin-math-watchosarm32
Advanced tools
Set of Kotlin APIs to make graphics math easier to write. These APIs are mostly modeled after GLSL (OpenGL Shading Language) to make porting code to and from shaders easier.
The various types offered by this library are only meant to be value types. Most APIs are therefore exposed as top-level functions and not as methods. For instance:
val v = Float3(1.0f, 3.0f, 4.0f)
val n = normalize(v)
This project supports multi-platform thanks to ekgame.
repositories {
// ...
mavenCentral()
}
dependencies {
implementation 'dev.romainguy:kotlin-math:1.1.0'
}
Simply run the following command to generate build/libs/kotlin-math.jar:
$ ./gradlew assemble
Vector types:
Matrix types:
Each vector type exposes its component as properties:
val x = myVector.x
val (x, y, z) = myVector
A vector can also be treated as an array:
val x = myVector[0]
val x = myVector[VectorComponents.X]
The traditional mathematical form with 1-based indexing can be used:
val x = myVector(1)
To improve code readability, the vector types provide aliases for each property, allowing you to choose the most appropriate names:
val (x, y, z) = myPosition.xyz
val (r, g, b) = myColor.rgb
val (s, t) = myTextureCoordinates.st
Vector types also provide different ways to swizzle their components, although in a more limited way than in GLSL. The most obvious use for swizzling is to extract sub-vectors:
val position = Float3(…)
val position2d = position.xy // extract a Float2
val colorWithAlpha = Float4(…)
val rgbColor = colorWithAlpha.rgb // extract a Float3
The get operators allows for more complex swizzling by enabling re-ordering and duplication of the components:
val colorWithAlpha = Float4(…)
val bgrColor = colorWithAlpha[
VectorComponents.B,
VectorComponents.G,
VectorComponents.R
] // re-ordered 3 components sub-vector
Vector comparisons follow GLSL rules:
== returns true if all components are equal!= returns true if not all components are equalIn addition you can use component-wise relational operators that return a vector of boolean with the result of each component-wise comparison:
lessThanlessThanEqualgreaterThangreaterThanEqualequalnotEqualExample:
if (all(lessThan(v1, v2))) {
// …
}
You can also use the following infix operators if you prefer the operator syntax:
ltltegtgteeqneqExample:
if (any(v1 lte v2)) {
// …
}
Matrices are represented as a set of column vectors. For instance, a Mat4 can
be destructured into the right, up, forward and translation vectors:
val (right, up, forward, translation) = myMat4
Each vector can be accessed as a property or by its index:
forward = myMat4.forward
forward = myMat4.z
forward = myMat4[2]
forward = myMat4[MatrixColumns.Z]
Matrix types also offer APIs to access each element individually by specifying the column then row:
v = myMat4.z[1]
v = myMat4[2, 1]
v = myMat4[MatrixColumns.Z, 1]
You can also use the invoke operator to access elements in row-major mode with 1-based indices to follow the traditional mathematical notation:
v = myMat4(2, 3) // equivalent to myMat4[2, 1]
Construct a Euler angles rotation matrix using per-axis angles in degrees:
rotationMatrix = rotation(d = Float3(y = 90.0f)) // rotation of 90° around y axis
Construct a Euler angles rotation matrix using an axis direction and an angle in degrees:
rotationMatrix = rotation(axis = Float3(y = 1.0f), angle = 90.0f) // rotation of 90° around y axis
Construct a quaternion rotation matrix following the Hamilton convention (assumes the destination and local coordinate spaces are initially aligned, and the local coordinate space is then rotated counter-clockwise about a unit-length axis, k, by an angle, theta):
rotationMatrix = rotation(quaternion = Float4(y = 1.0f, w = 1.0f)) // rotation of 90° around y axis
The file Scalar.kt contains various helper methods to use common math operations
with floats. It is intended to be used in combination with Kotlin 1.2's new float
math methods.
FAQs
Graphics oriented math library for Kotlin
We found that dev.romainguy:kotlin-math-watchosarm32 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.