Replace unsafe code with exactly equivalent safe code
@@ -2096,11 +2096,10 @@ impl FastNoise {
#[allow(dead_code)]
fn get_white_noise4d(&self, x: f32, y: f32, z: f32, w: f32) -> f32 {
- unsafe {
- let xc: i32 = std::mem::transmute_copy(&x);
- let yc: i32 = std::mem::transmute_copy(&y);
- let zc: i32 = std::mem::transmute_copy(&z);
- let wc: i32 = std::mem::transmute_copy(&w);
+ let xc: i32 = x.to_bits() as i32;
+ let yc: i32 = y.to_bits() as i32;
+ let zc: i32 = z.to_bits() as i32;
+ let wc: i32 = w.to_bits() as i32;
self.val_coord_4d(
self.seed as i32,
@@ -2110,13 +2109,11 @@ impl FastNoise {
wc ^ (wc >> 16),
)
}
- }
fn get_white_noise3d(&self, x: f32, y: f32, z: f32) -> f32 {
- unsafe {
- let xc: i32 = std::mem::transmute_copy(&x);
- let yc: i32 = std::mem::transmute_copy(&y);
- let zc: i32 = std::mem::transmute_copy(&z);
+ let xc: i32 = x.to_bits() as i32;
+ let yc: i32 = y.to_bits() as i32;
+ let zc: i32 = z.to_bits() as i32;
self.val_coord_3d(
self.seed as i32,
@@ -2125,16 +2122,13 @@ impl FastNoise {
zc ^ (zc >> 16),
)
}
- }
fn get_white_noise(&self, x: f32, y: f32) -> f32 {
- unsafe {
- let xc: i32 = std::mem::transmute_copy(&x);
- let yc: i32 = std::mem::transmute_copy(&y);
+ let xc: i32 = x.to_bits() as i32;
+ let yc: i32 = y.to_bits() as i32;
self.val_coord_2d(self.seed as i32, xc ^ (xc >> 16), yc ^ (yc >> 16))
}
- }
#[allow(dead_code)]
fn get_white_noise_int4d(&self, x: i32, y: i32, z: i32, w: i32) -> f32 {
