Skip to content

Commit

Permalink
Add default implementation of GenericImageView::dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
zetanumbers committed Oct 17, 2023
1 parent b385ec0 commit 5df1171
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 2 additions & 12 deletions src/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5df1171

Please sign in to comment.