-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ddf660
commit 09546f4
Showing
6 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::fmt; | ||
|
||
use geom::Size; | ||
|
||
use crate::png::Pixel; | ||
|
||
/// A drawing creation error | ||
#[derive(Debug, Clone, Copy)] | ||
#[non_exhaustive] | ||
pub enum Error { | ||
/// The drawing is larger than the maximum PNG dimensions | ||
#[cfg(feature = "svg")] | ||
PngDimensionsError(Size<Pixel>), | ||
} | ||
|
||
impl fmt::Display for Error { | ||
#[inline] | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match *self { | ||
#[cfg(feature = "svg")] | ||
Self::PngDimensionsError(dims) => write!(f, "invalid PNG dimensions {dims:?}"), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for Error {} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use geom::Point; | ||
|
||
use crate::Options; | ||
|
||
#[test] | ||
fn error_fmt() { | ||
let key1 = key::Key::example(); | ||
let key2 = { | ||
let mut tmp = key1.clone(); | ||
tmp.position = Point::new(1e20, 1e20); | ||
tmp | ||
}; | ||
|
||
let error = Options::default() | ||
.draw(&[key1, key2]) | ||
.to_png(1.0) | ||
.unwrap_err(); | ||
|
||
assert!(format!("{error}").starts_with("invalid PNG dimensions ")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters