UDim2 within bounds

Hey, how do I know with script if a UDim2 is within bounds? I already tried with this method

local lowerBoundX = (obj.AbsolutePosition.X + obj.AbsoluteSize.X / 2) 
local upperBoundX = (obj.AbsolutePosition.X - obj.AbsoluteSize.X / 2)
                
local lowerBoundY = (obj.AbsolutePosition.Y - obj.AbsoluteSize.Y / 2) 
local upperBoundY = (obj.AbsolutePosition.Y + obj.AbsoluteSize.Y / 2)

but doesn’t seems to work because I’m creating a raycast on 2D dimension but even if it has 30 pixels of Y difference it targets as hit

example:

this is the code im using to determine if its inside the boundaries and it seems to work with normal objects but in this case it’s like 80% useless

function UI:IsVector2WithinArea(vector2, min, max)
    local DoesXFit = (
        vector2.X > math.min(min.X, max.X) and vector2.X < math.max(min.X, max.X)
    )
    
    local DoesYFit = (
        vector2.Y > math.min(min.Y, max.Y) and vector2.Y < math.max(min.Y, max.Y)
    )
    
    if (DoesXFit and DoesYFit) then
        return true
    else
        return false
    end
end