Skip to content

Commit

Permalink
Made everything more const
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob2309 committed Aug 17, 2021
1 parent 7e4e361 commit a5d8542
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gfx-maths"
version = "0.2.0"
version = "0.2.1"
authors = [ "Robin Quint" ]
edition = "2018"
description = "Implementations for the most essential Graphics Math operations"
Expand Down
8 changes: 4 additions & 4 deletions src/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const fn cr(c: usize, r: usize) -> usize {

impl Mat4 {
/// Creates the identity matrix.
pub fn identity() -> Self {
pub const fn identity() -> Self {
Self {
values: [
1.0, 0.0, 0.0, 0.0,
Expand All @@ -43,7 +43,7 @@ impl Mat4 {
}

/// Creates a 3D translation matrix.
pub fn translate(t: Vec3) -> Self {
pub const fn translate(t: Vec3) -> Self {
let mut res = Self::identity();

res.values[cr(3, 0)] = t.x;
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Mat4 {
}

/// Creates a 3D scale matrix.
pub fn scale(s: Vec3) -> Self {
pub const fn scale(s: Vec3) -> Self {
let mut res = Self::identity();

res.values[cr(0, 0)] = s.x;
Expand Down Expand Up @@ -205,7 +205,7 @@ impl Mat4 {
}

/// Returns a value indexed by `column` and `row`
pub fn get(&self, column: usize, row: usize) -> f32 {
pub const fn get(&self, column: usize, row: usize) -> f32 {
self.values[cr(column, row)]
}

Expand Down
4 changes: 2 additions & 2 deletions src/quaternion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ impl Default for Quaternion {
}

impl Quaternion {
pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
Self{x, y, z, w}
}

/// Creates (0, 0, 0, 1), which represents no rotation
pub fn identity() -> Self {
pub const fn identity() -> Self {
Self{x: 0.0, y: 0.0, z: 0.0, w: 1.0}
}

Expand Down
6 changes: 3 additions & 3 deletions src/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ impl Default for Vec2 {
}

impl Vec2 {
pub fn new(x: f32, y: f32) -> Self {
pub const fn new(x: f32, y: f32) -> Self {
Self{x, y}
}

/// Creates (0, 0)
pub fn zero() -> Self {
pub const fn zero() -> Self {
Self{x: 0.0, y: 0.0}
}

/// Creates (1, 1)
pub fn one() -> Self {
pub const fn one() -> Self {
Self{x: 1.0, y: 1.0}
}

Expand Down
6 changes: 3 additions & 3 deletions src/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ impl Default for Vec3 {
}

impl Vec3 {
pub fn new(x: f32, y: f32, z: f32) -> Self {
pub const fn new(x: f32, y: f32, z: f32) -> Self {
Self{x, y, z}
}

/// Creates (0, 0, 0)
pub fn zero() -> Self {
pub const fn zero() -> Self {
Self{x: 0.0, y: 0.0, z: 0.0}
}

/// Creates (1, 1, 1)
pub fn one() -> Self {
pub const fn one() -> Self {
Self{x: 1.0, y: 1.0, z: 1.0}
}

Expand Down
6 changes: 3 additions & 3 deletions src/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ impl Default for Vec4 {
}

impl Vec4 {
pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
Self{x, y, z, w}
}

/// Creates (0, 0, 0, 0)
pub fn zero() -> Self {
pub const fn zero() -> Self {
Self{x: 0.0, y: 0.0, z: 0.0, w: 0.0}
}

/// Creates (1, 1, 1, 1)
pub fn one() -> Self {
pub const fn one() -> Self {
Self{x: 1.0, y: 1.0, z: 1.0, w: 1.0}
}

Expand Down

0 comments on commit a5d8542

Please sign in to comment.