Skip to content

Commit

Permalink
Implement fract as self - self.trunc() rather than GLSL's self - self…
Browse files Browse the repository at this point in the history
….floor() (#499)

* Add `fract_gl`.
  • Loading branch information
bitshifter committed Mar 23, 2024
1 parent bb32f1d commit 9f694bc
Show file tree
Hide file tree
Showing 21 changed files with 282 additions and 39 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog], and this project adheres to
[Semantic Versioning].

## [0.27.0] - 2024-03-23

### Breaking changes

* Changed implementation of vector `fract` method to match the Rust
implementation instead of the GLSL implementation, that is `self -
self.trunc()` instead of `self - self.floor()`.

### Added

* Added vector `fract_gl` which uses the GLSL specification of fract,
`self - self.floor()`.

## [0.26.0] - 2024-03-18

### Breaking changes
Expand Down Expand Up @@ -1043,7 +1056,8 @@ The format is based on [Keep a Changelog], and this project adheres to

[Keep a Changelog]: https://keepachangelog.com/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
[Unreleased]: https://github.com/bitshifter/glam-rs/compare/0.26.0...HEAD
[Unreleased]: https://github.com/bitshifter/glam-rs/compare/0.27.0...HEAD
[0.27.0]: https://github.com/bitshifter/glam-rs/compare/0.26.0...0.27.0
[0.26.0]: https://github.com/bitshifter/glam-rs/compare/0.25.0...0.26.0
[0.25.0]: https://github.com/bitshifter/glam-rs/compare/0.24.2...0.25.0
[0.24.2]: https://github.com/bitshifter/glam-rs/compare/0.24.1...0.24.2
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "glam"
version = "0.26.0" # remember to update html_root_url
version = "0.27.0" # remember to update html_root_url
edition = "2021"
authors = ["Cameron Hart <cameron.hart@gmail.com>"]
description = "A simple and fast 3D math library for games and graphics"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -78,7 +78,7 @@ defined in `std`. For example:

```toml
[dependencies]
glam = { version = "0.26", default-features = false, features = ["libm"] }
glam = { version = "0.27", default-features = false, features = ["libm"] }
```

To support both `std` and `no_std` builds in project, you can use the following
Expand All @@ -92,7 +92,7 @@ std = ["glam/std"]
libm = ["glam/libm"]

[dependencies]
glam = { version = "0.26", default-features = false }
glam = { version = "0.27", default-features = false }
```

### Optional features
Expand Down
18 changes: 16 additions & 2 deletions codegen/templates/vec.rs.tera
Expand Up @@ -1556,13 +1556,27 @@ impl {{ self_t }} {
{% endif %}
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/coresimd/vec3a.rs
Expand Up @@ -649,13 +649,27 @@ impl Vec3A {
Self(self.0.trunc())
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/coresimd/vec4.rs
Expand Up @@ -629,13 +629,27 @@ impl Vec4 {
Self(self.0.trunc())
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/scalar/vec3a.rs
Expand Up @@ -686,13 +686,27 @@ impl Vec3A {
}
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/scalar/vec4.rs
Expand Up @@ -733,13 +733,27 @@ impl Vec4 {
}
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/sse2/vec3a.rs
Expand Up @@ -697,13 +697,27 @@ impl Vec3A {
Self(unsafe { m128_trunc(self.0) })
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/sse2/vec4.rs
Expand Up @@ -678,13 +678,27 @@ impl Vec4 {
Self(unsafe { m128_trunc(self.0) })
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/vec2.rs
Expand Up @@ -615,13 +615,27 @@ impl Vec2 {
}
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/vec3.rs
Expand Up @@ -677,13 +677,27 @@ impl Vec3 {
}
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/wasm32/vec3a.rs
Expand Up @@ -668,13 +668,27 @@ impl Vec3A {
Self(f32x4_trunc(self.0))
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down
18 changes: 16 additions & 2 deletions src/f32/wasm32/vec4.rs
Expand Up @@ -656,13 +656,27 @@ impl Vec4 {
Self(f32x4_trunc(self.0))
}

/// Returns a vector containing the fractional part of the vector, e.g. `self -
/// self.floor()`.
/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
///
/// Note that this differs from the GLSL implementation of `fract` which returns
/// `self - self.floor()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract(self) -> Self {
self - self.trunc()
}

/// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
///
/// Note that this differs from the Rust implementation of `fract` which returns
/// `self - self.trunc()`.
///
/// Note that this is fast but not precise for large numbers.
#[inline]
#[must_use]
pub fn fract_gl(self) -> Self {
self - self.floor()
}

Expand Down

0 comments on commit 9f694bc

Please sign in to comment.