diff options
| author | jussi | 2024-02-21 23:25:17 +0200 |
|---|---|---|
| committer | jussi | 2024-02-21 23:25:17 +0200 |
| commit | 178196b0ffb8e2358ce9b0be5e1570a10136eb45 (patch) | |
| tree | 45d657547c10c01dc230dbf5dc9f30281cad621a /examples/resources/lib/rectangle.lua | |
| parent | 836c9d1d0005c32714c89b3adecbb232472b494a (diff) | |
| download | reilua-enhanced-178196b0ffb8e2358ce9b0be5e1570a10136eb45.tar.gz reilua-enhanced-178196b0ffb8e2358ce9b0be5e1570a10136eb45.tar.bz2 reilua-enhanced-178196b0ffb8e2358ce9b0be5e1570a10136eb45.zip | |
Raygui lib tooltip.
Diffstat (limited to 'examples/resources/lib/rectangle.lua')
| -rw-r--r-- | examples/resources/lib/rectangle.lua | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/examples/resources/lib/rectangle.lua b/examples/resources/lib/rectangle.lua index a37c1c1..4b8d53b 100644 --- a/examples/resources/lib/rectangle.lua +++ b/examples/resources/lib/rectangle.lua @@ -109,7 +109,7 @@ function Rectangle:area() return self.width * self.height end ---- Returns rectangle that fits both rectangles inside it +-- Returns rectangle that fits both rectangles inside it function Rectangle:fit( rec ) local pos = Vector2:new( math.min( self.x, rec.x ), math.min( self.y, rec.y ) ) @@ -121,10 +121,20 @@ function Rectangle:fit( rec ) ) end ---- If rectangle is fully inside another rectangle -function Rectangle:isInside( rect ) - return rect.x <= self.x and self.x + self.width <= rect.x + rect.width - and rect.y <= self.y and self.y + self.height <= rect.y + rect.height +-- If rectangle is fully inside another rectangle +function Rectangle:isInside( rec ) + return rec.x <= self.x and self.x + self.width <= rec.x + rec.width + and rec.y <= self.y and self.y + self.height <= rec.y + rec.height +end + +-- Returns clamped rectangle that is inside another rectangle. +function Rectangle:clampInside( rec ) + return Rectangle:new( + math.max( rec.x, math.min( self.x, rec.x + rec.width - self.width ) ), + math.max( rec.y, math.min( self.y, rec.y + rec.height - self.height ) ), + self.width, + self.height + ) end function Rectangle:checkCollisionRec( rec ) |
