From 4a35cb6e99d5668010f2206cf678ec610b6f0646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Stepanovi=C4=87?= Date: Thu, 16 Feb 2023 07:03:02 +0000 Subject: [PATCH] use Self::new() for point creation --- src/rxing_result_point.rs | 56 +++++++++------------------------------ 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/src/rxing_result_point.rs b/src/rxing_result_point.rs index 49bf2db..7948c8c 100644 --- a/src/rxing_result_point.rs +++ b/src/rxing_result_point.rs @@ -76,14 +76,11 @@ impl fmt::Display for RXingResultPoint { } } -impl std::ops::Sub for RXingResultPoint { +impl std::ops::Sub for RXingResultPoint { type Output = Self; fn sub(self, rhs: Self) -> Self::Output { - Self { - x: self.x - rhs.x, - y: self.y - rhs.y, - } + Self::new(self.x - rhs.x, self.y - rhs.y) } } @@ -91,32 +88,23 @@ impl std::ops::Neg for RXingResultPoint { type Output = Self; fn neg(self) -> Self::Output { - Self { - x: -self.x, - y: -self.y, - } + Self::new(-self.x, -self.y) } } -impl std::ops::Add for RXingResultPoint { +impl std::ops::Add for RXingResultPoint { type Output = Self; fn add(self, rhs: Self) -> Self::Output { - Self { - x: self.x + rhs.x, - y: self.y + rhs.y, - } + Self::new(self.x + rhs.x, self.y + rhs.y) } } -impl std::ops::Mul for RXingResultPoint { +impl std::ops::Mul for RXingResultPoint { type Output = Self; fn mul(self, rhs: Self) -> Self::Output { - Self { - x: self.x * rhs.x, - y: self.y * rhs.y, - } + Self::new(self.x * rhs.x, self.y * rhs.y) } } @@ -124,10 +112,7 @@ impl std::ops::Mul for RXingResultPoint { type Output = Self; fn mul(self, rhs: f32) -> Self::Output { - Self { - x: self.x * rhs, - y: self.y * rhs, - } + Self::new(self.x * rhs, self.y * rhs) } } @@ -135,10 +120,7 @@ impl std::ops::Mul for RXingResultPoint { type Output = Self; fn mul(self, rhs: i32) -> Self::Output { - Self { - x: self.x * rhs as f32, - y: self.y * rhs as f32, - } + Self::new(self.x * rhs as f32, self.y * rhs as f32) } } @@ -146,10 +128,7 @@ impl std::ops::Mul for i32 { type Output = RXingResultPoint; fn mul(self, rhs: RXingResultPoint) -> Self::Output { - Self::Output { - x: rhs.x * self as f32, - y: rhs.y * self as f32, - } + Self::Output::new(rhs.x * self as f32, rhs.y * self as f32) } } @@ -157,10 +136,7 @@ impl std::ops::Mul for f32 { type Output = RXingResultPoint; fn mul(self, rhs: RXingResultPoint) -> Self::Output { - Self::Output { - x: rhs.x * self, - y: rhs.y * self, - } + Self::Output::new(rhs.x * self, rhs.y * self) } } @@ -168,10 +144,7 @@ impl std::ops::Div for RXingResultPoint { type Output = RXingResultPoint; fn div(self, rhs: f32) -> Self::Output { - Self { - x: self.x / rhs, - y: self.y / rhs, - } + Self::Output::new(self.x / rhs, self.y / rhs) } } @@ -208,10 +181,7 @@ impl RXingResultPoint { /// See also the documentation of the GridSampler API. #[inline(always)] pub fn centered(self) -> Self { - Self { - x: self.x.floor() + 0.5, - y: self.y.floor() + 0.5, - } + Self::new(self.x.floor() + 0.5, self.y.floor() + 0.5) } pub fn middle(self, p: Self) -> Self {