lib/ray/rect.rb in ray-0.1.1 vs lib/ray/rect.rb in ray-0.2.0
- old
+ new
@@ -19,20 +19,21 @@
(y + h) <= (rect.y + rect.h)
end
# @return [true, false] True if the receiver is outside the rect.
def outside?(rect)
- rect = rect.to_rect
- !rect.contain?(top_left) &&
- !rect.contain?(bottom_left) &&
- !rect.contain?(top_right) &&
- !rect.contain?(bottom_right)
+ !collide?(rect)
end
# @return [true, false] True if the receiver collides with the rect.
def collide?(rect)
- !outside?(rect)
+ rect = rect.to_rect
+
+ rect.x < x + width &&
+ x < rect.x + rect.width &&
+ rect.y < y + height &&
+ y < rect.y + rect.height
end
# @return [true, false] True if the receiver contians this point
def contain?(p)
p = p.to_vector2
@@ -103,14 +104,7 @@
class Array
# @return [Ray::Rect] Converts an array to a rect.
def to_rect
Ray::Rect.new(*self)
- end
-end
-
-class Hash
- # @return [Ray::Rect] Converts a hash into a rect.
- def to_rect
- Ray::Rect.new(self)
end
end