From 45269c8d0d5fceeaeb38c9500eb018059cba2361 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 29 Mar 2022 18:16:22 +0200 Subject: [PATCH] Merge accessors of `fj::Difference2d` --- fj-operations/src/difference_2d.rs | 10 +++++++--- fj/src/shape_2d.rs | 11 +++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fj-operations/src/difference_2d.rs b/fj-operations/src/difference_2d.rs index 89178c598..bf0cd58fe 100644 --- a/fj-operations/src/difference_2d.rs +++ b/fj-operations/src/difference_2d.rs @@ -16,8 +16,12 @@ impl ToShape for fj::Difference2d { let mut shape = Shape::new(); - let [mut a, mut b] = [&self.a(), &self.b()] - .map(|shape| shape.to_shape(tolerance, debug_info)); + // Can be cleaned up, once `each_ref` is stable: + // https://doc.rust-lang.org/std/primitive.array.html#method.each_ref + let [a, b] = self.shapes(); + let shapes = [&a, &b]; + let [mut a, mut b] = + shapes.map(|shape| shape.to_shape(tolerance, debug_info)); // Check preconditions. // @@ -76,7 +80,7 @@ impl ToShape for fj::Difference2d { // This is a conservative estimate of the bounding box: It's never going // to be bigger than the bounding box of the original shape that another // is being subtracted from. - self.a().bounding_volume() + self.shapes()[0].bounding_volume() } } diff --git a/fj/src/shape_2d.rs b/fj/src/shape_2d.rs index 2e8648af5..f5116d824 100644 --- a/fj/src/shape_2d.rs +++ b/fj/src/shape_2d.rs @@ -98,14 +98,9 @@ impl Difference2d { self.shapes[0].color() } - /// Access the original shape - pub fn a(&self) -> &Shape2d { - &self.shapes[0] - } - - /// Access the shape being subtracted - pub fn b(&self) -> &Shape2d { - &self.shapes[1] + /// Access the shapes that make up the difference + pub fn shapes(&self) -> &[Shape2d; 2] { + &self.shapes } }