function pointInRect(rect, point, rotationPoint) {
  if (rect.width <= 0 || rect.height <= 0) {
    return false; // early out
  }

  if (rotationPoint !== undefined) {
    // Rotate the point the same amount as the rectangle
    const tmp = {
      x: point.x - rotationPoint.x,
      y: point.y - rotationPoint.y,
    };

    if (rotationPoint.angle !== 0) {
      // In order to get the coordinates the same, you need to
      // rotate in the reverse direction
      const angle = -rotationPoint.angle;

      const tmp2 = {
        x: Math.cos(angle) * tmp.x - Math.sin(angle) * tmp.y,
        y: Math.sin(angle) * tmp.x + Math.cos(angle) * tmp.y,
      };
      point = tmp2;
    } else {
      point = tmp;
    }

    // Note that if a rotation is specified, the rectangle coordinates
    // are **not* the full canvas coordinates. They are relative to the
    // rotationPoint. Hence, the point coordinates need not be translated
    // back in this case.
  }

  const right = rect.x + rect.width;
  const bottom = rect.y + rect.width;

  return (
    rect.left < point.x &&
    right > point.x &&
    rect.top < point.y &&
    bottom > point.y
  );
}
Check if the point falls within the given rectangle.
@param {rect} rect
@param {point} point
@param {rotationPoint} [rotationPoint] if specified, the rotation that applies to the rectangle.
@returns {boolean}  true if point within rectangle, false otherwise