diff options
| author | 2019-07-20 19:12:31 +0200 | |
|---|---|---|
| committer | 2019-07-20 19:12:31 +0200 | |
| commit | 2b7ad3d50eae48b1963aa8e866e184c41133ca3d (patch) | |
| tree | ae5b0c851aebb2dd8c01c08620d1cea7aa9d2466 /src/rectangle.rs | |
| parent | eefdcbe06cce97b452ee71ccb6fcd1a423d29075 (diff) | |
| download | iced-2b7ad3d50eae48b1963aa8e866e184c41133ca3d.tar.gz iced-2b7ad3d50eae48b1963aa8e866e184c41133ca3d.tar.bz2 iced-2b7ad3d50eae48b1963aa8e866e184c41133ca3d.zip | |
Decouple `iced` from `coffee`
Diffstat (limited to 'src/rectangle.rs')
| -rw-r--r-- | src/rectangle.rs | 30 | 
1 files changed, 30 insertions, 0 deletions
| diff --git a/src/rectangle.rs b/src/rectangle.rs new file mode 100644 index 00000000..ca224dad --- /dev/null +++ b/src/rectangle.rs @@ -0,0 +1,30 @@ +use crate::Point; + +/// A generic rectangle. +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +pub struct Rectangle<T> { +    /// X coordinate of the top-left corner. +    pub x: T, + +    /// Y coordinate of the top-left corner. +    pub y: T, + +    /// Width of the rectangle. +    pub width: T, + +    /// Height of the rectangle. +    pub height: T, +} + +impl Rectangle<f32> { +    /// Returns true if the given [`Point`] is contained in the [`Rectangle`]. +    /// +    /// [`Point`]: type.Point.html +    /// [`Rectangle`]: struct.Rectangle.html +    pub fn contains(&self, point: Point) -> bool { +        self.x <= point.x +            && point.x <= self.x + self.width +            && self.y <= point.y +            && point.y <= self.y + self.height +    } +} | 
