{"id":13428821,"url":"https://github.com/romainguy/kotlin-math","last_synced_at":"2026-04-01T18:56:32.264Z","repository":{"id":41225860,"uuid":"115212016","full_name":"romainguy/kotlin-math","owner":"romainguy","description":"Set of Kotlin APIs to make graphics math easier to write.","archived":false,"fork":false,"pushed_at":"2026-03-19T22:48:02.000Z","size":313,"stargazers_count":884,"open_issues_count":4,"forks_count":66,"subscribers_count":9,"default_branch":"main","last_synced_at":"2026-03-20T12:02:30.145Z","etag":null,"topics":["android","graphics","kotlin","math"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romainguy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-12-23T17:45:43.000Z","updated_at":"2026-03-20T04:21:45.000Z","dependencies_parsed_at":"2024-01-14T02:38:43.679Z","dependency_job_id":"3a370eee-26a0-45a2-be85-69d817811c26","html_url":"https://github.com/romainguy/kotlin-math","commit_stats":{"total_commits":80,"total_committers":9,"mean_commits":8.88888888888889,"dds":"0.32499999999999996","last_synced_commit":"b7b88ce748b61ff430d1a51fe75158570a1fb9e3"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/romainguy/kotlin-math","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainguy%2Fkotlin-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainguy%2Fkotlin-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainguy%2Fkotlin-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainguy%2Fkotlin-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romainguy","download_url":"https://codeload.github.com/romainguy/kotlin-math/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romainguy%2Fkotlin-math/sbom","scorecard":{"id":783621,"data":{"date":"2025-08-11","repo":{"name":"github.com/romainguy/kotlin-math","commit":"e82fc5895de7ba94a3a15f308ba999140759eb4d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.6,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":2,"reason":"Found 7/30 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":9,"reason":"binaries present in source code","details":["Warn: binary detected: gradle/wrapper/gradle-wrapper.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 7 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-23T05:29:54.514Z","repository_id":41225860,"created_at":"2025-08-23T05:29:54.514Z","updated_at":"2025-08-23T05:29:54.514Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31290980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","graphics","kotlin","math"],"created_at":"2024-07-31T01:01:05.995Z","updated_at":"2026-04-01T18:56:32.240Z","avatar_url":"https://github.com/romainguy.png","language":"Kotlin","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# kotlin-math\n\n[![kotlin-math](https://img.shields.io/maven-central/v/dev.romainguy/kotlin-math?label=kotlin-math\u0026color=green)](https://mvnrepository.com/artifact/dev.romainguy/kotlin-math)\n\nSet of Kotlin APIs to make graphics math easier to write. These APIs are mostly\nmodeled after GLSL (OpenGL Shading Language) to make porting code to and from\nshaders easier.\n\nThe various types offered by this library are only meant to be _value types_.\nMost APIs are therefore exposed as top-level functions and not as methods.\nFor instance:\n\n```kotlin\nval v = Float3(1.0f, 3.0f, 4.0f)\nval n = normalize(v)\n```\n\nThis project supports multi-platform thanks to [ekgame](https://github.com/ekgame).\n\n## Maven\n\n```gradle\nrepositories {\n    // ...\n    mavenCentral()\n}\n\ndependencies {\n    implementation 'dev.romainguy:kotlin-math:1.8.0'\n}\n```\n\n## Building the project\n\nSimply run the following command to generate `build/libs/kotlin-math.jar`:\n\n```bash\n$ ./gradlew assemble\n```\n\n## Types\n\nScalar types:\n- `Half`, half-precision floating point values (also called fp16)\n- `Rational`, number expressed as the ratio of two integer\n\nVector types:\n- `Float2`, vector of 2 floats\n- `Float3`, vector of 3 floats\n- `Float4`, vector of 4 floats\n- `Half2`, vector of 2 half-precision floats\n- `Half3`, vector of 3 half-precision floats\n- `Half4`, vector of 4 half-precision floats\n- `Bool2`, vector of 2 booleans\n- `Bool3`, vector of 3 booleans\n- `Bool4`, vector of 4 booleans\n\nMatrix types:\n- `Mat3`, 3x3 float matrix\n- `Mat4`, 4x4 float matrix\n\nOther types:\n- `Quaternion`, unit quaternions to represent orientation\n- `Ray`, simple representation of a 3D ray (origin plus direction)\n\n## Vector types\n\n### Accessing components\n\nEach vector type exposes its component as properties:\n\n```kotlin\nval x = myVector.x\nval (x, y, z) = myVector\n```\n\nA vector can also be treated as an array:\n\n```kotlin\nval x = myVector[0]\nval x = myVector[VectorComponents.X]\n```\n\nThe traditional mathematical form with 1-based indexing can be used:\n\n```kotlin\nval x = myVector(1)\n```\n\n### Property aliases\n\nTo improve code readability, the vector types provide aliases for each property,\nallowing you to choose the most appropriate names:\n\n```kotlin\nval (x, y, z) = myPosition.xyz\nval (r, g, b) = myColor.rgb\nval (s, t) = myTextureCoordinates.st\n```\n\n### Swizzling\n\nVector types also provide different ways to swizzle their components, although\nin a more limited way than in GLSL. The most obvious use for swizzling is to\nextract sub-vectors:\n\n```kotlin\nval position = Float3(…)\nval position2d = position.xy // extract a Float2\n\nval colorWithAlpha = Float4(…)\nval rgbColor = colorWithAlpha.rgb // extract a Float3\n```\n\nThe get operators allows for more complex swizzling by enabling re-ordering and\nduplication of the components:\n\n```kotlin\nval colorWithAlpha = Float4(…)\nval bgrColor = colorWithAlpha[\n    VectorComponents.B,\n    VectorComponents.G,\n    VectorComponents.R\n] // re-ordered 3 components sub-vector\n```\n\n### Comparing vector types\n\nVector comparisons follow GLSL rules:\n- `==` returns true if all components are equal \n- `!=` returns true if not all components are equal\n\nIn addition you can use component-wise relational operators that return a vector\nof boolean with the result of each component-wise comparison:\n- `lessThan`\n- `lessThanEqual`\n- `greaterThan`\n- `greaterThanEqual`\n- `equal`\n- `notEqual`\n\nExample:\n\n```kotlin\nif (all(lessThan(v1, v2))) {\n   // …\n}\n```\n\nYou can also use the following infix operators if you prefer the operator\nsyntax:\n- `lt`\n- `lte`\n- `gt`\n- `gte`\n- `eq`\n- `neq`\n\nExample:\n\n```kotlin\nif (any(v1 lte v2)) {\n   // …\n}\n```\n\n## Matrix types\n\nMatrices are represented as a set of column vectors. For instance, a `Mat4` can\nbe destructured into the right, up, forward and translation vectors:\n\n```kotlin\nval (right, up, forward, translation) = myMat4\n```\n\nEach vector can be accessed as a property or by its index:\n\n```kotlin\nforward = myMat4.forward\nforward = myMat4.z\nforward = myMat4[2]\nforward = myMat4[MatrixColumns.Z]\n```\n\nMatrix types also offer APIs to access each element individually by specifying\nthe column then row:\n\n```kotlin\nv = myMat4.z[1]\nv = myMat4[2, 1]\nv = myMat4[MatrixColumns.Z, 1]\n```\n\nYou can also use the invoke operator to access elements in row-major mode with\n1-based indices to follow the traditional mathematical notation:\n\n```kotlin\nv = myMat4(2, 3) // equivalent to myMat4[2, 1]\n```\n\n## Quaternions and rotations\n\nConstruct a Euler angles rotation matrix using per-axis angles in degrees:\n\n```kotlin\nrotationMatrix = rotation(d = Float3(y = 90.0f)) // rotation of 90° around y axis\n```\n\nConstruct a Euler angles rotation matrix using an axis direction and an angle in degrees:\n\n```kotlin\nrotationMatrix = rotation(axis = Float3(y = 1.0f), angle = 90.0f) // rotation of 90° around y axis\n```\n\nConstruct a quaternion rotation matrix following the Hamilton convention (assumes the\ndestination and local coordinate spaces are initially aligned, and the local coordinate\nspace is then rotated counter-clockwise about a unit-length axis, k, by an angle, theta):\n\n```kotlin\nrotationMatrix = rotation(quaternion = Quaternion(y = 1.0f, w = 1.0f)) // rotation of 90° around y axis\n```\n\n## Scalar APIs\n\nThe file `Scalar.kt` contains various helper methods to use common math operations\nwith floats. It is intended to be used in combination with Kotlin 1.2's new float\nmath methods.\n\n## Rational numbers\n\nThis library provides simple support for rational numbers to avoid numerical imprecision. The\ncurrent implementation is limited to 32 bits of storage for the numerator and the denominator.\nThe current implementation is also not written for speed.\n\n```kotlin\nval a = Rational(2, 5)   // Represents 2/5\nval b = Rational(127)    // Integers can be represented exactly\nval c = Rational(0.25f)  // Floats and doubles will be converted to a rational representation\n\n// The following operators are supported:\nprintln(+a)\nprintln(-a)\nprintln(a + b)\nprintln(a - b)\nprintln(c * d)\nprintln(c / d)\n\n// And you can convert back to other types:\nprintln(a.toFloat())\nprintln(a.toLong())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromainguy%2Fkotlin-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromainguy%2Fkotlin-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromainguy%2Fkotlin-math/lists"}