class Overlap::Segment
Attributes
center[R]
end_position[R]
key[R]
quantity[R]
radius[R]
start_position[R]
Public Class Methods
new(start_position, end_position)
click to toggle source
# File lib/overlap/segment.rb, line 6 def initialize(start_position, end_position) @start_position = start_position @end_position = end_position build! end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/overlap/segment.rb, line 58 def <=>(other) if start_position == other.start_position end_position <=> other.end_position else start_position <=> other.start_position end end
==(other)
click to toggle source
# File lib/overlap/segment.rb, line 45 def ==(other) self.class == other.class && to_a == other.to_a end
Also aliased as: eql?
hash()
click to toggle source
# File lib/overlap/segment.rb, line 50 def hash to_a.hash end
intersection(other)
click to toggle source
# File lib/overlap/segment.rb, line 54 def intersection(other) end_position - other.start_position end
merge!(other)
click to toggle source
# File lib/overlap/segment.rb, line 12 def merge!(other) if other.start_position < start_position @start_position = other.start_position end if end_position < other.end_position @end_position = other.end_position end build! end
overlap?(other)
click to toggle source
# File lib/overlap/segment.rb, line 41 def overlap?(other) (center - other.center).abs.round(3) <= (radius + other.radius).round(3) end
same?(other)
click to toggle source
# File lib/overlap/segment.rb, line 37 def same?(other) self == other end
to_a()
click to toggle source
# File lib/overlap/segment.rb, line 33 def to_a [ start_position, end_position ] end
to_s()
click to toggle source
# File lib/overlap/segment.rb, line 24 def to_s "[#{start_position.to_f}, #{end_position.to_f}]" end
Also aliased as: inspect
Private Instance Methods
build!()
click to toggle source
# File lib/overlap/segment.rb, line 68 def build! @quantity = end_position - start_position @radius = quantity / 2 @center = start_position + radius @key = [ start_position, end_position ] end