Skip to content
Snippets Groups Projects
Commit 2ee9e082 authored by marcantoinem's avatar marcantoinem
Browse files

fix: improve merge algorithm

parent 558da0ae
No related branches found
No related tags found
1 merge request!10Hotfix various
......@@ -31,8 +31,7 @@ impl Group {
let new_hour = new_period.hours | p.hours;
let is_mergeable = p.day == new_period.day
&& p.room == new_period.room
&& (p.hours.start() == new_hour.start() + 4
|| p.hours.end() + 4 == new_hour.end());
&& (p.hours.is_contiguous(new_hour));
let keep = !is_mergeable || new_hours == Hours::default();
if is_mergeable {
new_hours |= new_hour;
......@@ -49,8 +48,7 @@ impl Group {
let new_hour = new_period.hours | p.hours;
p.day == new_period.day
&& p.room == new_period.room
&& (p.hours.start() == new_hour.start() + 4
|| p.hours.end() + 4 == new_hour.end())
&& (p.hours.is_contiguous(new_hour))
})
.unwrap();
first_period.hours |= new_hours;
......
......@@ -53,6 +53,10 @@ impl Hours {
(self.end() >> 2) + 8
}
pub fn is_contiguous(self, other: Self) -> bool {
self.start().abs_diff(other.start()) <= 5 || self.end().abs_diff(other.end()) <= 5
}
pub fn starting_text(self) -> String {
let mut hour = self.starting_hour().to_string();
let minute = self.start_minutes();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment