Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub use crate::buffer_::{
pub use crate::flat::FlatSamples;

// Traits
pub use crate::traits::{EncodableLayout, Pixel, PixelWithColorType, Primitive};
pub use crate::traits::{EncodableLayout, Enlargeable, Pixel, PixelWithColorType, Primitive};

// Opening and loading images
pub use crate::dynimage::{
Expand Down
5 changes: 5 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ declare_primitive!(f64: (0.0)..1.0);
/// An `Enlargable::Larger` value should be enough to calculate
/// the sum (average) of a few hundred or thousand Enlargeable values.
pub trait Enlargeable: Sized + Bounded + NumCast {
/// A type with larger capacity to calculate
/// the sum (average) of a few hundred or thousand Enlargeable values.
type Larger: Copy + NumCast + Num + PartialOrd<Self::Larger> + Clone + Bounded + AddAssign;

/// Convert `Larger` type to `Self` type.
/// Clamp value that exceeds the max value and min value of `Self` type.
fn clamp_from(n: Self::Larger) -> Self {
if n > Self::max_value().to_larger() {
Self::max_value()
Expand All @@ -83,6 +87,7 @@ pub trait Enlargeable: Sized + Bounded + NumCast {
}
}

/// Convert `Self` type to `Larger` type.
fn to_larger(self) -> Self::Larger {
NumCast::from(self).unwrap()
}
Expand Down
Loading