Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There will not be an unique solution for any particular setup, but you can easily find one of the solutions with this algorithm: </p> <ol> <li>Find a rectangle within A that is above rectangle B. If the top of A is higher than B (i.e. has a lower value in px), there is such an rectangle. This rectangle is defined by: (left edge of A, top edge of A) to (right edge of A, top edge of B). </li> <li>If the left edge of B is to the right of the left edge of A, the next rectangle is: (left edge of A, min(top edge of A, top edge of B)) to (left edge of B, max (bottom edge of A, bottom edge of B)) </li> <li>If the right edge of B is to the left of the right edge of B, similar to above</li> <li>...and the possible rectangle below B</li> </ol> <p>In total, you will get from 0 to 4 rectangles. </p> <p>Pseudocode with a somewhat unusual, but for this purpose clear, definition of rectangle: </p> <pre><code>function getClipped(A, B) { var rectangles = []; if (A.top &lt; B.top) { rectangles.push({ left: A.left, top: A.top, right: A.right, bottom: B.top }); } if (A.left &lt; B.left) { rectangles.push({ left: A.left, top: max(A.top, B.top), right: B.left, bottom: min(A.bottom, B.bottom) }); } if (A.right &gt; B.right) { rectangles.push({ left: B.right, top: max(A.top, B.top), right: A.right, bottom: min(A.bottom, B.bottom) }); } if (A.bottom &gt; B.bottom) { rectangles.push({ left: A.left, top: B.bottom, right: A.right, bottom. A.bottom }); } return rectangles; } var rectA = { left: nn, top: nn, right: nn, bottom: nn}; var rectB = { left: nn, top: nn, right: nn, bottom: nn}; var clipped = getClipped(rectA, rectB) ; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload