class VectorBeWinding::Rect
Attributes
bottom[R]
left[R]
right[R]
top[R]
Public Class Methods
new(left, top, right, bottom)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 5 def initialize(left, top, right, bottom) @left, @right = if left <= right then [left, right] else [right, left] end @top, @bottom = if top <= bottom then [top, bottom] else [bottom, top] end end
range_containingness(a0, a1, b0, b1)
click to toggle source
check [a0, a0] contains [b0, b1]
# File lib/vector_be_winding/rect.rb, line 69 def self.range_containingness(a0, a1, b0, b1) if a0 <= b0 && b1 <= a1 (b0 - a0) * (a1 - b1) else -1 end end
range_intersectedness(a0, a1, b0, b1)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 54 def self.range_intersectedness(a0, a1, b0, b1) if a0 < b0 a1 - b0 else b1 - a0 end end
with_vectors(v0, v1)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 10 def self.with_vectors(v0, v1) self.new(v0.x, v0.y, v1.x, v1.y) end
Public Instance Methods
&(rect1)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 32 def &(rect1) newLeft = [left, rect1.left].max newTop = [top, rect1.top].max newRight = [right, rect1.right].min newBottom = [bottom, rect1.bottom].min if (newLeft <= newRight && newTop <= newBottom) Rect.new(newLeft, newTop, newRight, newBottom) else nil end end
==(rect1)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 18 def ==(rect1) left == rect1.left && top == rect1.top && right == rect1.right && bottom == rect1.bottom end
bounding_rect()
click to toggle source
# File lib/vector_be_winding/rect.rb, line 14 def bounding_rect self end
containingness(shape1)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 62 def containingness(shape1) b = shape1.bounding_rect [Rect.range_containingness(left, right, b.left, b.right), Rect.range_containingness(top, bottom, b.top, b.bottom)].min end
empty?()
click to toggle source
# File lib/vector_be_winding/rect.rb, line 23 def empty? left == right || top == bottom end
intersectedness(shape1)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 45 def intersectedness(shape1) if shape1.class == Rect [Rect.range_intersectedness(left, right, shape1.left, shape1.right), Rect.range_intersectedness(top, bottom, shape1.top, shape1.bottom)].min else shape1.intersectedness(self) end end
|(rect1)
click to toggle source
# File lib/vector_be_winding/rect.rb, line 27 def |(rect1) Rect.new([left, rect1.left].min, [top, rect1.top].min, [right, rect1.right].max, [bottom, rect1.bottom].max) end