def clamp!(rect)
nself = self.normalize
rect = Rect.new_from_object(rect)
unless rect.contain?(nself)
if nself.at(2) >= rect.at(2)
self[0] = rect.centerx - nself.at(2).div(2)
else
if nself.at(0) < rect.at(0)
self[0] = rect.at(0)
elsif nself.right > rect.right
self[0] = rect.right - nself.at(2)
end
end
if nself.at(3) >= rect.at(3)
self[1] = rect.centery - nself.at(3).div(2)
else
if nself.at(1) < rect.at(1)
self[1] = rect.at(1)
elsif nself.bottom > rect.bottom
self[1] = rect.bottom - nself.at(3)
end
end
end
return self
end