From 2d148a2dc9aabaaf60485f7e7d6eb471e3f9c0e1 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Thu, 7 Mar 2019 15:55:46 +0100 Subject: [PATCH 1/2] Access members directly instead of using the box min_x(),min_y(),etc. methods. --- src/box3d.rs | 178 +++++++++++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/src/box3d.rs b/src/box3d.rs index b3425a61..4533b732 100644 --- a/src/box3d.rs +++ b/src/box3d.rs @@ -152,32 +152,32 @@ where #[inline] pub fn max_x_typed(&self) -> Length { - Length::new(self.max_x()) + Length::new(self.max.x) } #[inline] pub fn min_x_typed(&self) -> Length { - Length::new(self.min_x()) + Length::new(self.min.x) } #[inline] pub fn max_y_typed(&self) -> Length { - Length::new(self.max_y()) + Length::new(self.max.y) } #[inline] pub fn min_y_typed(&self) -> Length { - Length::new(self.min_y()) + Length::new(self.min.y) } #[inline] pub fn max_z_typed(&self) -> Length { - Length::new(self.max_z()) + Length::new(self.max.z) } #[inline] pub fn min_z_typed(&self) -> Length { - Length::new(self.min_z()) + Length::new(self.min.z) } } @@ -187,12 +187,12 @@ where { #[inline] pub fn intersects(&self, other: &Self) -> bool { - self.min_x() < other.max_x() - && self.max_x() > other.min_x() - && self.min_y() < other.max_y() - && self.max_y() > other.min_y() - && self.min_z() < other.max_z() - && self.max_z() > other.min_z() + self.min.x < other.max.x + && self.max.x > other.min.x + && self.min.y < other.max.y + && self.max.y > other.min.y + && self.min.z < other.max.z + && self.max.z > other.min.z } #[inline] @@ -206,15 +206,15 @@ where pub fn intersection(&self, other: &Self) -> Self { let intersection_min = TypedPoint3D::new( - max(self.min_x(), other.min_x()), - max(self.min_y(), other.min_y()), - max(self.min_z(), other.min_z()), + max(self.min.x, other.min.x), + max(self.min.y, other.min.y), + max(self.min.z, other.min.z), ); let intersection_max = TypedPoint3D::new( - min(self.max_x(), other.max_x()), - min(self.max_y(), other.max_y()), - min(self.max_z(), other.max_z()), + min(self.max.x, other.max.x), + min(self.max.y, other.max.y), + min(self.max.z, other.max.z), ); TypedBox3D::new( @@ -245,9 +245,9 @@ where /// are on the back, right or bottom faces. #[inline] pub fn contains(&self, other: &TypedPoint3D) -> bool { - self.min_x() <= other.x && other.x < self.max_x() - && self.min_y() <= other.y && other.y < self.max_y() - && self.min_z() <= other.z && other.z < self.max_z() + self.min.x <= other.x && other.x < self.max.x + && self.min.y <= other.y && other.y < self.max.y + && self.min.z <= other.z && other.z < self.max.z } } @@ -261,9 +261,9 @@ where #[inline] pub fn contains_box(&self, other: &Self) -> bool { other.is_empty() - || (self.min_x() <= other.min_x() && other.max_x() <= self.max_x() - && self.min_y() <= other.min_y() && other.max_y() <= self.max_y() - && self.min_z() <= other.min_z() && other.max_z() <= self.max_z()) + || (self.min.x <= other.min.x && other.max.x <= self.max.x + && self.min.y <= other.min.y && other.max.y <= self.max.y + && self.min.z <= other.min.z && other.max.z <= self.max.z) } } @@ -274,9 +274,9 @@ where #[inline] pub fn size(&self)-> TypedSize3D { TypedSize3D::new( - self.max_x() - self.min_x(), - self.max_y() - self.min_y(), - self.max_z() - self.min_z(), + self.max.x - self.min.x, + self.max.y - self.min.y, + self.max.z - self.min.z, ) } } @@ -290,8 +290,8 @@ where #[cfg_attr(feature = "unstable", must_use)] pub fn inflate(&self, width: T, height: T, depth: T) -> Self { TypedBox3D::new( - TypedPoint3D::new(self.min_x() - width, self.min_y() - height, self.min_z() - depth), - TypedPoint3D::new(self.max_x() + width, self.max_x() + height, self.max_z() + depth), + TypedPoint3D::new(self.min.x - width, self.min.y - height, self.min.z - depth), + TypedPoint3D::new(self.max.x + width, self.max.x + height, self.max.z + depth), ) } @@ -392,14 +392,14 @@ where pub fn union(&self, other: &Self) -> Self { TypedBox3D::new( TypedPoint3D::new( - min(self.min_x(), other.min_x()), - min(self.min_y(), other.min_y()), - min(self.min_z(), other.min_z()), + min(self.min.x, other.min.x), + min(self.min.y, other.min.y), + min(self.min.z, other.min.z), ), TypedPoint3D::new( - max(self.max_x(), other.max_x()), - max(self.max_y(), other.max_y()), - max(self.max_z(), other.max_z()), + max(self.max.x, other.max.x), + max(self.max.y, other.max.y), + max(self.max.z, other.max.z), ), ) } @@ -737,45 +737,45 @@ mod tests { #[test] fn test_min_max() { let b = Box3D::from_points(&[point3(50.0, 25.0, 12.5), point3(100.0, 160.0, 200.0)]); - assert!(b.min_x() == 50.0); - assert!(b.min_y() == 25.0); - assert!(b.min_z() == 12.5); - assert!(b.max_x() == 100.0); - assert!(b.max_y() == 160.0); - assert!(b.max_z() == 200.0); + assert!(b.min.x == 50.0); + assert!(b.min.y == 25.0); + assert!(b.min.z == 12.5); + assert!(b.max.x == 100.0); + assert!(b.max.y == 160.0); + assert!(b.max.z == 200.0); } #[test] fn test_round_in() { let b = Box3D::from_points(&[point3(-25.5, -40.4, -70.9), point3(60.3, 36.5, 89.8)]).round_in(); - assert!(b.min_x() == -25.0); - assert!(b.min_y() == -40.0); - assert!(b.min_z() == -70.0); - assert!(b.max_x() == 60.0); - assert!(b.max_y() == 36.0); - assert!(b.max_z() == 89.0); + assert!(b.min.x == -25.0); + assert!(b.min.y == -40.0); + assert!(b.min.z == -70.0); + assert!(b.max.x == 60.0); + assert!(b.max.y == 36.0); + assert!(b.max.z == 89.0); } #[test] fn test_round_out() { let b = Box3D::from_points(&[point3(-25.5, -40.4, -70.9), point3(60.3, 36.5, 89.8)]).round_out(); - assert!(b.min_x() == -26.0); - assert!(b.min_y() == -41.0); - assert!(b.min_z() == -71.0); - assert!(b.max_x() == 61.0); - assert!(b.max_y() == 37.0); - assert!(b.max_z() == 90.0); + assert!(b.min.x == -26.0); + assert!(b.min.y == -41.0); + assert!(b.min.z == -71.0); + assert!(b.max.x == 61.0); + assert!(b.max.y == 37.0); + assert!(b.max.z == 90.0); } #[test] fn test_round() { let b = Box3D::from_points(&[point3(-25.5, -40.4, -70.9), point3(60.3, 36.5, 89.8)]).round(); - assert!(b.min_x() == -26.0); - assert!(b.min_y() == -40.0); - assert!(b.min_z() == -71.0); - assert!(b.max_x() == 60.0); - assert!(b.max_y() == 37.0); - assert!(b.max_z() == 90.0); + assert!(b.min.x == -26.0); + assert!(b.min.y == -40.0); + assert!(b.min.z == -71.0); + assert!(b.max.x == 60.0); + assert!(b.max.y == 37.0); + assert!(b.max.z == 90.0); } #[test] @@ -797,12 +797,12 @@ mod tests { let b = b.translate(&translation); center += translation; assert!(b.center() == center); - assert!(b.max_x() == 25.0); - assert!(b.max_y() == 17.5); - assert!(b.max_z() == 209.5); - assert!(b.min_x() == 10.0); - assert!(b.min_y() == 2.5); - assert!(b.min_z() == 9.5); + assert!(b.max.x == 25.0); + assert!(b.max.y == 17.5); + assert!(b.max.z == 209.5); + assert!(b.min.x == 10.0); + assert!(b.min.y == 2.5); + assert!(b.min.z == 9.5); } #[test] @@ -810,12 +810,12 @@ mod tests { let b1 = Box3D::from_points(&[point3(-20.0, -20.0, -20.0), point3(0.0, 20.0, 20.0)]); let b2 = Box3D::from_points(&[point3(0.0, 20.0, 20.0), point3(20.0, -20.0, -20.0)]); let b = b1.union(&b2); - assert!(b.max_x() == 20.0); - assert!(b.max_y() == 20.0); - assert!(b.max_z() == 20.0); - assert!(b.min_x() == -20.0); - assert!(b.min_y() == -20.0); - assert!(b.min_z() == -20.0); + assert!(b.max.x == 20.0); + assert!(b.max.y == 20.0); + assert!(b.max.z == 20.0); + assert!(b.min.x == -20.0); + assert!(b.min.y == -20.0); + assert!(b.min.z == -20.0); assert!(b.volume() == (40.0 * 40.0 * 40.0)); } @@ -831,12 +831,12 @@ mod tests { let b1 = Box3D::from_points(&[point3(-15.0, -20.0, -20.0), point3(10.0, 20.0, 20.0)]); let b2 = Box3D::from_points(&[point3(-10.0, 20.0, 20.0), point3(15.0, -20.0, -20.0)]); let b = b1.intersection(&b2); - assert!(b.max_x() == 10.0); - assert!(b.max_y() == 20.0); - assert!(b.max_z() == 20.0); - assert!(b.min_x() == -10.0); - assert!(b.min_y() == -20.0); - assert!(b.min_z() == -20.0); + assert!(b.max.x == 10.0); + assert!(b.max.y == 20.0); + assert!(b.max.z == 20.0); + assert!(b.min.x == -10.0); + assert!(b.min.y == -20.0); + assert!(b.min.z == -20.0); assert!(b.volume() == (20.0 * 40.0 * 40.0)); } @@ -855,23 +855,23 @@ mod tests { fn test_scale() { let b = Box3D::from_points(&[point3(-10.0, -10.0, -10.0), point3(10.0, 10.0, 10.0)]); let b = b.scale(0.5, 0.5, 0.5); - assert!(b.max_x() == 5.0); - assert!(b.max_y() == 5.0); - assert!(b.max_z() == 5.0); - assert!(b.min_x() == -5.0); - assert!(b.min_y() == -5.0); - assert!(b.min_z() == -5.0); + assert!(b.max.x == 5.0); + assert!(b.max.y == 5.0); + assert!(b.max.z == 5.0); + assert!(b.min.x == -5.0); + assert!(b.min.y == -5.0); + assert!(b.min.z == -5.0); } #[test] fn test_zero() { let b = Box3D::::zero(); - assert!(b.max_x() == 0.0); - assert!(b.max_y() == 0.0); - assert!(b.max_z() == 0.0); - assert!(b.min_x() == 0.0); - assert!(b.min_y() == 0.0); - assert!(b.min_z() == 0.0); + assert!(b.max.x == 0.0); + assert!(b.max.y == 0.0); + assert!(b.max.z == 0.0); + assert!(b.min.x == 0.0); + assert!(b.min.y == 0.0); + assert!(b.min.z == 0.0); } #[test] From 1ad2505481653d532f060f122f61085fcb95d327 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Thu, 7 Mar 2019 16:03:30 +0100 Subject: [PATCH 2/2] Remove TypedBox3D::min_x() and similar methods. --- src/box3d.rs | 65 ---------------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/src/box3d.rs b/src/box3d.rs index 4533b732..a86d60a8 100644 --- a/src/box3d.rs +++ b/src/box3d.rs @@ -116,71 +116,6 @@ where } } -impl TypedBox3D -where - T: Copy, -{ - #[inline] - pub fn max_x(&self) -> T { - self.max.x - } - - #[inline] - pub fn min_x(&self) -> T { - self.min.x - } - - #[inline] - pub fn max_y(&self) -> T { - self.max.y - } - - #[inline] - pub fn min_y(&self) -> T { - self.min.y - } - - #[inline] - pub fn max_z(&self) -> T { - self.max.z - } - - #[inline] - pub fn min_z(&self) -> T { - self.min.z - } - - #[inline] - pub fn max_x_typed(&self) -> Length { - Length::new(self.max.x) - } - - #[inline] - pub fn min_x_typed(&self) -> Length { - Length::new(self.min.x) - } - - #[inline] - pub fn max_y_typed(&self) -> Length { - Length::new(self.max.y) - } - - #[inline] - pub fn min_y_typed(&self) -> Length { - Length::new(self.min.y) - } - - #[inline] - pub fn max_z_typed(&self) -> Length { - Length::new(self.max.z) - } - - #[inline] - pub fn min_z_typed(&self) -> Length { - Length::new(self.min.z) - } -} - impl TypedBox3D where T: Copy + PartialOrd,