lib/gamebox/lib/rect.rb
# Translate the calling Rect to be entirely inside the given Rect. If 
# the caller is too large along either axis to fit in the given rect,
# it is centered with respect to the given rect, along that axis.
Translate the calling Rect to be entirely inside the given Rect. If
the caller is too large along either axis to fit in the given rect,
it is centered with respect to the given rect, along that axis.
Translate the calling Rect to be entirely inside the given Rect . If the caller is too large along either axis to fit in the given rect it is centered with respect to the given rect along that axis .
def clamp!(rect)
    nself = self.normalize
    rect = Rect.new_from_object(rect)
    unless rect.contain?(nself)
      if nself[2] >= rect[2]
        self[0] = rect.centerx - nself[2].div(2)
      else
        if nself[0] < rect[0]
          self[0] = rect[0]
        elsif nself.right > rect.right
          self[0] = rect.right - nself[2]
        end
      end
      if nself[3] >= rect[3]
        self[1] = rect.centery - nself[3].div(2)
      else
        if nself[1] < rect[1]
          self[1] = rect[1]
        elsif nself.bottom > rect.bottom
          self[1] = rect.bottom - nself[3]
        end
      end
    end
    return self
  end
def clamp! ( rect ) nself = self . normalize rect = Rect . new_from_object ( rect ) unless rect . contain? ( nself ) if nself [ 2 ] >= rect [ 2 ] self [ 0 ] = rect . centerx - nself [ 2 ] . div ( 2 ) else if nself [ 0 ] < rect [ 0 ] self [ 0 ] = rect [ 0 ] elsif nself . right > rect . right self [ 0 ] = rect . right - nself [ 2 ] end end if nself [ 3 ] >= rect [ 3 ] self [ 1 ] = rect . centery - nself [ 3 ] . div ( 2 ) else if nself [ 1 ] < rect [ 1 ] self [ 1 ] = rect [ 1 ] elsif nself . bottom > rect . bottom self [ 1 ] = rect . bottom - nself [ 3 ] end end end return self end
Translate the calling Rect to be entirely inside the given Rect.
Translate the calling Rect to be entirely inside the given Rect .
#If self is inside given, there is no need to move self #If self is too wide: #Else self is not too wide #If self is to the left of arg #If self is to the right of arg #Otherwise, leave x alone #If self is too tall: #Else self is not too tall #If self is above arg #If self below arg #Otherwise, leave y alone
rect
<not_specific>