Debian Codegraph @

debian/missing-sources/glam-0.29.3/README.md

raw symbols SCIP
1 # glam
2
3 [![Build Status]][github-ci] [![Coverage Status]][coveralls.io]
4 [![Latest Version]][crates.io] [![docs]][docs.rs]
5 [![Minimum Supported Rust Version]][Rust 1.68.2]
6
7 A simple and fast 3D math library for games and graphics.
8
9 ## Development status
10
11 `glam` is in beta stage. Base functionality has been implemented and the look
12 and feel of the API has solidified.
13
14 ## Features
15
16 * `f32` types
17 * vectors: `Vec2`, `Vec3`, `Vec3A` and `Vec4`
18 * square matrices: `Mat2`, `Mat3`, `Mat3A` and `Mat4`
19 * a quaternion type: `Quat`
20 * affine transformation types: `Affine2` and `Affine3A`
21 * `f64` types
22 * vectors: `DVec2`, `DVec3` and `DVec4`
23 * square matrices: `DMat2`, `DMat3` and `DMat4`
24 * a quaternion type: `DQuat`
25 * affine transformation types: `DAffine2` and `DAffine3`
26 * `i8` types
27 * vectors: `I8Vec2`, `I8Vec3` and `I8Vec4`
28 * `u8` types
29 * vectors: `U16Vec2`, `U16Vec3` and `U16Vec4`
30 * `i16` types
31 * vectors: `I16Vec2`, `I16Vec3` and `I16Vec4`
32 * `u16` types
33 * vectors: `U16Vec2`, `U16Vec3` and `U16Vec4`
34 * `i32` types
35 * vectors: `IVec2`, `IVec3` and `IVec4`
36 * `u32` types
37 * vectors: `UVec2`, `UVec3` and `UVec4`
38 * `i64` types
39 * vectors: `I64Vec2`, `I64Vec3` and `I64Vec4`
40 * `u64` types
41 * vectors: `U64Vec2`, `U64Vec3` and `U64Vec4`
42 * `bool` types
43 * vectors: `BVec2`, `BVec3` and `BVec4`
44
45 ### SIMD
46
47 The `Vec3A`, `Vec4`, `Quat`, `Mat2`, `Mat3A`, `Mat4`, `Affine2` and `Affine3A`
48 types use 128-bit wide SIMD vector types for storage on `x86`, `x86_64` and
49 `wasm32` architectures. As a result, these types are all 16 byte aligned and
50 depending on the size of the type or the type's members, they may contain
51 internal padding. This results in some wasted space in the cases of `Vec3A`,
52 `Mat3A`, `Affine2` and `Affine3A`. However, the use of SIMD generally results
53 in better performance than scalar math.
54
55 `glam` outperforms similar Rust libraries for common operations as tested by the
56 [`mathbench`][mathbench] project.
57
58 [mathbench]: https://github.com/bitshifter/mathbench-rs
59
60 ### Enabling SIMD
61
62 SIMD is supported on `x86`, `x86_64` and `wasm32` targets.
63
64 * `SSE2` is enabled by default on `x86_64` targets.
65 * To enable `SSE2` on `x86` targets add `-C target-feature=+sse2` to
66 `RUSTCFLAGS`.
67 * `NEON` is enabled by default on `aarch64` targets.
68 * To enable `NEON` on `aarch64` targets add `-C target-feature=+neon` to `RUSTFLAGS`.
69 * To enable `simd128` on `wasm32` targets add `-C target-feature=+simd128` to
70 `RUSTFLAGS`.
71 * Experimental [portable simd] support can be enabled with the `core-simd`
72 feature. This requires the nightly compiler as it is still unstable in Rust.
73
74 Note that SIMD on `wasm32` passes tests but has not been benchmarked,
75 performance may or may not be better than scalar math.
76
77 [portable simd]: https://doc.rust-lang.org/core/simd/index.html
78
79 ### `no_std` support
80
81 `no_std` support can be enabled by compiling with `--no-default-features` to
82 disable `std` support and `--features libm` for math functions that are only
83 defined in `std`. For example:
84
85 ```toml
86 [dependencies]
87 glam = { version = "0.29.3", default-features = false, features = ["libm"] }
88 ```
89
90 To support both `std` and `no_std` builds in project, you can use the following
91 in your `Cargo.toml`:
92
93 ```toml
94 [features]
95 default = ["std"]
96
97 std = ["glam/std"]
98 libm = ["glam/libm"]
99
100 [dependencies]
101 glam = { version = "0.29.3", default-features = false }
102 ```
103
104 Alternatively, you can use the `nostd-libm` feature.
105 This will always include a `libm` dependency, but allows the user to still override it with `std` if they prefer.
106 This will allow your crate to compile with default features disabled, instead of forcing the user to enable either `std` or `libm`.
107
108 ```toml
109 [features]
110 default = ["std"]
111
112 std = ["glam/std"]
113 libm = ["glam/libm"]
114
115 [dependencies]
116 glam = { version = "0.30.0", default-features = false, features = ["nostd-libm"] }
117 ```
118
119 ### Optional features
120
121 * [`approx`] - traits and macros for approximate float comparisons
122 * [`bytemuck`] - for casting into slices of bytes
123 * [`libm`] - uses `libm` math functions instead of `std`
124 * [`nostd-libm`] - uses `libm` math functions if `std` is not available
125 * [`mint`] - for interoperating with other 3D math libraries
126 * [`rand`] - implementations of `Distribution` trait for all `glam` types.
127 * [`serde`] - implementations of `Serialize` and `Deserialize` for all `glam`
128 types. Note that serialization should work between builds of `glam` with and
129 without SIMD enabled
130 * [`rkyv`] - implementations of `Archive`, `Serialize` and `Deserialize` for
131 all `glam` types. Note that serialization is not interoperable with and
132 without the `scalar-math` feature. It should work between all other builds of
133 `glam`. Endian conversion is currently not supported
134 * [`bytecheck`] - to perform archive validation when using the `rkyv` feature
135
136 [`approx`]: https://docs.rs/approx
137 [`bytemuck`]: https://docs.rs/bytemuck
138 [`libm`]: https://github.com/rust-lang/libm
139 [`mint`]: https://github.com/kvark/mint
140 [`rand`]: https://github.com/rust-random/rand
141 [`serde`]: https://serde.rs
142 [`rkyv`]: https://github.com/rkyv/rkyv
143 [`bytecheck`]: https://github.com/rkyv/bytecheck
144
145 ### Feature gates
146
147 * `scalar-math` - compiles with SIMD support disabled
148 * `debug-glam-assert` - adds assertions in debug builds which check the validity
149 of parameters passed to `glam` to help catch runtime errors
150 * `glam-assert` - adds validation assertions to all builds
151 * `cuda` - forces `glam` types to match expected [cuda alignment]
152 * `fast-math` - By default, glam attempts to provide bit-for-bit identical
153 results on all platforms. Using this feature will enable platform specific
154 optimizations that may not be identical to other platforms. **Intermediate
155 libraries should not use this feature and defer the decision to the final
156 binary build**.
157 * `core-simd` - enables SIMD support via the [portable simd] module. This is an
158 unstable feature which requires a nightly Rust toolchain and `std` support.
159
160 [cuda alignment]: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#built-in-vector-types
161
162 ### Minimum Supported Rust Version (MSRV)
163
164 The minimum supported version of Rust for `glam` is `1.68.2`.
165
166 ## Conventions
167
168 ### Column vectors
169
170 `glam` interprets vectors as column matrices (also known as "column vectors")
171 meaning when transforming a vector with a matrix the matrix goes on the left,
172 e.g. `v' = Mv`. DirectX uses row vectors, OpenGL uses column vectors. There
173 are pros and cons to both.
174
175 ### Column-major order
176
177 Matrices are stored in column major format. Each column vector is stored in
178 contiguous memory.
179
180 ### Co-ordinate system
181
182 `glam` is co-ordinate system agnostic and intends to support both right-handed
183 and left-handed conventions.
184
185 ## Design Philosophy
186
187 The design of this library is guided by a desire for simplicity and good
188 performance.
189
190 * No generics and minimal traits in the public API for simplicity of usage
191 * All dependencies are optional (e.g. `mint`, `rand` and `serde`)
192 * Follows the [Rust API Guidelines] where possible
193 * Aiming for 100% test [coverage]
194 * Common functionality is benchmarked using [Criterion.rs]
195
196 [Rust API Guidelines]: https://rust-lang-nursery.github.io/api-guidelines/
197 [coverage]: coveralls.io
198 [Criterion.rs]: https://bheisler.github.io/criterion.rs/book/index.html
199
200 ## Architecture
201
202 See [ARCHITECTURE.md] for details on `glam`'s internals.
203
204 [ARCHITECTURE.md]: ARCHITECTURE.md
205
206 ## Inspirations
207
208 There were many inspirations for the interface and internals of glam from the
209 Rust and C++ worlds. In particular:
210
211 * [How to write a maths library in 2016] inspired the initial `Vec3A`
212 implementation
213 * [Realtime Math] - header only C++11 with SSE and NEON SIMD intrinsic support
214 * [DirectXMath] - header only SIMD C++ linear algebra library for use in games
215 and graphics apps
216 * `glam` is a play on the name of the popular C++ library [GLM]
217
218 [How to write a maths library in 2016]: http://www.codersnotes.com/notes/maths-lib-2016/
219 [Realtime Math]: https://github.com/nfrechette/rtm
220 [DirectXMath]: https://docs.microsoft.com/en-us/windows/desktop/dxmath/directxmath-portal
221 [GLM]: https://glm.g-truc.net
222
223 ## License
224
225 Licensed under either of
226
227 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE)
228 or http://www.apache.org/licenses/LICENSE-2.0)
229 * MIT license ([LICENSE-MIT](LICENSE-MIT)
230 or http://opensource.org/licenses/MIT)
231
232 at your option.
233
234 ## Contribution
235
236 Contributions in any form (issues, pull requests, etc.) to this project must
237 adhere to Rust's [Code of Conduct].
238
239 Unless you explicitly state otherwise, any contribution intentionally submitted
240 for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
241 dual licensed as above, without any additional terms or conditions.
242
243 If you are interested in contributing or have a request or suggestion
244 [start a discussion] on GitHub. See [CONTRIBUTING.md] for more information for
245 contributors.
246
247 Most code in `glam` is generated, see the [codegen README] for details.
248
249 Thank you to all of the `glam` [contributors]!
250
251 [Code of Conduct]: https://www.rust-lang.org/en-US/conduct.html
252 [start a discussion]: https://github.com/bitshifter/glam-rs/discussions
253 [CONTRIBUTING.md]: CONTRIBUTING.md
254 [codegen README]: codegen/README.md
255 [contributors]: https://github.com/bitshifter/glam-rs/graphs/contributors
256
257 ## Support
258
259 The [Game Development in Rust Discord] and [Bevy Engine Discord] servers are
260 not official support channels but can be good places to ask for help with
261 `glam`.
262
263 [Game Development in Rust Discord]: https://discord.gg/yNtPTb2
264 [Bevy Engine Discord]: https://discord.gg/gMUk5Ph
265
266 ## Attribution
267
268 `glam` contains code ported from the following C++ libraries:
269
270 * [DirectXMath] - MIT License - Copyright (c) 2011-2020 Microsoft Corp
271 * [Realtime Math] - MIT License - Copyright (c) 2018 Nicholas Frechette
272 * [GLM] - MIT License - Copyright (c) 2005 - G-Truc Creation
273
274 See [ATTRIBUTION.md] for details.
275
276 [ATTRIBUTION.md]: ATTRIBUTION.md
277
278 [Build Status]: https://github.com/bitshifter/glam-rs/actions/workflows/ci.yml/badge.svg
279 [github-ci]: https://github.com/bitshifter/glam-rs/actions/workflows/ci.yml
280 [Coverage Status]: https://coveralls.io/repos/github/bitshifter/glam-rs/badge.svg?branch=main
281 [coveralls.io]: https://coveralls.io/github/bitshifter/glam-rs?branch=main
282 [Latest Version]: https://img.shields.io/crates/v/glam.svg
283 [crates.io]: https://crates.io/crates/glam/
284 [docs]: https://docs.rs/glam/badge.svg
285 [docs.rs]: https://docs.rs/glam/
286 [Minimum Supported Rust Version]: https://img.shields.io/badge/Rust-1.68.2-blue?color=fc8d62&logo=rust
287 [Rust 1.68.2]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1682-2023-03-28