Skip to content

Commit 7d7845d

Browse files
committed
Merge pull request #25 from mtsr/rfc369-numerics-fixes
Fix rust-lang/rust#18827 related issues.
2 parents 0f5cc98 + 32369a8 commit 7d7845d

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

src/gen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use std::num::cast;
16+
use std::num::{cast, Float};
1717

1818
use util::{lerp,scurve3,scurve5};
1919

src/model.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use std::num::{zero,one};
16+
use std::num::Float;
1717

1818
use util::lerp;
1919
use source::Source;
@@ -28,8 +28,8 @@ impl<'a, S:Source, F:Float> Line<'a, S, F> {
2828

2929
pub fn new(src: &'a S) -> Line<'a, S, F> {
3030
Line {
31-
start: [zero(), zero(), zero()],
32-
end: [one(), one(), one()],
31+
start: [Float::zero(), Float::zero(), Float::zero()],
32+
end: [Float::one(), Float::one(), Float::one()],
3333
source: src,
3434
}
3535
}
@@ -53,6 +53,6 @@ impl<'a, S:Source> Plane<'a, S> {
5353
}
5454

5555
pub fn get<F:Float>(&self, x: F, y: F) -> F {
56-
self.source.get(x, y, zero())
56+
self.source.get(x, y, Float::zero())
5757
}
5858
}

src/source/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::num::Float;
2+
13
pub use self::perlin::Perlin;
24
pub use self::ridgedmulti::RidgedMulti;
35

src/source/perlin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
use std::rand;
2020
use std::rand::Rng;
21-
use std::num::{zero, one, cast};
21+
use std::num::{cast, Float};
2222

2323
use super::Source;
2424
use Quality;
@@ -98,8 +98,8 @@ impl Perlin {
9898

9999
impl Source for Perlin {
100100
fn get<F:Float>(&self, x: F, y: F, z: F) -> F {
101-
let mut value : F = zero();
102-
let mut cur_persistence = one();
101+
let mut value : F = Float::zero();
102+
let mut cur_persistence = Float::one();
103103

104104
let frequency = cast(self.frequency).unwrap();
105105
let lacunarity = cast(self.lacunarity).unwrap();

src/source/ridgedmulti.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// limitations under the License.
1515

1616
use std;
17-
use std::num::{zero,one,abs,cast};
17+
use std::num::{cast, Float};
1818
use std::rand::Rng;
1919

2020
use util::clamp;
@@ -106,8 +106,8 @@ impl RidgedMulti {
106106
impl Source for RidgedMulti {
107107

108108
fn get<F:Float>(&self, x: F, y: F, z: F) -> F {
109-
let mut value : F = zero();
110-
let mut weight : F = one();
109+
let mut value : F = Float::zero();
110+
let mut weight : F = Float::one();
111111

112112
let offset : F = cast(self.offset).unwrap();
113113
let gain = cast(self.gain).unwrap();
@@ -126,12 +126,12 @@ impl Source for RidgedMulti {
126126
y.clone(),
127127
z.clone(), seed, self.quality);
128128

129-
let signal = abs(signal);
129+
let signal = signal.abs();
130130
let signal = offset - signal;
131131
let signal = signal * signal;
132132
let signal = signal * weight;
133133

134-
weight = clamp(signal * gain, zero(), one());
134+
weight = clamp(signal * gain, Float::zero(), Float::one());
135135

136136
value = value + (signal * cast(self.spectral_weights[i]).unwrap());
137137

src/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use std::num::cast;
16+
use std::num::{cast, Float};
1717

1818
#[inline]
1919
pub fn lerp<T: Float>(t: T, a: T, b: T) -> T {
@@ -32,7 +32,7 @@ pub fn scurve5<T: Float>(t: T) -> T {
3232
t * t * t * (t * (t * cast(6i).unwrap() - cast(15i).unwrap()) + cast(10i).unwrap())
3333
}
3434

35-
pub fn clamp<T: Primitive>(val: T, min: T, max: T) -> T {
35+
pub fn clamp<F: Float>(val: F, min: F, max: F) -> F {
3636
if val < min {
3737
min
3838
} else if val > max {

0 commit comments

Comments
 (0)