From ae712f77a290592a4cbd5c5d3ed74c849310c0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Thu, 14 May 2020 22:13:08 +0200 Subject: [PATCH 1/2] fix iterator type --- common/src/comp/body/biped_large.rs | 3 +-- common/src/comp/body/bird_medium.rs | 3 +-- common/src/comp/body/critter.rs | 3 +-- common/src/comp/body/dragon.rs | 3 +-- common/src/comp/body/golem.rs | 3 +-- common/src/comp/body/humanoid.rs | 3 +-- common/src/comp/body/quadruped_medium.rs | 3 +-- common/src/comp/body/quadruped_small.rs | 3 +-- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/common/src/comp/body/biped_large.rs b/common/src/comp/body/biped_large.rs index 598a15b7fe..6e26f4300e 100644 --- a/common/src/comp/body/biped_large.rs +++ b/common/src/comp/body/biped_large.rs @@ -55,10 +55,9 @@ impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies pub const ALL_SPECIES: [Species; 2] = [Species::Ogre, Species::Cyclops]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Species; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } } diff --git a/common/src/comp/body/bird_medium.rs b/common/src/comp/body/bird_medium.rs index 10c7e17966..a66d9f2e0d 100644 --- a/common/src/comp/body/bird_medium.rs +++ b/common/src/comp/body/bird_medium.rs @@ -82,10 +82,9 @@ pub const ALL_SPECIES: [Species; 8] = [ ]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Species; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } } diff --git a/common/src/comp/body/critter.rs b/common/src/comp/body/critter.rs index d72145a7e9..6170515512 100644 --- a/common/src/comp/body/critter.rs +++ b/common/src/comp/body/critter.rs @@ -72,10 +72,9 @@ pub const ALL_SPECIES: [Species; 6] = [ ]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Species; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } } diff --git a/common/src/comp/body/dragon.rs b/common/src/comp/body/dragon.rs index 3ccb3c6b65..942e80e4e7 100644 --- a/common/src/comp/body/dragon.rs +++ b/common/src/comp/body/dragon.rs @@ -52,10 +52,9 @@ impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies pub const ALL_SPECIES: [Species; 1] = [Species::Reddragon]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Species; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } } diff --git a/common/src/comp/body/golem.rs b/common/src/comp/body/golem.rs index 136957aebf..e4f430887b 100644 --- a/common/src/comp/body/golem.rs +++ b/common/src/comp/body/golem.rs @@ -52,10 +52,9 @@ impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies pub const ALL_SPECIES: [Species; 1] = [Species::StoneGolem]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Species; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } } diff --git a/common/src/comp/body/humanoid.rs b/common/src/comp/body/humanoid.rs index 91b6c483ef..73eed323cd 100644 --- a/common/src/comp/body/humanoid.rs +++ b/common/src/comp/body/humanoid.rs @@ -105,10 +105,9 @@ pub const ALL_RACES: [Race; 6] = [ ]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Race; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_RACES.iter().copied() } } diff --git a/common/src/comp/body/quadruped_medium.rs b/common/src/comp/body/quadruped_medium.rs index 8d7a1265ff..d4c310db74 100644 --- a/common/src/comp/body/quadruped_medium.rs +++ b/common/src/comp/body/quadruped_medium.rs @@ -82,10 +82,9 @@ pub const ALL_SPECIES: [Species; 8] = [ ]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Species; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } } diff --git a/common/src/comp/body/quadruped_small.rs b/common/src/comp/body/quadruped_small.rs index 51e5376828..b44958ffb1 100644 --- a/common/src/comp/body/quadruped_small.rs +++ b/common/src/comp/body/quadruped_small.rs @@ -102,10 +102,9 @@ pub const ALL_SPECIES: [Species; 13] = [ ]; impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; type Item = Species; - type IntoIter = impl Iterator; - fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } } From c75764558775a2ec4b01478ec2bde55552fc6d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Thu, 14 May 2020 22:13:20 +0200 Subject: [PATCH 2/2] fix links --- world/src/sim/util.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/world/src/sim/util.rs b/world/src/sim/util.rs index e9f9cd816f..add95e8ab0 100644 --- a/world/src/sim/util.rs +++ b/world/src/sim/util.rs @@ -25,7 +25,7 @@ pub fn map_edge_factor(posi: usize) -> f32 { /// Computes the cumulative distribution function of the weighted sum of k /// independent, uniformly distributed random variables between 0 and 1. For -/// each variable i, we use weights[i] as the weight to give samples[i] (the +/// each variable i, we use `weights[i]` as the weight to give `samples[i]` (the /// weights should all be positive). /// /// If the precondition is met, the distribution of the result of calling this @@ -37,23 +37,26 @@ pub fn map_edge_factor(posi: usize) -> f32 { /// /// NOTE: /// -/// Per [1], the problem of determing the CDF of +/// Per [[1]], the problem of determing the CDF of /// the sum of uniformly distributed random variables over *different* ranges is /// considerably more complicated than it is for the same-range case. /// Fortunately, it also provides a reference to [2], which contains a complete /// derivation of an exact rule for the density function for this case. The CDF -/// is just the integral of the cumulative distribution function [3], +/// is just the integral of the cumulative distribution function [[3]], /// which we use to convert this into a CDF formula. /// /// This allows us to sum weighted, uniform, independent random variables. /// /// At some point, we should probably contribute this back to stats-rs. /// -/// 1. https://www.r-bloggers.com/sums-of-random-variables/, +/// 1. [https://www.r-bloggers.com/sums-of-random-variables/][1], /// 2. Sadooghi-Alvandi, S., A. Nematollahi, & R. Habibi, 2009. /// On the Distribution of the Sum of Independent Uniform Random Variables. /// Statistical Papers, 50, 171-175. -/// 3. hhttps://en.wikipedia.org/wiki/Cumulative_distribution_function +/// 3. [https://en.wikipedia.org/wiki/Cumulative_distribution_function][3] +/// +/// [1]: https://www.r-bloggers.com/sums-of-random-variables/ +/// [3]: https://en.wikipedia.org/wiki/Cumulative_distribution_function pub fn cdf_irwin_hall(weights: &[f32; N], samples: [f32; N]) -> f32 { // Let J_k = {(j_1, ... , j_k) : 1 ≤ j_1 < j_2 < ··· < j_k ≤ N }. //