Skip to content

Commit

Permalink
Merge pull request #117 from bitshifter/refactor
Browse files Browse the repository at this point in the history
Add support for `f64`, `i32`, `u32` primitive types.

Fixes #70.
Fixes #99.
  • Loading branch information
bitshifter authored Jan 12, 2021
2 parents 9b4579d + 6c92ad6 commit 504052c
Show file tree
Hide file tree
Showing 100 changed files with 35,053 additions and 21,825 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
Cargo.lock
Session.vim
.cargo-ok
cargo-timing*.html
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ The format is based on [Keep a Changelog], and this project adheres to

## [Unreleased]

### Added

* Added `f64` primitive type support
* vectors: `DVec2`, `DVec3` and `DVec4`
* square matrices: `DMat2`, `DMat3` and `DMat4`
* a quaternion type: `DQuat`
* Added `i32` primitive type support
* vectors: `IVec2`, `IVec3` and `IVec4`
* Added `u32` primitive type support
* vectors: `UVec2`, `UVec3` and `UVec4`
* Added `bool` primitive type support
* vectors: `BVec2`, `BVec3` and `BVec4`

### Changed

* `Vec2Mask`, `Vec3Mask` and `Vec4Mask` have been replaced by `BVec2`, `BVec3`,
`BVec3A`, `BVec4` and `BVec4A`. These types ar used by some vector methods
and are not typically referenced directly. This is a breaking change.

### Removed

* `build.rs` has been removed.

## [0.11.3] - 2020-12-29

### Changed
Expand Down
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "glam"
version = "0.11.3" # remember to update html_root_url
version = "0.12.0" # remember to update html_root_url
edition = "2018"
authors = ["Cameron Hart <[email protected]>"]
description = "A simple and fast 3D math library for games and graphics"
Expand All @@ -9,7 +9,6 @@ readme = "README.md"
license = "MIT OR Apache-2.0"
keywords = ["gamedev", "math", "matrix", "vector", "quaternion"]
categories = ["game-engines", "no-std"]
build = "build.rs"

[badges]
travis-ci = { repository = "bitshifter/glam-rs" }
Expand Down Expand Up @@ -40,7 +39,6 @@ libm = ["num-traits/libm"]
[dependencies]
bytemuck = { version = "1.4", optional = true, default-features = false }
mint = { version = "0.5", optional = true, default-features = false }
# enabled by the libm feature, required when building no_std
num-traits = { version = "0.2.14", optional = true, default-features = false }
rand = { version = "0.7", optional = true, default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ and feel of the API has solidified.

## Features

* Only single precision floating point (`f32`) arithmetic is supported
* vectors: `Vec2`, `Vec3`, `Vec3A` `Vec4`
* square matrices: `Mat2`, `Mat3`, `Mat4`
* a quaternion type: `Quat`
* `f32` types
* vectors: `Vec2`, `Vec3`, `Vec3A` and `Vec4`
* square matrices: `Mat2`, `Mat3` and `Mat4`
* a quaternion type: `Quat`
* `f64` types
* vectors: `DVec2`, `DVec3` and `DVec4`
* square matrices: `DMat2`, `DMat3` and `DMat4`
* a quaternion type: `DQuat`
* `i32` types
* vectors: `IVec2`, `IVec3` and `IVec4`
* `u32` types
* vectors: `UVec2`, `UVec3` and `UVec4`
* `bool` types
* vectors: `BVec2`, `BVec3` and `BVec4`

### SIMD

Expand Down Expand Up @@ -105,7 +115,6 @@ The design of this library is guided by a desire for simplicity and good
performance.

* No traits or generics for simplicity of implementation and usage
* Only single precision floating point `f32` arithmetic is supported for now
* All dependencies are optional (e.g. `mint`, `rand` and `serde`)
* Follows the [Rust API Guidelines] where possible
* Aiming for 100% test [coverage]
Expand All @@ -119,7 +128,6 @@ performance.

* Experiment with a using a 4x3 matrix as a 3D transform type that can be more
efficient than `Mat4` for certain operations like inverse and multiplies
* `no-std` support
* `wasm` support

## Inspirations
Expand Down
30 changes: 30 additions & 0 deletions benches/support/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,36 @@ macro_rules! bench_trinop {
};
}

#[macro_export]
macro_rules! bench_select {
($name:ident, $desc:expr, ty => $ty: ident, op => $op: ident, from => $from:expr) => {
pub(crate) fn $name(c: &mut Criterion) {
const SIZE: usize = 1 << 13;
let mut rng = support::PCG32::default();
let inputs1 =
criterion::black_box((0..SIZE).map(|_| $from(&mut rng)).collect::<Vec<_>>());
let inputs2 =
criterion::black_box((0..SIZE).map(|_| $from(&mut rng)).collect::<Vec<_>>());
let masks = vec![$from(&mut rng).$op($from(&mut rng)); SIZE];
// pre-fill output vector with some random value
let mut outputs = vec![$from(&mut rng); SIZE];
let mut i = 0;
c.bench_function($desc, |b| {
b.iter(|| {
i = (i + 1) & (SIZE - 1);
unsafe {
*outputs.get_unchecked_mut(i) = $ty::select(
*masks.get_unchecked(i),
*inputs1.get_unchecked(i),
*inputs2.get_unchecked(i),
);
}
})
});
criterion::black_box(outputs);
}
};
}
#[macro_export]
macro_rules! bench_from_ypr {
($name: ident, $desc: expr, ty => $ty:ty) => {
Expand Down
2 changes: 1 addition & 1 deletion benches/support/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]
use core::f32;
use glam::f32::{Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A, Vec4};
use glam::{Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A, Vec4};

pub struct PCG32 {
state: u64,
Expand Down
2 changes: 1 addition & 1 deletion benches/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod macros;
mod support;

use criterion::{criterion_group, criterion_main, Criterion};
use glam::f32::{TransformRT, TransformSRT};
use glam::{TransformRT, TransformSRT};
use std::ops::Mul;
use support::*;

Expand Down
22 changes: 19 additions & 3 deletions benches/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ mod macros;
mod support;

use criterion::{criterion_group, criterion_main, Criterion};
use glam::f32::Vec2;
use glam::Vec2;
use std::ops::Mul;
use support::{random_mat2, random_srt_mat3, random_vec2};

euler!(vec2_euler, "vec2 euler", ty => Vec2, storage => Vec2, zero => Vec2::zero(), rand => random_vec2);
euler!(
vec2_euler,
"vec2 euler",
ty => Vec2,
storage => Vec2,
zero => Vec2::zero(),
rand => random_vec2);

bench_binop!(
mat2_mul_vec2,
Expand All @@ -33,6 +39,7 @@ bench_binop!(
from1 => random_srt_mat3,
from2 => random_vec2
);

bench_binop!(
vec2_angle_between,
"vec2 angle_between",
Expand All @@ -41,12 +48,21 @@ bench_binop!(
from2 => random_vec2
);

bench_select!(
vec2_select,
"vec2 select",
ty => Vec2,
op => cmple,
from => random_vec2
);

criterion_group!(
benches,
vec2_euler,
mat2_mul_vec2,
mat3_transform_point2,
mat3_transform_vector2,
vec2_euler,
vec2_select,
vec2_angle_between
);

Expand Down
17 changes: 13 additions & 4 deletions benches/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod macros;
mod support;

use criterion::{criterion_group, criterion_main, Criterion};
use glam::f32::Vec3;
use glam::Vec3;
use std::ops::{Add, Mul};
use support::{random_mat3, random_quat, random_srt_mat4, random_vec3};

Expand Down Expand Up @@ -107,18 +107,27 @@ bench_binop!(
from2 => random_vec3
);

bench_select!(
vec3_select,
"vec3 select",
ty => Vec3,
op => cmple,
from => random_vec3
);

criterion_group!(
benches,
vec3_add_vec3,
quat_mul_vec3,
mat3_mul_vec3,
mat4_transform_point3,
mat4_transform_vector3,
quat_mul_vec3,
vec3_add_vec3,
vec3_angle_between,
vec3_euler,
vec3_to_rgb,
vec3_select,
vec3_to_array_fields,
vec3_to_array_into,
vec3_to_rgb,
vec3_to_tuple_into,
);

Expand Down
15 changes: 12 additions & 3 deletions benches/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod macros;
mod support;

use criterion::{criterion_group, criterion_main, Criterion};
use glam::f32::{Vec3, Vec3A};
use glam::{Vec3, Vec3A};
use std::ops::Mul;
use support::{random_mat3, random_quat, random_vec3a};

Expand Down Expand Up @@ -95,15 +95,24 @@ bench_binop!(
from2 => random_vec3a
);

bench_select!(
vec3a_select,
"vec3a select",
ty => Vec3A,
op => cmple,
from => random_vec3a
);

criterion_group!(
benches,
quat_mul_vec3a,
mat3_mul_vec3a,
quat_mul_vec3a,
vec3a_angle_between,
vec3a_euler,
vec3a_to_rgb,
vec3a_select,
vec3a_to_array_deref,
vec3a_to_array_into,
vec3a_to_rgb,
vec3a_to_tuple_into,
vec3a_to_vec3,
);
Expand Down
11 changes: 10 additions & 1 deletion benches/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod macros;
mod support;

use criterion::{criterion_group, criterion_main, Criterion};
use glam::Vec4;
use std::ops::Mul;
use support::{random_srt_mat4, random_vec4};

Expand All @@ -15,6 +16,14 @@ bench_binop!(
from2 => random_vec4
);

criterion_group!(benches, vec4_mul_mat4,);
bench_select!(
vec4_select,
"vec4 select",
ty => Vec4,
op => cmple,
from => random_vec4
);

criterion_group!(benches, vec4_mul_mat4, vec4_select,);

criterion_main!(benches);
31 changes: 0 additions & 31 deletions build.rs

This file was deleted.

7 changes: 7 additions & 0 deletions build_all_msrv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

CARGO='rustup run 1.36.0 cargo'
$CARGO test --features "bytemuck mint rand serde debug-glam-assert transform-types" && \
$CARGO test --features "scalar-math bytemuck mint rand serde debug-glam-assert transform-types" && \
$CARGO test --no-default-features --features "libm scalar-math bytemuck mint rand serde debug-glam-assert transform-types" && \
$CARGO bench --no-run
Loading

0 comments on commit 504052c

Please sign in to comment.