class SDL2::Rect
Public Class Methods
cast(something)
click to toggle source
Automatically construct a Rect
out of something.
-
Accepts an array of &:to_i with length 2 or 4 as [x, y, [w, h]]
Calls superclass method
# File lib/sdl2/rect.rb, line 16 def self.cast(something) if something.kind_of?(Array) result = Rect.new case something.count when 4 result.x, result.y, result.w, result.h = something.map(&:to_i) when 2 result.x, result.y = something.map(&:to_i) else raise "#{self}#cast cannot convert array length #{something.count} of: #{something.inspect}" end return result else return super end end
Public Instance Methods
empty()
click to toggle source
Returns true if the rectangle has no area.
# File lib/sdl2/rect.rb, line 35 def empty return ((!self.null?) || (self[:w] <= 0) || (self[:h] <= 0)) end
Also aliased as: empty?
enclose_points(points, count = nil, clip = self)
click to toggle source
Calculate a minimal rectangle enclosing a set of points
# File lib/sdl2/rect.rb, line 94 def enclose_points(points, count = nil, clip = self) clip = Rect.cast(clip) points, count = Point.cast_array(points, count) result = Rect.new if SDL2.enclose_points?(points, count, clip, result) return result else result.free return nil end end
has_intersection?(rect)
click to toggle source
Determine whether two rectangles intersect.
* Another rectangle to test against.
@return True when they touch, false when they don’t
# File lib/sdl2/rect.rb, line 64 def has_intersection?(rect) rect = Rect.cast(rect) SDL2.has_intersection?(self, rect) end
intersect_line(x1, y1, x2, y2)
click to toggle source
Calculate the intersection of a rectangle and line segment.
# File lib/sdl2/rect.rb, line 107 def intersect_line(x1, y1, x2, y2) result = Rect.new if SDL2.intersect_rect_and_line(self, x1, y1, x2, y2) return result else result.free return nil end end
intersection(rect)
click to toggle source
Calculate the intersection of two rectangles.
* Another rectangle to find intersection with self.
@return Rect
or Nil if no intersection found.
# File lib/sdl2/rect.rb, line 72 def intersection(rect) rect = Rect.cast(rect) result = Rect.new if SDL2.intersect_rect?(self, rect, result) return result else result.free return nil end end
Also aliased as: intersect_rect
union(rect)
click to toggle source
Calculate the union of two rectangles.
# File lib/sdl2/rect.rb, line 86 def union(rect) rect = Rect.cast(rect) result = Rect.new SDL2.union_rect(self, rect, result) return result end