{"id":23037009,"url":"https://github.com/goki/mat32","last_synced_at":"2025-08-14T17:32:42.165Z","repository":{"id":57518014,"uuid":"247568922","full_name":"goki/mat32","owner":"goki","description":"float32 based vector and matrix package for 2D \u0026 3D graphics, based on G3N math32, with value-based design","archived":false,"fork":false,"pushed_at":"2024-01-09T20:34:50.000Z","size":316,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-06-20T02:32:04.984Z","etag":null,"topics":["go","golang","math-library","matrix-library","opengl","svg","vector-graphics","vulkan"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goki.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}},"created_at":"2020-03-15T23:22:58.000Z","updated_at":"2024-04-13T17:40:32.000Z","dependencies_parsed_at":"2023-12-19T07:03:40.520Z","dependency_job_id":"9913dbd8-bf0a-4f66-b3c8-c6ea8eb3a50b","html_url":"https://github.com/goki/mat32","commit_stats":{"total_commits":134,"total_committers":6,"mean_commits":"22.333333333333332","dds":0.4925373134328358,"last_synced_commit":"e27a3df49bf8afa870862308f9b5d4412e1c4f50"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goki%2Fmat32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goki%2Fmat32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goki%2Fmat32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goki%2Fmat32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goki","download_url":"https://codeload.github.com/goki/mat32/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229851418,"owners_count":18134201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["go","golang","math-library","matrix-library","opengl","svg","vector-graphics","vulkan"],"created_at":"2024-12-15T17:28:24.079Z","updated_at":"2024-12-15T17:28:24.704Z","avatar_url":"https://github.com/goki.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mat32\n\n`mat32` is a float32 based vector and matrix package for 2D \u0026 3D graphics, based on the [G3N math32](https://github.com/g3n/engine) package, but using a value-based design instead of pointer-based, which simplifies chained expressions of multiple operators.\n\nThe [go-gl/mathgl](https://github.com/go-gl/mathgl) package is also comparable, which in turn is based on [image/math/f32](https://golang.org/x/image/math/f32) types, which use arrays instead of `struct`s with named X, Y, Z components.  The named components make things easier to read overall.  The G3N and this package support a much more complete set of vector and matrix math, covering almost everything you might need, including aggregate types such as triangles, planes, etc.\n\nThis package also includes the Matrix class from [fogleman/gg](https://github.com/fogleman/gg) (as `Mat2`) for 2D graphics -- this also includes additional support for SVG-style configuring of a matrix, in the `SetString` method.\n\n# Value-based Vectors\n\nThe use of value-based methods means that vectors are passed and returned as values instead of pointers:\n\nSo, in this `mat32` package, `Add` looks like this:\n\n```Go\n// Add adds other vector to this one and returns result in a new vector.\nfunc (v Vec3) Add(other Vec3) Vec3 {\n\treturn V3(v.X + other.X, v.Y + other.Y, v.Z + other.Z)\n}\n```\n\nversus G3N:\n\n```Go\n// Add adds other vector to this one.\n// Returns the pointer to this updated vector.\nfunc (v *Vector3) Add(other *Vector3) *Vector3 {\n\tv.X += other.X\n\tv.Y += other.Y\n\tv.Z += other.Z\n\treturn v\n}\n```\n\nThe value-based design allows you to just string together sequences of expressions naturally, without worrying about allocating intermediate variables:\n\n```Go\n// Normal returns the triangle's normal.\nfunc Normal(a, b, c Vec3) Vec3 {\n\tnv := c.Sub(b).Cross(a.Sub(b))\n   ...\n```\n\nThere may be a small performance cost for the value-based approach (comparative benchmarks have not yet been run), but the overall simplicity advantages are significant.\n\nThe matrix types still do use pointer-based logic because they are significantly larger and thus the performance issues are likely to be more important.\n\n# Struct vs. Array Performance: Struct is much faster\n\nThis is a benchmark from Egon Elbre, showing that small arrays can be significantly slower than \na struct: https://github.com/egonelbre/exp/blob/master/bench/vector_fusing/vector_test.go\n\n```\n# array\nBenchmarkAddMul-32                      70589480                17.3 ns/op\n# struct\nBenchmarkStructAddMul-32                1000000000               0.740 ns/op\n```\n\nDiscussion: https://github.com/golang/go/issues/15925\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoki%2Fmat32","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoki%2Fmat32","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoki%2Fmat32/lists"}