From 4a05a947843883998d7e251b73d911a5c688b319 Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Mon, 16 Sep 2024 00:28:08 +0100 Subject: [PATCH] feat: [Interval] add overlaps() method Found to be useful when writing tests --- pipeline/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pipeline/utils.py b/pipeline/utils.py index 9a180df..dcc3e98 100644 --- a/pipeline/utils.py +++ b/pipeline/utils.py @@ -217,6 +217,18 @@ class Interval(): self.duration = new_duration self.end = self.start + self.duration + def overlaps(self, other): + """Check if this interval overlaps (or touches) with another interval + + This is the case if: + - this.start <= other.end <= this.end + - this.start <= other.start <= this.end + - other.start <= this.end <= other.end + - other.start <= this.start <= other.end + """ + return (self.start <= other.end <= self.end) or (self.start <= other.start <= self.end) or \ + (other.start <= self.end <= other.end) or (other.start <= self.start <= other.end) + class Feature(): """A feature extracted from a media file ("has a" Interval)