All files / packages/tools/src/utilities/math/ellipse pointInEllipse.ts

92.85% Statements 13/14
50% Branches 3/6
100% Functions 1/1
90.9% Lines 10/11

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 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                      1302x 5208x 5208x   1302x 1302x 1302x     1302x 1302x     1302x       1302x    
import type { Types } from '@cornerstonejs/core';
 
type Ellipse = {
  center: Types.Point3;
  xRadius: number;
  yRadius: number;
  zRadius: number;
};
 
/**
 * Given an ellipse and a point, return true if the point is inside the ellipse
 * @param ellipse - The ellipse object to check against.
 * @param pointLPS - The point in LPS space to test.
 * @returns A boolean value.
 */
export default function pointInEllipse(
  ellipse: Ellipse,
  pointLPS: Types.Point3
): boolean {
  const { center: circleCenterWorld, xRadius, yRadius, zRadius } = ellipse;
  const [x, y, z] = pointLPS;
  const [x0, y0, z0] = circleCenterWorld;
 
  let inside = 0;
  Eif (xRadius !== 0) {
    inside += ((x - x0) * (x - x0)) / (xRadius * xRadius);
  }
 
  Eif (yRadius !== 0) {
    inside += ((y - y0) * (y - y0)) / (yRadius * yRadius);
  }
 
  Iif (zRadius !== 0) {
    inside += ((z - z0) * (z - z0)) / (zRadius * zRadius);
  }
 
  return inside <= 1;
}