**BREAKING**: Added a new variant of enum CropBoxError::WidthOrHeightLessOrEqualToZero.

This commit is contained in:
Kirill Kuzminykh
2024-02-05 01:22:02 +03:00
parent 25ea0da382
commit ed70607f2b
4 changed files with 52 additions and 1 deletions
+6
View File
@@ -1,3 +1,9 @@
## [Unreleased] - ReleaseDate
### Added
- **BREAKING**: Added a new variant of enum `CropBoxError::WidthOrHeightLessOrEqualToZero`.
## [3.0.0] - 2024-02-04
### Added
+2
View File
@@ -22,6 +22,8 @@ pub enum CropBoxError {
PositionIsOutOfImageBoundaries,
#[error("Size of the crop box is out of the image boundaries")]
SizeIsOutOfImageBoundaries,
#[error("Width or height of the crop box is less or equal to zero")]
WidthOrHeightLessOrEqualToZero,
}
#[derive(Error, Debug, Clone, Copy)]
+3
View File
@@ -126,6 +126,9 @@ where
let width_f = self.width().get() as f64;
let height_f = self.height().get() as f64;
if crop_box.width <= 0. || crop_box.height <= 0. {
return Err(CropBoxError::WidthOrHeightLessOrEqualToZero);
}
if crop_box.left < 0.
|| crop_box.top < 0.
|| crop_box.left >= width_f
+41 -1
View File
@@ -860,12 +860,52 @@ mod not_u8x4 {
mod u8x4 {
use std::f64::consts::PI;
use fast_image_resize::Filter;
use fast_image_resize::{CropBoxError, Filter, ImageView};
use super::*;
type P = U8x4;
#[test]
fn set_crop_box() {
let mut view: ImageView<P> =
ImageView::from_buffer(nonzero(1), nonzero(1), &[0, 0, 0, 0]).unwrap();
for (left, top) in [(1., 0.), (0., 1.)] {
assert_eq!(
view.set_crop_box(CropBox {
left,
top,
width: 1.,
height: 1.
}),
Err(CropBoxError::PositionIsOutOfImageBoundaries)
);
}
for (width, height) in [(2., 1.), (1., 2.)] {
assert_eq!(
view.set_crop_box(CropBox {
left: 0.,
top: 0.,
width,
height
}),
Err(CropBoxError::SizeIsOutOfImageBoundaries)
);
}
for (width, height) in [(0., 1.), (1., 0.), (-1., 1.), (1., -1.)] {
assert_eq!(
view.set_crop_box(CropBox {
left: 0.,
top: 0.,
width,
height
}),
Err(CropBoxError::WidthOrHeightLessOrEqualToZero)
);
}
}
#[test]
fn downscale_u8x4() {
P::downscale_test(