Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions poisson-visualisation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
11 changes: 5 additions & 6 deletions poisson-visualisation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::<f32>() * 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;
Expand Down Expand Up @@ -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]);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions poisson/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
11 changes: 6 additions & 5 deletions poisson/src/algorithm/bridson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.",
);
Expand Down Expand Up @@ -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::<f64, _>(StandardNormal))
.expect("The f64 produced by StandardNormal should be always castable to float.");
}
let result = result.normalize() * rand.gen() * max;
Expand Down
9 changes: 5 additions & 4 deletions poisson/src/algorithm/ebeida.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -46,7 +47,7 @@ where
success: 0,
outside: vec![],
mantissa_digits: {
let (mantissa, _, _) = F::max_value().integer_decode();
let (mantissa, _, _) = <F as NumFloat>::max_value().integer_decode();
mantissa.count_ones() as usize
},
}
Expand Down Expand Up @@ -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.",
);
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 10 additions & 16 deletions poisson/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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<T> Float for T where T: NumFloat + AbstractField + AddAssign + SubAssign + MulAssign + DivAssign
impl<T> Float for T where T: NumFloat + RealField + AddAssign + SubAssign + MulAssign + DivAssign
{}

/// Describes what vectors are.
pub trait Vector<F>:
Zero
+ FiniteDimVectorSpace<Field = F>
+ NormedSpace<Field = F>
+ Index<usize>
+ IndexMut<usize>
+ Clone
+ FiniteDimVectorSpace
+ NormedSpace<RealField = F, ComplexField = F>
where
F: Float,
{
Expand All @@ -100,11 +97,8 @@ impl<T, F> Vector<F> for T
where
F: Float,
T: Zero
+ FiniteDimVectorSpace<Field = F>
+ NormedSpace<Field = F>
+ Index<usize>
+ IndexMut<usize>
+ Clone
+ FiniteDimVectorSpace
+ NormedSpace<RealField = F, ComplexField = F>,
{
}

Expand Down
2 changes: 1 addition & 1 deletion poisson/src/utils/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
18 changes: 9 additions & 9 deletions poisson/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,7 +33,7 @@ where
{
pub fn new(radius: F, poisson_type: Type) -> Grid<F, V> {
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.");
Expand Down Expand Up @@ -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(),
);
}

Expand All @@ -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()
);
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -220,7 +220,7 @@ where
V: Vector<F>,
{
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))
Expand All @@ -234,7 +234,7 @@ where
F: Float,
V: Vector<F>,
{
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)
Expand All @@ -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(),
}
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion poisson/tests/validity.rs
Original file line number Diff line number Diff line change
@@ -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<f64>;
Expand Down