Remove redundant access to point model coords

This commit is contained in:
Hanno Braun 2022-02-20 13:32:58 +01:00
parent 1e33846f93
commit bff0d20f83
4 changed files with 19 additions and 45 deletions

View File

@ -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(),
]),
}

View File

@ -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;
}

View File

@ -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
}

View File

@ -51,11 +51,6 @@ impl<const D: usize> Point<D> {
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;