Checking whether two strokes overlap I have these two functions and I was just wondering if there is any way to shorten the line of code with the many &amp;&amp; statements. Shortening of the rest of the code would be cool too, but it's not necessary. I'm trying to learn if there is a better way to accomplish this though. 

# Accepts two stroks and determines if they overlap with one another
def overlap? stroke1, stroke2
    min_x = 0
    max_x = 1
    min_y = 2
    max_y = 3

    bounds1 = get_bounds stroke1
    bounds2 = get_bounds stroke2

    return true if (bounds1[max_x] &gt;= bounds2[min_x]) &amp;&amp; (bounds1[max_y] &gt;= bounds2[min_y]) &amp;&amp; (bounds2[max_x] &gt;= bounds1[min_x]) &amp;&amp; (bounds2[max_y] &gt;= bounds1[min_y])

    return false
end 

# Returns an array of bounds [x_min, x_max, y_min, y_max] for the stroke
def get_bounds stroke
    # Arrays for storing x and y values for the stroke currently being inspected
    xvals = Array.new
    yvals = Array.new

    stroke.each_slice(3) do |point|
        xvals.push(point[0])
        yvals.push(point[1])
    end

    # A temporary array that stores the min/max x/y for the stroke being inspected
    bounds = Array.new
    bounds &lt;&lt; xvals.min &lt;&lt; xvals.max &lt;&lt; yvals.min &lt;&lt; yvals.max

    return bounds
end


I actually did not write this code, but I offered to clean it up and I came upon this and thought that there was probably a better way.
The code in the if is duplicate, so we can extract it to a method that I will call gte (greater than or equal). The maxs and mins values ​​are used at this comparison, so they will be moved to the new method too:

def gte(bounds1, bounds2)
    min_x, max_x, min_y, max_y = 0, 1, 2, 3

    bounds1[max_x] &gt;= bounds2[min_x] &amp;&amp; bounds1[max_y] &gt;= bounds2[min_y]
end


The content in the if expression changes to:

gte(bounds1, bounds2) &amp;&amp; gte(bounds2, bounds1)


But the if is not necessary because this expression already returns a boolean value, then we will return it directly. The keyword return is not required, then the method overlap? code looks like this:

def overlap?(stroke1, stroke2)
    bounds1 = get_bounds stroke1
    bounds2 = get_bounds stroke2

    gte(bounds1, bounds2) &amp;&amp; gte(bounds2, bounds1)
end


Maybe you have a better name than gte, but remember that it must have a meaningful name!