aboutsummaryrefslogtreecommitdiff
path: root/src/texture
diff options
context:
space:
mode:
Diffstat (limited to 'src/texture')
-rw-r--r--src/texture/checker_texture.rs2
-rw-r--r--src/texture/image_texture.rs8
-rw-r--r--src/texture/noise_texture.rs9
-rw-r--r--src/texture/perlin.rs19
-rw-r--r--src/texture/solid_color.rs4
5 files changed, 27 insertions, 15 deletions
diff --git a/src/texture/checker_texture.rs b/src/texture/checker_texture.rs
index 385017b..d10166e 100644
--- a/src/texture/checker_texture.rs
+++ b/src/texture/checker_texture.rs
@@ -1,6 +1,6 @@
use std::sync::Arc;
-use super::{Texture, SolidColor};
+use super::{SolidColor, Texture};
use crate::{vec3::Color, vec3::Point3};
pub struct CheckerTexture {
diff --git a/src/texture/image_texture.rs b/src/texture/image_texture.rs
index 763c3f0..d90b9b6 100644
--- a/src/texture/image_texture.rs
+++ b/src/texture/image_texture.rs
@@ -50,8 +50,12 @@ impl Texture for ImageTexture {
let mut i = (u * self.width as f64) as usize;
let mut j = (v * self.height as f64) as usize;
- if i >= self.width { i = self.width - 1 };
- if j >= self.height { j = self.height - 1 };
+ if i >= self.width {
+ i = self.width - 1
+ };
+ if j >= self.height {
+ j = self.height - 1
+ };
let color_scale = 1.0 / 255.0;
let pixel = j * self.bytes_per_scanline + i * BYTES_PER_PIXEL;
Color {
diff --git a/src/texture/noise_texture.rs b/src/texture/noise_texture.rs
index 92ac166..7fe3cdb 100644
--- a/src/texture/noise_texture.rs
+++ b/src/texture/noise_texture.rs
@@ -1,4 +1,4 @@
-use super::{Texture, perlin::Perlin};
+use super::{perlin::Perlin, Texture};
use crate::{vec3::Color, vec3::Point3};
pub struct NoiseTexture {
@@ -17,6 +17,11 @@ impl NoiseTexture {
impl Texture for NoiseTexture {
fn value(&self, _: f64, _: f64, p: &Point3) -> Color {
- Color { x: 1.0, y: 1.0, z: 1.0 } * 0.5 * (1.0 + (self.scale * p.z + 10.0 * self.noise.turb(p, 7)).sin())
+ Color {
+ x: 1.0,
+ y: 1.0,
+ z: 1.0,
+ } * 0.5
+ * (1.0 + (self.scale * p.z + 10.0 * self.noise.turb(p, 7)).sin())
}
}
diff --git a/src/texture/perlin.rs b/src/texture/perlin.rs
index 43d8f64..a796a43 100644
--- a/src/texture/perlin.rs
+++ b/src/texture/perlin.rs
@@ -1,4 +1,4 @@
-use crate::vec3::{Vec3, Point3};
+use crate::vec3::{Point3, Vec3};
const POINT_COUNT: usize = 256;
@@ -55,7 +55,8 @@ impl Perlin {
^ self.perm_z.get(((k + dk as i32) & 255) as usize).unwrap())
as usize,
)
- .unwrap().clone();
+ .unwrap()
+ .clone();
}
}
}
@@ -73,11 +74,15 @@ impl Perlin {
let i_f = i as f64;
let j_f = j as f64;
let k_f = k as f64;
- let weight_v = Vec3 { x: u - i_f, y: v - j_f, z: w - k_f };
- accum += (i_f * uu + (1.0 - i_f) * (1.0 - uu)) *
- (j_f * vv + (1.0 - j_f) * (1.0 - vv)) *
- (k_f * ww + (1.0 - k_f) * (1.0 - ww)) *
- c[i][j][k].dot(&weight_v);
+ let weight_v = Vec3 {
+ x: u - i_f,
+ y: v - j_f,
+ z: w - k_f,
+ };
+ accum += (i_f * uu + (1.0 - i_f) * (1.0 - uu))
+ * (j_f * vv + (1.0 - j_f) * (1.0 - vv))
+ * (k_f * ww + (1.0 - k_f) * (1.0 - ww))
+ * c[i][j][k].dot(&weight_v);
}
}
}
diff --git a/src/texture/solid_color.rs b/src/texture/solid_color.rs
index 3af46ca..1bbc463 100644
--- a/src/texture/solid_color.rs
+++ b/src/texture/solid_color.rs
@@ -7,9 +7,7 @@ pub struct SolidColor {
impl SolidColor {
pub fn from_color(color_value: Color) -> Self {
- Self {
- color_value,
- }
+ Self { color_value }
}
}