From 5df1171202dd4da9fdad95b0810583c0150fa5ce Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Tue, 17 Oct 2023 11:12:24 +0300 Subject: [PATCH] Add default implementation of `GenericImageView::dimensions` --- src/buffer.rs | 4 ---- src/flat.rs | 14 ++------------ src/image.rs | 5 ++++- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 6f6623311d..baee82f4ce 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1169,10 +1169,6 @@ where { type Pixel = P; - fn dimensions(&self) -> (u32, u32) { - self.dimensions() - } - fn bounds(&self) -> (u32, u32, u32, u32) { (0, 0, self.width, self.height) } diff --git a/src/flat.rs b/src/flat.rs index a336b33bd1..b676db7ae8 100644 --- a/src/flat.rs +++ b/src/flat.rs @@ -1386,13 +1386,8 @@ where { type Pixel = P; - fn dimensions(&self) -> (u32, u32) { - (self.inner.layout.width, self.inner.layout.height) - } - fn bounds(&self) -> (u32, u32, u32, u32) { - let (w, h) = self.dimensions(); - (0, 0, w, h) + (0, 0, self.inner.layout.width, self.inner.layout.height) } fn in_bounds(&self, x: u32, y: u32) -> bool { @@ -1429,13 +1424,8 @@ where { type Pixel = P; - fn dimensions(&self) -> (u32, u32) { - (self.inner.layout.width, self.inner.layout.height) - } - fn bounds(&self) -> (u32, u32, u32, u32) { - let (w, h) = self.dimensions(); - (0, 0, w, h) + (0, 0, self.inner.layout.width, self.inner.layout.height) } fn in_bounds(&self, x: u32, y: u32) -> bool { diff --git a/src/image.rs b/src/image.rs index eac5d7c9cd..531c43b08e 100644 --- a/src/image.rs +++ b/src/image.rs @@ -945,7 +945,10 @@ pub trait GenericImageView { type Pixel: Pixel; /// The width and height of this image. - fn dimensions(&self) -> (u32, u32); + fn dimensions(&self) -> (u32, u32) { + let (_, _, w, h) = self.bounds(); + (w, h) + } /// The width of this image. fn width(&self) -> u32 {