title: Get points of intersection of 2 Rectangles
body: <p>How can I get the points of intersection of 2 rectangles. I have gotten this so far:</p>
  
  <pre><code>module.exports.boxIntersection = function(box1, box2) {
      var xMin1 = box1.x - box1.width;
      var xMin2 = box2.x - box2.width;
      var xMax1 = box1.x + box1.width;
      var xMax2 = box2.x + box2.width;
      var zMin1 = box1.z - box1.length;
      var zMin2 = box2.z - box2.length;
      var zMax1 = box1.z + box1.length;
      var zMax2 = box2.z + box2.length;
      var xMin = Math.max(xMin1, xMin2);
      var xMax = Math.min(xMax1, xMax2);
      if (xMax &gt; xMin) {
          var zMin = Math.max(zMin1, zMin2);
          var zMax = Math.min(zMax1, zMax2);
          if (zMax &gt; zMin) return [xMin, zMin, xMax, zMax];
      } return null;
  };
  </code></pre>
  
  <p>This only returns 2 points of intersection. But I need all the points of intersections to be returned like this:</p>
  
  <p><a href="https://i.stack.imgur.com/JIofd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JIofd.png" alt="enter image description here"></a></p>
  
  <p>In a case like this however it should only return 2 points:</p>
  
  <p><a href="https://i.stack.imgur.com/H1dFn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H1dFn.png" alt="enter image description here"></a></p>
  
  <p>I saw this question here: <a href="https://stackoverflow.com/questions/19753134/get-the-points-of-intersection-from-2-rectangles">Get the points of intersection from 2 rectangles</a></p>
  
  <p>But it only returns 2 points.</p>
  
  <p>EDIT: 
  In a case where the rectangle aligns with a side of another is should only return the points that are at a true intersection like so:
  <a href="https://i.stack.imgur.com/oJt6s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oJt6s.png" alt="enter image description here"></a></p>