Skip to content

Commit

Permalink
Use trait Euclid less.
Browse files Browse the repository at this point in the history
Note: this has nothing to do with the `euclid` library the previous
commits were working with. That is just a coincidence of tidying up
different parts of math code.
  • Loading branch information
kpreid committed May 22, 2024
1 parent bb6e590 commit f9633bd
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 44 deletions.
17 changes: 7 additions & 10 deletions all-is-cubes-base/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,19 @@ macro_rules! notnan {
};
}

#[cfg(not(feature = "std"))]
#[cfg(not(any(feature = "std", test)))]
#[allow(dead_code)] // TODO: Not sure why we sometimes get "trait `Euclid` is never used" w/o this
/// Identical to [`num_traits::Euclid`] except that its signatures are compatible with
/// `std` versions.
///
/// Note: this code is duplicated between `all-is-cubes` and
/// `all-is-cubes-base` so that it doesn't need to be public.
pub(crate) trait Euclid {
#[allow(dead_code)]
fn div_euclid(self, rhs: Self) -> Self;
// fn div_euclid(self, rhs: Self) -> Self;
fn rem_euclid(self, rhs: Self) -> Self;
}
#[cfg(not(feature = "std"))]
#[cfg(not(any(feature = "std", test)))]
impl<T: num_traits::Euclid + Copy> Euclid for T {
fn div_euclid(self, rhs: Self) -> Self {
<T as num_traits::Euclid>::div_euclid(&self, &rhs)
}
// fn div_euclid(self, rhs: Self) -> Self {
// <T as num_traits::Euclid>::div_euclid(&self, &rhs)
// }
fn rem_euclid(self, rhs: Self) -> Self {
<T as num_traits::Euclid>::rem_euclid(&self, &rhs)
}
Expand Down
5 changes: 0 additions & 5 deletions all-is-cubes/src/character/exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ use euclid::{vec3, Point3D};
#[allow(unused_imports)]
use num_traits::float::Float as _;

/// Acts as polyfill for float methods
#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
use crate::math::Euclid as _;

use crate::camera;
use crate::math::FreeCoordinate;
use crate::raycast::Ray;
Expand Down
3 changes: 0 additions & 3 deletions all-is-cubes/src/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ use euclid::{vec3, Point3D, Vector3D};
#[allow(unused_imports)]
use num_traits::float::FloatCore as _;

#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
use crate::math::Euclid as _;
use crate::math::{
Cube, FreeCoordinate, FreePoint, FreeVector, GridAab, GridCoordinate, GridPoint,
};
Expand Down
20 changes: 0 additions & 20 deletions all-is-cubes/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@ pub use all_is_cubes_base::{notnan, rgb_const, rgba_const};
#[doc = include_str!("save/serde-warning.md")]
pub use all_is_cubes_base::math::GridAab;

#[cfg(not(feature = "std"))]
/// Identical to [`num_traits::Euclid`] except that its signatures are compatible with
/// `std` versions.
///
/// Note: this code is duplicated between `all-is-cubes` and
/// `all-is-cubes-base` so that it doesn't need to be public.
pub(crate) trait Euclid {
fn div_euclid(self, rhs: Self) -> Self;
fn rem_euclid(self, rhs: Self) -> Self;
}
#[cfg(not(feature = "std"))]
impl<T: num_traits::Euclid + Copy> Euclid for T {
fn div_euclid(self, rhs: Self) -> Self {
<T as num_traits::Euclid>::div_euclid(&self, &rhs)
}
fn rem_euclid(self, rhs: Self) -> Self {
<T as num_traits::Euclid>::rem_euclid(&self, &rhs)
}
}

#[inline]
pub(crate) fn smoothstep(x: f64) -> f64 {
let x = x.clamp(0.0, 1.0);
Expand Down
3 changes: 0 additions & 3 deletions all-is-cubes/src/physics/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ use super::collision::{
};
use crate::block::{BlockCollision, Resolution};
use crate::fluff::Fluff;
#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
use crate::math::Euclid as _;
use crate::math::{Aab, Face7, FreeCoordinate, FreePoint, FreeVector, Geometry as _};
use crate::physics::{StopAt, Velocity, POSITION_EPSILON};
use crate::raycast::Ray;
Expand Down
3 changes: 0 additions & 3 deletions all-is-cubes/src/raytracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ use rayon::iter::{IntoParallelIterator as _, ParallelIterator as _};
use crate::block::{Evoxels, Resolution, AIR};
use crate::camera::NdcPoint2;
use crate::camera::{Camera, GraphicsOptions, TransparencyOption};
#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
use crate::math::Euclid as _;
use crate::math::{
rgb_const, smoothstep, Cube, Face6, Face7, FreeCoordinate, FreePoint, FreeVector, GridAab,
GridMatrix, Intensity, Rgb, Rgba, Vol,
Expand Down

0 comments on commit f9633bd

Please sign in to comment.