vector_math
Crystal library for basic 2D, 3D, and 4D vector and matrix math.
It's currently quite small, but includes:
- Everything is a struct, so everything happens on the stack
- Completely immutable, so behavior is easy to reason about
- Operator overloading for +, -, * and /
- Rotation and translation helpers for 4D matrices
Installation
- Add the dependency to your
shard.yml
:
dependencies:
vector_math:
github: ajselvig/crystal_vector_math
- Run
shards install
Usage
require "vector_math"
include VectorMath
# 2D vectors
vec2(1.0, 2.0) + vec2(3.0, 4.0)
# => [4.0, 6.0]
vec2(2.0, 4.0, 6.0) / 2
# => [1.0, 2.0, 3.0]
Contributing
- Fork it (https://github.com/ajselvig/crystal_vector_math/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Andy Selvig - creator and maintainer