https://github.com/fireblade-engine/math
A dependency free, lightweight, fast math library for 2D and 3D vectors, quaternions and matrices in Swift with (optional) SIMD support.
https://github.com/fireblade-engine/math
2d 3d 3d-vectors cross-platform game-development gamedev math matrices matrix numerics quaternion quaternions simd simd-support spm swift swift-package-manager vector vector-graphics vectors
Last synced: 3 months ago
JSON representation
A dependency free, lightweight, fast math library for 2D and 3D vectors, quaternions and matrices in Swift with (optional) SIMD support.
- Host: GitHub
- URL: https://github.com/fireblade-engine/math
- Owner: fireblade-engine
- License: mit
- Created: 2020-09-02T07:39:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2026-02-10T16:33:15.000Z (3 months ago)
- Last Synced: 2026-02-10T17:02:07.832Z (3 months ago)
- Topics: 2d, 3d, 3d-vectors, cross-platform, game-development, gamedev, math, matrices, matrix, numerics, quaternion, quaternions, simd, simd-support, spm, swift, swift-package-manager, vector, vector-graphics, vectors
- Language: Swift
- Homepage:
- Size: 547 KB
- Stars: 44
- Watchers: 2
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# FirebladeMath
[](LICENSE)
[](https://github.com/fireblade-engine/math/actions/workflows/ci-macos.yml)
[](https://github.com/fireblade-engine/math/actions/workflows/ci-linux.yml)
[](https://github.com/fireblade-engine/math/actions/workflows/ci-windows.yml)
[](https://swiftpackageindex.com/fireblade-engine/math)
[](https://swiftpackageindex.com/fireblade-engine/math)
A dependency-free, lightweight, fast math library for 2D and 3D vectors, quaternions, and matrices in Swift with (optional) SIMD support. It is developed and maintained as part of the [Fireblade Game Engine project](https://github.com/fireblade-engine).
## ✨ Features
- **Vectors:** `Vec2`, `Vec3`, `Vec4` for `Float`, `Double`, `Int`, and `UInt`.
- **Matrices:** `Mat2x2`, `Mat3x3`, `Mat4x4` for `Float` and `Double`.
- **Quaternions:** `Quat4f` and `Quat4d`.
- **Geometric Types:** `Point`, `Size`, `Rect`.
- **Math Functions:** A comprehensive set of functions including `sin`, `cos`, `tan`, `asin`, `acos`, `atan2`, `dot`, `cross`, `normalize`, `reflect`, `refract`, and many more.
- **SIMD Support:** Leveraging hardware acceleration where available, with a fallback implementation when SIMD is not supported.
- **Swift 6 Ready:** Fully compatible with Swift 6 and `Sendable` conformance.
## 🚀 Getting Started
### 📋 Prerequisites
* Swift 6.1 or higher
* Swift Package Manager (SPM)
### 💻 Installation
Add Fireblade Math as a dependency to your `Package.swift` file:
```swift
// swift-tools-version: 6.1
import PackageDescription
let package = Package(
name: "YourPackageName",
dependencies: [
.package(url: "https://github.com/fireblade-engine/math.git", from: "1.0.0")
],
targets: [
.target(
name: "YourTargetName",
dependencies: ["FirebladeMath"])
]
)
```
### 🛠 SIMD Traits
Starting with version 1.0.0, FirebladeMath uses Swift traits to manage SIMD support. By default, SIMD is enabled on Apple platforms. You can manually control it in your package configuration if needed.
## 📖 Usage Examples
### Vectors
```swift
import FirebladeMath
let v1 = Vec3f(1, 2, 3)
let v2 = Vec3f(4, 5, 6)
let dotProduct = dot(v1, v2)
let crossProduct = cross(v1, v2)
let unitVector = normalize(v1)
```
### Matrices
```swift
import FirebladeMath
// Create a transformation matrix
var modelMatrix = Mat4x4f.identity
modelMatrix.translate(by: [10, 20, 30])
modelMatrix.rotate(by: .pi / 2, axis: [0, 1, 0])
// Project a point
let projection = Mat4x4f.perspectiveRH(fovy: .pi / 4, aspect: 16/9, zNear: 0.1, zFar: 100)
```
### Quaternions
```swift
import FirebladeMath
let q = Quat4f(angle: .pi / 4, axis: [0, 1, 0])
let rotatedVector = q * Vec3f(1, 0, 0)
```
## 💁 How to contribute
If you want to contribute please see the [CONTRIBUTION GUIDE](CONTRIBUTING.md) first.
1. `git clone git@github.com:fireblade-engine/math.git`
2. `cd math`
3. `make setupEnvironment`
Before committing code please ensure to run:
- `make precommit`
This project is currently maintained by [@ctreffs](https://github.com/ctreffs).
See also the list of [contributors](https://github.com/fireblade-engine/math/contributors) who participated in this project.
## 🔏 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ♻ Alternatives
- [alejandro-isaza/Upsurge](https://github.com/alejandro-isaza/Upsurge)
- [capnslipp/SCNMathExtensions](https://github.com/capnslipp/SCNMathExtensions)
- [davidskrundz/math](https://github.com/davidskrundz/math)
- [dn-m/Math](https://github.com/dn-m/Math)
- [Jounce/Surge](https://github.com/Jounce/Surge)
- [jph00/basemath](https://github.com/jph00/basemath)
- [mattt/euler](https://github.com/mattt/euler)
- [nicklockwood/VectorMath](https://github.com/nicklockwood/VectorMath)
- [SwiftGFX/SwiftMath](https://github.com/SwiftGFX/SwiftMath)
- [SwiftGL/Math](https://github.com/SwiftGL/Math)
- [taketo1024/swiftymath](https://github.com/taketo1024/swiftymath)
- [timsearle/euclid](https://github.com/timsearle/euclid)