Skip to content

Commit

Permalink
[Patch 1835886] ippa's patch to optimize Rect#collide_rect?.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacius committed Nov 21, 2007
1 parent 9e01693 commit a598972
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CREDITS
Expand Up @@ -48,3 +48,8 @@
Email:: danielneis at gmail.com
Contribution:: Patch to add Sprite#undraw (based on UpdateGroup#undraw).
Date:: 2007-07-29 (r460).

- <b>ippa</a>
Email:: admin@rubylicio.us
Contribution:: Patch to optimize Rect#collide_rect?
Date:: 2007-11-21 (595)
6 changes: 2 additions & 4 deletions lib/rubygame/rect.rb
Expand Up @@ -498,10 +498,8 @@ def collide_point?(x,y)
def collide_rect?(rect)
nself = self.normalize
rect = Rect.new_from_object(rect).normalize!
return ((( (rect.l)..(rect.r) ).include?(nself.l) or\
((nself.l)..(nself.r)).include?( rect.l)) and\
(( (rect.t)..(rect.b) ).include?(nself.t) or\
((nself.t)..(nself.b)).include?( rect.t)))
return ((nself.l >= rect.l && nself.l <= rect.r) or (rect.l >= nself.l && rect.l <= nself.r)) &&
((nself.t >= rect.t && nself.t <= rect.b) or (rect.t >= nself.t && rect.t <= nself.b))
end

# True if the given Rect is totally within the caller. Borders may
Expand Down

0 comments on commit a598972

Please sign in to comment.