From 178196b0ffb8e2358ce9b0be5e1570a10136eb45 Mon Sep 17 00:00:00 2001 From: jussi Date: Wed, 21 Feb 2024 23:25:17 +0200 Subject: Raygui lib tooltip. --- examples/resources/lib/rectangle.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'examples/resources/lib/rectangle.lua') 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 ) -- cgit v1.2.3