pub struct Region { /* private fields */ }Expand description
Normalized image edges. Zero-area regions are valid.
Implementations§
Source§impl Region
impl Region
Sourcepub fn new(top: f64, bottom: f64, left: f64, right: f64) -> Result<Self, Error>
pub fn new(top: f64, bottom: f64, left: f64, right: f64) -> Result<Self, Error>
Validate finite edges in [0, 1], with top <= bottom and left <= right.
§Errors
Returns InvalidArgument if an edge is nonfinite or outside [0, 1],
if top exceeds bottom, or if left exceeds right. Zero-area regions are valid.
Sourcepub fn padded(&self, fraction: f64) -> Result<Self, Error>
pub fn padded(&self, fraction: f64) -> Result<Self, Error>
Grow each side by a fraction of the region size, clipping to the image.
§Errors
Returns InvalidArgument for nonfinite padding or resulting invalid
edges, such as negative padding that shrinks past the opposite edge.
Sourcepub fn pixels(
&self,
width: u32,
height: u32,
) -> Result<(u32, u32, u32, u32), Error>
pub fn pixels( &self, width: u32, height: u32, ) -> Result<(u32, u32, u32, u32), Error>
Pixel edges (left, top, right, bottom), using ties-to-even rounding.
use semantic_operators::Region;
let region = Region::new(0.2, 0.6, 0.1, 0.5)?;
assert_eq!(region.pixels(1000, 500)?, (100, 100, 500, 300));§Errors
Returns InvalidArgument if either pixel dimension is zero.
Trait Implementations§
Source§impl AnswerType for Region
impl AnswerType for Region
Source§fn from_answer_value(v: &AnswerValue) -> Result<Self, Error>
fn from_answer_value(v: &AnswerValue) -> Result<Self, Error>
Check and copy a heterogeneous value. Read more
impl Copy for Region
Source§impl<'de> Deserialize<'de> for Region
impl<'de> Deserialize<'de> for Region
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Region
Auto Trait Implementations§
impl Freeze for Region
impl RefUnwindSafe for Region
impl Send for Region
impl Sync for Region
impl Unpin for Region
impl UnsafeUnpin for Region
impl UnwindSafe for Region
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more