Fluido - 2005-04-28

Hello there. I had the need to generate the insertion of two rectangles. Here is the code I used. You may be interested in adding this code (or a better optimized one) in the RUDL codebase.

class Array
  def intersection(orect)
    return nil if orect==nil || !overlaps?(orect)
   
    nx=(x>orect.x) ? x : orect.x
    ny=(y>orect.y) ? y : orect.y
    nxt=(x+w<orect.x+orect.w) ? x+w : orect.x+orect.w
    nyt=(y+h<orect.y+orect.h) ? y+h : orect.y+orect.h

    return [nx,ny,nxt-nx+1,nyt-ny+1]
  end
end

Ciao
Carlo