VRFS-4113 - lesson analysis error dealt with

This commit is contained in:
Seth Call 2016-05-23 15:55:28 -05:00
parent 2dafc8288a
commit 021dc47d89
1 changed files with 19 additions and 1 deletions

View File

@ -285,7 +285,8 @@ module JamRuby
}
end
def self.intersect(a, b)
# not OK for time objects. Here for docs more than anything
def self.intersect2(a, b)
min, max = a.first, a.exclude_end? ? a.max : a.last
other_min, other_max = b.first, b.exclude_end? ? b.max : b.last
@ -295,6 +296,23 @@ module JamRuby
new_min && new_max ? Range.new(new_min, new_max) : nil
end
def self.contained_by(a, test)
min, max = a.first, a.exclude_end? ? a.max : a.last
test >= min && test <= max
end
def self.intersect(a, b)
min, max = a.first, a.exclude_end? ? a.max : a.last
other_min, other_max = b.first, b.exclude_end? ? b.max : b.last
new_min = contained_by(a, other_min) ? other_min : contained_by(b, min) ? min : nil
new_max = contained_by(a, other_max) ? other_max : contained_by(b, max) ? max : nil
new_min && new_max ? Range.new(new_min, new_max) : nil
end
def self.time_ranges(histories)
ranges = []
histories.each do |history|