All files / domain/utils/geometry collision.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 262x 2x                     2x       8x 8x   8x 32x     8x    
import axis from "./axis";
import axisCollision from "./axisCollision";
import { RectangleCorners } from "./interfaces";
 
/**
 * Check whether two rectangles collide on each one of their four axis. If
 * all axis collide, then the two rectangles do collide on the plane.
 *
 * @param  {array}    Rectangle A's corners.
 * @param  {array}    Rectangle B's corners.
 * @return {boolean}  True if the rectangles collide.
 */
export default function collision(
  c1: RectangleCorners,
  c2: RectangleCorners
): boolean {
  const axs = axis(c1, c2);
  let col = true;
 
  for (let i = 0; i < 4; i++) {
    col = col && axisCollision(axs[i], c1, c2);
  }
 
  return col;
}