Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic rectangle splitting
    primarykey
    data
    text
    <p><em>I'm stuck on some trivial question and, well, I guess I need help here.</em></p> <p><img src="https://i.stack.imgur.com/1k7oT.png" alt="enter image description here"></p> <p>I have two rectangles and it's guaranteed that they have one common point from their 4 base points <strong>(upper part of the picture).</strong> It's also guaranteed that they are axis-aligned.</p> <p><em>I know this common point (which also can be easily deduced), dimensions and the coordinates of these rectangles.</em></p> <hr> <p>Now, I need to <em>retrieve the coordinates</em> of the rectangles named <code>1</code> and <code>2</code> and I'm seeking for an easy way to do that <strong>(lower part of the picture)</strong>.</p> <p><em>My current implementation relies on many <code>if</code> statements and I suspect I'm too stupid to find a better way.</em></p> <p>Thank you.</p> <h3>Update: My current implementation.</h3> <pre><code>Point commonPoint = getCommonPoint(bigRectangle, smallRectangle); rectangle2 = new Rectangle(smallRectangle.getAdjacentVerticalPoint(commonPoint), bigRectangle.getOppositePoint(commonPoint)); rectangle1 = new Rectangle(smallRectangle.getAdjacentHorizontalPoint(commonPoint) bigRectangle.getOppositePoint(commonPoint)); // Now simply adjust one of these rectangles to remove the overlap, // it's trivial - we take the 'opposite' points for 'small' and 'big' // rectangles and then use their absolute coordinate difference as // a fix for either width of 'rectangle2' or height of 'rectangle1' // (in this situation it's going to be width). adjustRectangle(rectangle2); </code></pre> <p>This is refactored, but still methods <code>getCommonPoint</code> and <code>getAdjacent...</code> and <code>getOpposite</code> have many <code>if</code> statements and I thought if this can be done better.</p>
    singulars
    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.
 

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