lib/gamebox/lib/rect.rb
# Crop the calling Rect to be entirely inside the given Rect. If the
# caller does not intersect the given Rect at all, its width and height
# are set to zero, but its x and y offsets are not changed.
# 
# As a side effect, the Rect is normalized.
Crop the calling Rect to be entirely inside the given Rect. If the
caller does not intersect the given Rect at all, its width and height
are set to zero, but its x and y offsets are not changed.

As a side effect, the Rect is normalized.
Crop the calling Rect to be entirely inside the given Rect . If the caller does not intersect the given Rect at all its width and height are set to zero but its x and y offsets are not changed . As a side effect the Rect is normalized .
def clip!(rect)
    nself = self.normalize
    other = Rect.new_from_object(rect).normalize!
    if self.collide_rect?(other)
      self[0] = [nself[0], other[0]].max
      self[1] = [nself[1], other[1]].max
      self[2] = [nself.right, other.right].min - self[0]
      self[3] = [nself.bottom, other.bottom].min - self[1]
    else 
      self[0], self[1] = nself.topleft
      self[2], self[3] = 0, 0
    end
    return self
  end
def clip! ( rect ) nself = self . normalize other = Rect . new_from_object ( rect ) . normalize! if self . collide_rect? ( other ) self [ 0 ] = [ nself [ 0 ] , other [ 0 ] ] . max self [ 1 ] = [ nself [ 1 ] , other [ 1 ] ] . max self [ 2 ] = [ nself . right , other . right ] . min - self [ 0 ] self [ 3 ] = [ nself . bottom , other . bottom ] . min - self [ 1 ] else self [ 0 ] , self [ 1 ] = nself . topleft self [ 2 ] , self [ 3 ] = 0 , 0 end return self end
Crop the calling Rect to be entirely inside the given Rect.
Crop the calling Rect to be entirely inside the given Rect .
#if they do not intersect at all:
rect
<not_specific>