title: Algorithm for two rectangles placing in a specific way
body: <p>I've spent some time on looking for an appropriate way to solve my problem with the specific rectangles placement.</p>
  
  <p>Lets get directly to the problem.</p>
  
  <p>I've got two rectangles, which are fixed size. One of them is locked, and cannot be moved, and the other one can be move freely.</p>
  
  <p>I've got two of them placed on the fixed width and height canvas. Lets say it's 1000x1000.</p>
  
  <p>I need to place the second, moveable rectangle in the horizontal or vertical alignment with the other, locked one, while the moveable one cannot get outside the range of 1000x1000 canvas.</p>
  
  <p>What I understand under the definition of horizontal/vertical alignment is that if you look only at X (that's for horizontal) or Y (that's for vertical) axis, you have the locked one inside the moveable one or the other way.</p>
  
  <p>I know that I can get through my problem with a hack, but I want to find any smarter solution to it.</p>
  
  <p>Any suggestions?</p>
  
  <p>EDIT: All the informations about two rectangles are known. Corners, widths/heights.</p>