From 068fdbe0b60145fa0ce77757dc08c7e122df2a9c Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Sat, 12 Sep 2020 17:16:33 -0700 Subject: [PATCH] Update dependencies --- README.md | 2 +- poisson-visualisation/Cargo.toml | 12 ++++++------ poisson-visualisation/src/main.rs | 11 +++++------ poisson/Cargo.toml | 9 +++++---- poisson/src/algorithm/bridson.rs | 11 ++++++----- poisson/src/algorithm/ebeida.rs | 9 +++++---- poisson/src/lib.rs | 26 ++++++++++---------------- poisson/src/utils/math.rs | 2 +- poisson/src/utils/mod.rs | 18 +++++++++--------- poisson/tests/validity.rs | 2 +- 10 files changed, 49 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 657790cb..dbd34975 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ as distribution for sampling in rendering or for (re)meshing. # Usage -Works with nalgebra 0.16 and rand 0.5 +Works with nalgebra 0.22 and rand 0.7 ```rust extern crate nalgebra as na; diff --git a/poisson-visualisation/Cargo.toml b/poisson-visualisation/Cargo.toml index 150f5e27..0c755b50 100644 --- a/poisson-visualisation/Cargo.toml +++ b/poisson-visualisation/Cargo.toml @@ -5,10 +5,10 @@ authors = ["WaDelma <>"] edition = "2018" [dependencies] -nalgebra = "0.17" -image = "0.21.0" -clap = "2.32.0" -rand = "0.6" -lab = "0.4" -fnv = "1.0" +nalgebra = { version = "0.22", features = [ "alga" ] } +image = "0.23" +clap = "2" +rand = "0.7" +lab = "0.8" +fnv = "1" poisson = { path = "../poisson" } \ No newline at end of file diff --git a/poisson-visualisation/src/main.rs b/poisson-visualisation/src/main.rs index c893d993..ba6ccafb 100644 --- a/poisson-visualisation/src/main.rs +++ b/poisson-visualisation/src/main.rs @@ -2,7 +2,7 @@ use clap::{App, Arg, ArgMatches, arg_enum, _clap_count_exprs, value_t}; use poisson::{Builder, Type, algorithm::{Bridson, Ebeida}}; -use rand::{rngs::SmallRng, FromEntropy, Rng, seq::SliceRandom, SeedableRng}; +use rand::{rngs::SmallRng, Rng, seq::SliceRandom, SeedableRng}; use nalgebra::Vector2; @@ -112,13 +112,12 @@ fn visualise(m: ArgMatches) { let mut image = ImageBuffer::new(width, height); for p in points { let pp = ps.pop().unwrap(); - let col = Rgb { - data: Lab { + let col = Rgb(Lab { l: style_rng.gen::() * 80. + 10., a: pp.x * 256. - 128., b: pp.y * 256. - 128. }.to_rgb() - }; + ); let x = p.x * width as f32; let y = p.y * height as f32; @@ -150,10 +149,10 @@ fn visualise(m: ArgMatches) { if style == Style::Colorful { image[(xxx, yyy)] = col; } else { - image[(xxx, yyy)] = Rgb { data: [255, 255, 255] }; + image[(xxx, yyy)] = Rgb([255, 255, 255]); } if style == Style::Plain && (xx == 0. || yy == 0.) { - image[(xxx, yyy)] = Rgb { data: [255, 0, 0] }; + image[(xxx, yyy)] = Rgb([255, 0, 0]); } } } diff --git a/poisson/Cargo.toml b/poisson/Cargo.toml index da5bc7e8..cd12c8d1 100644 --- a/poisson/Cargo.toml +++ b/poisson/Cargo.toml @@ -15,12 +15,13 @@ travis-ci = { repository = "WaDelma/poisson" } coveralls = { repository = "WaDelma/poisson", service = "github" } [dependencies] -rand = "0.6" -alga = "0.8" +rand = { version = "0.7", features = [ "small_rng" ] } +rand_distr = "0.2" +alga = "0.9" num-traits = "0.2" -lazy_static = "1.3" +lazy_static = "1" modulo = "0.1" sphere = "0.3" [dev-dependencies] -nalgebra = "0.17" +nalgebra = { version = "0.22", features = [ "alga" ] } diff --git a/poisson/src/algorithm/bridson.rs b/poisson/src/algorithm/bridson.rs index 25da8b42..b3680fe6 100644 --- a/poisson/src/algorithm/bridson.rs +++ b/poisson/src/algorithm/bridson.rs @@ -2,10 +2,11 @@ use crate::algorithm::{Algorithm, Creator}; use crate::utils::*; use crate::{Builder, Float, Vector}; -use num_traits::NumCast; +use num_traits::{Float as NumFloat, NumCast}; use rand::distributions::{Distribution, Standard, Uniform}; -use rand::{distributions::StandardNormal, Rng}; +use rand::Rng; +use rand_distr::StandardNormal; use sphere::sphere_volume; @@ -100,10 +101,10 @@ where // how much sphere can fill it at best case and just figure out how many fills are still needed. let dim = V::dimension(); let spacing = self.grid.cell(); - let grid_volume = F::cast(upper) * spacing.powi(dim as i32); + let grid_volume = F::cast(upper) * NumFloat::powi(spacing, dim as i32); let sphere_volume = sphere_volume(F::cast(2) * poisson.radius, dim as u64); let lower: F = grid_volume / sphere_volume; - let mut lower = lower.floor().to_usize().expect( + let mut lower = NumFloat::floor(lower).to_usize().expect( "Grids volume divided by spheres volume should be always \ castable to usize.", ); @@ -167,7 +168,7 @@ where loop { let mut result = V::zero(); for n in 0..V::dimension() { - result[n] = NumCast::from(rand.sample(StandardNormal)) + result[n] = NumCast::from(rand.sample::(StandardNormal)) .expect("The f64 produced by StandardNormal should be always castable to float."); } let result = result.normalize() * rand.gen() * max; diff --git a/poisson/src/algorithm/ebeida.rs b/poisson/src/algorithm/ebeida.rs index 6d92946b..90dfc4bf 100644 --- a/poisson/src/algorithm/ebeida.rs +++ b/poisson/src/algorithm/ebeida.rs @@ -2,6 +2,7 @@ use crate::algorithm::{Algorithm, Creator}; use crate::utils::*; use crate::{Builder, Float, Vector}; +use num_traits::{Float as NumFloat}; use rand::distributions::{Distribution, Standard, Uniform}; use rand::Rng; @@ -46,7 +47,7 @@ where success: 0, outside: vec![], mantissa_digits: { - let (mantissa, _, _) = F::max_value().integer_decode(); + let (mantissa, _, _) = ::max_value().integer_decode(); mantissa.count_ones() as usize }, } @@ -156,10 +157,10 @@ where let dim = V::dimension(); let side = 2usize.pow(self.level as u32); let spacing = self.grid.cell() / F::cast(side); - let grid_volume = F::cast(self.indices.len()) * spacing.powi(dim as i32); + let grid_volume = F::cast(self.indices.len()) * NumFloat::powi(spacing, dim as i32); let sphere_volume = sphere_volume(F::cast(2) * poisson.radius, dim as u64); let lower = grid_volume / sphere_volume; - let mut lower = lower.floor().to_usize().expect( + let mut lower = NumFloat::floor(lower).to_usize().expect( "Grids volume divided by spheres volume should be always \ castable to usize.", ); @@ -217,7 +218,7 @@ where // TODO: This does 4^d checking of points even though it could be done 3^d let side = 2usize.pow(level as u32); let spacing = grid.cell() / F::cast(side); - let sqradius = (F::cast(2) * poisson.radius).powi(2); + let sqradius = NumFloat::powi(F::cast(2) * poisson.radius, 2); let parent = get_parent(index.clone(), level); each_combination(&[0, 1]) .map(|t| (index.clone() + t) * spacing) diff --git a/poisson/src/lib.rs b/poisson/src/lib.rs index b1cb1fe5..99450e4a 100644 --- a/poisson/src/lib.rs +++ b/poisson/src/lib.rs @@ -21,7 +21,7 @@ //! extern crate rand; //! extern crate nalgebra as na; //! -//! use rand::FromEntropy; +//! use rand::SeedableRng; //! use rand::rngs::SmallRng; //! //! use poisson::{Builder, Type, algorithm}; @@ -41,7 +41,7 @@ //! ````rust //! # extern crate nalgebra as na; //! # use poisson::{Builder, Type, algorithm}; -//! # use rand::FromEntropy; +//! # use rand::SeedableRng; //! # use rand::rngs::SmallRng; //! //! fn main() { @@ -59,14 +59,14 @@ use rand::Rng; use num_traits::Float as NumFloat; use num_traits::{NumCast, Zero}; -use alga::general::AbstractField; +use alga::general::RealField; use alga::linear::{FiniteDimVectorSpace, NormedSpace}; #[macro_use] extern crate lazy_static; use std::marker::PhantomData; -use std::ops::{AddAssign, DivAssign, Index, IndexMut, MulAssign, SubAssign}; +use std::ops::{AddAssign, DivAssign, MulAssign, SubAssign}; use crate::algorithm::{Algorithm, Creator}; use crate::utils::math::calc_radius; @@ -75,23 +75,20 @@ pub mod algorithm; mod utils; /// Describes what floats are. -pub trait Float: NumFloat + AbstractField + AddAssign + SubAssign + MulAssign + DivAssign { +pub trait Float: NumFloat + RealField + AddAssign + SubAssign + MulAssign + DivAssign { /// Casts usize to float. fn cast(n: usize) -> Self { NumCast::from(n).expect("Casting usize to float should always succeed.") } } -impl Float for T where T: NumFloat + AbstractField + AddAssign + SubAssign + MulAssign + DivAssign +impl Float for T where T: NumFloat + RealField + AddAssign + SubAssign + MulAssign + DivAssign {} /// Describes what vectors are. pub trait Vector: Zero - + FiniteDimVectorSpace - + NormedSpace - + Index - + IndexMut - + Clone + + FiniteDimVectorSpace + + NormedSpace where F: Float, { @@ -100,11 +97,8 @@ impl Vector for T where F: Float, T: Zero - + FiniteDimVectorSpace - + NormedSpace - + Index - + IndexMut - + Clone + + FiniteDimVectorSpace + + NormedSpace, { } diff --git a/poisson/src/utils/math.rs b/poisson/src/utils/math.rs index 76cedeb6..abcf0d59 100644 --- a/poisson/src/utils/math.rs +++ b/poisson/src/utils/math.rs @@ -90,5 +90,5 @@ where Normal => newton(samples, dim), }; let max_radii: F = NumCast::from(MAX_RADII[dim - 2]).unwrap(); - (max_radii / F::cast(samples)).powf(F::cast(1) / F::cast(dim)) * relative + num_traits::Float::powf(max_radii / F::cast(samples), F::cast(1) / F::cast(dim)) * relative } diff --git a/poisson/src/utils/mod.rs b/poisson/src/utils/mod.rs index 9dcda94c..c747cb12 100644 --- a/poisson/src/utils/mod.rs +++ b/poisson/src/utils/mod.rs @@ -2,7 +2,7 @@ use crate::{Builder, Float, Type, Vector}; -use num_traits::NumCast; +use num_traits::{Float as NumFloat, NumCast}; use rand::distributions::{Distribution, Standard}; use rand::Rng; @@ -33,7 +33,7 @@ where { pub fn new(radius: F, poisson_type: Type) -> Grid { let dim = F::cast(V::dimension()); - let cell = (F::cast(2) * radius) / dim.sqrt(); + let cell = (F::cast(2) * radius) / NumFloat::sqrt(dim); let side = (F::cast(1) / cell) .to_usize() .expect("Expected that dividing 1 by cell width would be legal."); @@ -129,7 +129,7 @@ fn encoding_decoding_works() { let n = nalgebra::Vector2::new(10., 7.); assert_eq!( n, - decode(encode(&n, 15, Type::Normal).unwrap(), 15).unwrap() + decode::<_, nalgebra::Vector2<_>>(encode(&n, 15, Type::Normal).unwrap(), 15).unwrap(), ); } @@ -138,7 +138,7 @@ fn encoding_decoding_at_edge_works() { let n = nalgebra::Vector2::new(14., 14.); assert_eq!( n, - decode(encode(&n, 15, Type::Normal).unwrap(), 15).unwrap() + decode::<_, nalgebra::Vector2<_>>(encode(&n, 15, Type::Normal).unwrap(), 15).unwrap() ); } @@ -190,7 +190,7 @@ where { let mut cur = value.clone(); for n in 0..V::dimension() { - cur[n] = (cur[n] * F::cast(side)).floor(); + cur[n] = NumFloat::floor(cur[n] * F::cast(side)); } cur } @@ -220,7 +220,7 @@ where V: Vector, { let parent = get_parent(index, level); - let sqradius = (F::cast(2) * poisson.radius).powi(2); + let sqradius = NumFloat::powi(F::cast(2) * poisson.radius, 2); // NOTE: This does unnessary checks for corners, but it doesn't affect much in higher dimensions: 5^d vs 5^d - 2d each_combination(&[-2, -1, 0, 1, 2]) .filter_map(|t| grid.get(parent.clone() + t)) @@ -234,7 +234,7 @@ where F: Float, V: Vector, { - let sqradius = (F::cast(2) * poisson.radius).powi(2); + let sqradius = NumFloat::powi(F::cast(2) * poisson.radius, 2); samples .iter() .all(|t| sqdist(t.clone(), sample.clone(), poisson.poisson_type) >= sqradius) @@ -250,7 +250,7 @@ where match poisson_type { Perioditic => each_combination(&[-1, 0, 1]) .map(|v| (diff.clone() + v).norm_squared()) - .fold(F::max_value(), |a, b| a.min(b)), + .fold(NumFloat::max_value(), |a, b| NumFloat::min(a, b)), Normal => diff.norm_squared(), } } @@ -262,7 +262,7 @@ where { let split = 2usize.pow(level as u32); for n in 0..V::dimension() { - index[n] = (index[n] / F::cast(split)).floor(); + index[n] = NumFloat::floor(index[n] / F::cast(split)); } index } diff --git a/poisson/tests/validity.rs b/poisson/tests/validity.rs index 96e65895..34de6066 100644 --- a/poisson/tests/validity.rs +++ b/poisson/tests/validity.rs @@ -1,7 +1,7 @@ use poisson::Type; -use rand::distributions::StandardNormal; use rand::{rngs::SmallRng, Rng, SeedableRng}; +use rand_distr::StandardNormal; extern crate nalgebra as na; pub type Vect = na::Vector2;