From bff0d20f833fb5013074a6223dc5376cdf74a21e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sun, 20 Feb 2022 13:32:58 +0100 Subject: [PATCH] Remove redundant access to point model coords --- src/camera.rs | 28 ++++++++++++---------------- src/kernel/approximation.rs | 12 ++++++------ src/kernel/shapes/sweep.rs | 2 +- src/math/point.rs | 22 ---------------------- 4 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index bd8bb8366..f612eb92e 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -45,19 +45,15 @@ impl Camera { // // To do that, first compute the model's highest point, as well as // the furthest point from the origin, in x and y. - let highest_point = aabb.max.z(); - let furthest_point = [ - aabb.min.x().abs(), - aabb.max.x(), - aabb.min.y().abs(), - aabb.max.y(), - ] - .into_iter() - .reduce(Scalar::max) - // `reduce` can only return `None`, if there are no items in - // the iterator. And since we're creating an array full of - // items above, we know this can't panic. - .unwrap(); + let highest_point = aabb.max.z; + let furthest_point = + [aabb.min.x.abs(), aabb.max.x, aabb.min.y.abs(), aabb.max.y] + .into_iter() + .reduce(Scalar::max) + // `reduce` can only return `None`, if there are no items in + // the iterator. And since we're creating an array full of + // items above, we know this can't panic. + .unwrap(); // The actual furthest point is not far enough. We don't want the // model to fill the whole screen. @@ -74,7 +70,7 @@ impl Camera { let initial_offset = { let mut offset = aabb.center(); - *offset.z_mut() = Scalar::ZERO; + offset.z = Scalar::ZERO; -offset }; @@ -84,8 +80,8 @@ impl Camera { rotation: Transform::identity(), translation: Translation::from([ - initial_offset.x().into_f64(), - initial_offset.y().into_f64(), + initial_offset.x.into_f64(), + initial_offset.y.into_f64(), -initial_distance.into_f64(), ]), } diff --git a/src/kernel/approximation.rs b/src/kernel/approximation.rs index a84b52c03..22abc06a7 100644 --- a/src/kernel/approximation.rs +++ b/src/kernel/approximation.rs @@ -90,22 +90,22 @@ impl Approximation { // As this is a cycle, neighboring edges are going to share vertices. // Let's remove all those duplicates. points.sort_by(|a, b| { - if a.x() < b.x() { + if a.x < b.x { return Ordering::Less; } - if a.x() > b.x() { + if a.x > b.x { return Ordering::Greater; } - if a.y() < b.y() { + if a.y < b.y { return Ordering::Less; } - if a.y() > b.y() { + if a.y > b.y { return Ordering::Greater; } - if a.z() < b.z() { + if a.z < b.z { return Ordering::Less; } - if a.z() > b.z() { + if a.z > b.z { return Ordering::Greater; } diff --git a/src/kernel/shapes/sweep.rs b/src/kernel/shapes/sweep.rs index fcbd80684..13be91908 100644 --- a/src/kernel/shapes/sweep.rs +++ b/src/kernel/shapes/sweep.rs @@ -20,7 +20,7 @@ use crate::{ impl Shape for fj::Sweep { fn bounding_volume(&self) -> Aabb<3> { let mut aabb = self.shape.bounding_volume(); - *aabb.max.z_mut() = self.length.into(); + aabb.max.z = self.length.into(); aabb } diff --git a/src/math/point.rs b/src/math/point.rs index f43620eb7..a77f77922 100644 --- a/src/math/point.rs +++ b/src/math/point.rs @@ -51,11 +51,6 @@ impl Point { coords: self.coords.to_t(), } } - - /// Access a mutable reference to the point's z coordinate - pub fn z_mut(&mut self) -> &mut Scalar { - &mut self.coords.0[2] - } } impl Point<1> { @@ -77,23 +72,6 @@ impl Point<2> { } } -impl Point<3> { - /// Access the point's x coordinate - pub fn x(&self) -> Scalar { - self.coords.x - } - - /// Access the point's y coordinate - pub fn y(&self) -> Scalar { - self.coords.y - } - - /// Access the point's z coordinate - pub fn z(&self) -> Scalar { - self.coords.z - } -} - impl ops::Deref for Point<1> { type Target = T;