All files / domain/utils/geometry lowerLeftCoor.ts

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

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                2x 22x 22x          
import { Rectangle, Point } from "./interfaces";
 
/**
 * Get coordinates of a rectangle's lower left corner from its top points.
 *
 * @param  {object} A rectangle defined by two points (x1, y1) and (x2, y2).
 * @return {object} Coordinates of the corner (x, y).
 */
export default function lowerLeftCoor(r: Rectangle): Point {
  const width = Math.sqrt((r.x2 - r.x1) ** 2 + (r.y2 - r.y1) ** 2);
  return {
    x: r.x1 - ((r.y2 - r.y1) * r.height) / width,
    y: r.y1 + ((r.x2 - r.x1) * r.height) / width
  };
}