diff --git a/CREDITS b/CREDITS index e1d70c10..ffc667b0 100644 --- a/CREDITS +++ b/CREDITS @@ -48,3 +48,8 @@ Email:: danielneis at gmail.com Contribution:: Patch to add Sprite#undraw (based on UpdateGroup#undraw). Date:: 2007-07-29 (r460). + +- ippa + Email:: admin@rubylicio.us + Contribution:: Patch to optimize Rect#collide_rect? + Date:: 2007-11-21 (595) diff --git a/lib/rubygame/rect.rb b/lib/rubygame/rect.rb index d4103d97..8651f5c0 100644 --- a/lib/rubygame/rect.rb +++ b/lib/rubygame/rect.rb @@ -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