Skip to content

Commit

Permalink
wip feat(area): add extend method with tests
Browse files Browse the repository at this point in the history
wip: add aditionnal tests
  • Loading branch information
gwen-lg committed Sep 14, 2024
1 parent a4d3502 commit a6c1534
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/content/area.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cmp::{max, min};

use super::{ContentError, Size};

/// Location at which to display the subtitle.
Expand Down Expand Up @@ -74,6 +76,14 @@ impl Area {
&& self.0.y1 <= area.0.y1
&& self.0.y2 >= area.0.y2
}

/// Extend the area from an other `Area`
pub fn extend(&mut self, area: Self) {
self.0.x1 = min(self.0.x1, area.0.x1);
self.0.y1 = min(self.0.y1, area.0.y1);
self.0.x2 = max(self.0.x2, area.0.x2);
self.0.y2 = max(self.0.y2, area.0.y2);
}
}

impl TryFrom<AreaValues> for Area {
Expand Down Expand Up @@ -299,4 +309,27 @@ mod tests {
y2: 19,
})));
}

#[test]
fn area_extend() {
let area_ref = Area(AREA_REF);

assert!(
{
let mut new = area_ref;
new.extend(Area(AreaValues {
x1: 10,
y1: 20,
x2: 20,
y2: 30,
}));
new
} == Area(AreaValues {
x1: 10,
y1: 10,
x2: 20,
y2: 30
})
)
}
}

0 comments on commit a6c1534

Please sign in to comment.