All files / utils/geometry rectangleCorners.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 1/1
100% Lines 6/6

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 242x 2x                 2x     20x 20x   20x              
import lowerLeftCoor from "./lowerLeftCoor";
import lowerRightCoor from "./lowerRightCoor";
import { Rectangle, Point } from "./interfaces";
 
/**
 * Get the coordinates of all the corners of a rectangle from its top point.
 *
 * @param  {object} A rectangle defined by two points (x1, y1) and (x2, y2).
 * @return {array}  An array of the four corners' coordinates (x, y).
 */
export default function rectangleCorners(
  r: Rectangle
): [Point, Point, Point, Point] {
  const llc = lowerLeftCoor(r);
  const lrc = lowerRightCoor(r, llc);
 
  return [
    { x: r.x1, y: r.y1 },
    { x: r.x2, y: r.y2 },
    { x: llc.x, y: llc.y },
    { x: lrc.x, y: lrc.y }
  ];
}