mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 10:28:21 -06:00
add Image::quad
This commit is contained in:
parent
18c6e621e9
commit
c33594e995
|
@ -147,7 +147,7 @@ impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
///
|
///
|
||||||
/// Points not in bounds will not be included.
|
/// Points not in bounds will not be included.
|
||||||
///
|
///
|
||||||
/// Uses [`Image::points`].
|
/// Uses [`Image::quad`].
|
||||||
/// ```
|
/// ```
|
||||||
/// # use fimg::Image;
|
/// # use fimg::Image;
|
||||||
/// let mut i = Image::alloc(10, 10);
|
/// let mut i = Image::alloc(10, 10);
|
||||||
|
@ -176,14 +176,11 @@ impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
// v x1 v x2
|
// v x1 v x2
|
||||||
// [ ]
|
// [ ]
|
||||||
// ^ x3 ^ x4
|
// ^ x3 ^ x4
|
||||||
self.points(
|
self.quad(
|
||||||
&[
|
p!(x1 - wx, y1 - wy), // x1
|
||||||
p!(x1 - wx, y1 - wy), // x1
|
p!(x2 - wx, y2 - wy), // x2
|
||||||
p!(x2 - wx, y2 - wy), // x2
|
p!(x2 + wx, y2 + wy), // x3
|
||||||
p!(x2 + wx, y2 + wy), // x3
|
p!(x1 + wx, y1 + wy), // x4
|
||||||
p!(x1 + wx, y1 + wy), // x4
|
|
||||||
p!(x1 - wx, y1 - wy), // x1 (close)
|
|
||||||
],
|
|
||||||
color,
|
color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,4 +70,17 @@ impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
|
||||||
self.line((x1, y1), (x2, y2), c);
|
self.line((x1, y1), (x2, y2), c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draws a filled quadrilateral.
|
||||||
|
/// This currently just uses [`Image::points`], but in the future this may change.
|
||||||
|
pub fn quad(
|
||||||
|
&mut self,
|
||||||
|
a: (i32, i32),
|
||||||
|
b: (i32, i32),
|
||||||
|
c: (i32, i32),
|
||||||
|
d: (i32, i32),
|
||||||
|
col: [u8; CHANNELS],
|
||||||
|
) {
|
||||||
|
self.points(&[a, b, c, d, a], col);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue