All files / tools/src/types ISpline.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168                                                                                                                                                                                                                                                                                                                                               
import type { Types } from '@cornerstonejs/core';
import type {
  ClosestPoint,
  ClosestControlPoint,
  ClosestSplinePoint,
  ControlPointInfo,
} from './';
 
/**
 * Spline curve interface
 */
export interface ISpline {
  /** Number of control points */
  get numControlPoints(): number;
 
  /** Resolution of the spline curve (greater than or equal to 0) */
  get resolution(): number;
 
  /** Set the resolution of the spline curve */
  set resolution(resolution: number);
 
  /** Fixed resolution (eg: Linear Spline) */
  get fixedResolution(): boolean;
 
  /** Flag that is set to true when the curve is already closed */
  get closed(): boolean;
 
  /** Set the curve as closed which connects the last to the first point */
  set closed(closed: boolean);
 
  /** Axis-aligned bounding box (minX, minY, maxX, maxY) */
  get aabb(): Types.AABB2;
 
  /** Length of the spline curve in pixels */
  get length(): number;
 
  /**
   * Flag that is set to true when the spline needs to be updated. The update
   * runs automaticaly when needed (eg: getPolylinePoints).
   */
  get invalidated(): boolean;
 
  /**
   * Bézier curves have tangent points connected to control points
   * @returns True if the spline has tangent point or false otherwise
   */
  hasTangentPoints(): boolean;
 
  /**
   * Add a control point to the end of the array
   * @param point - Control point (2D)
   */
  addControlPoint(point: Types.Point2): void;
 
  /**
   * Add a list of control poits to the end of the array
   * @param points - Control points to be added
   */
  addControlPoints(points: Types.Point2[]): void;
 
  /**
   * Add a control point specifying its `u` value in Parameter Space which is a number from 0 to N
   * where N is the number of curve segments. The integer part is the curve segment index and the
   * decimal part is the `t` value on that curve segment.
   * @param u - `u` value in Parameter Space
   */
  addControlPointAtU(u: number): ControlPointInfo;
 
  /**
   * Delete a control point given its index
   * @param index - Control point index to be removed
   * @returns True if the control point is removed or false otherwise
   */
  deleteControlPointByIndex(index: number): boolean;
 
  /**
   * Remove all control points
   */
  clearControlPoints(): void;
 
  /**
   * Replace all control points by some new ones
   * @param points - Control points to be added to the array
   */
  setControlPoints(points: Types.Point2[]): void;
 
  /**
   * Update the coordinate of a control point given its index
   * @param index - Control point index
   * @param newControlPoint - New control point
   */
  updateControlPoint(index: number, newControlPoint: Types.Point2): void;
 
  /**
   * Get a list with all control points. The control points are cloned to prevent
   * any caller from changing them resulting in unexpected behaviors
   * @returns - List of all control points
   */
  getControlPoints(): Types.Point2[];
 
  /**
   * Finds the closest control point given a 2D point
   * @param point - Reference point
   * @returns Closest control point
   */
  getClosestControlPoint(point: Types.Point2): ClosestControlPoint;
 
  /**
   * Finds the closest control point given a 2D point and a maximum distance
   * @param point - Reference 2D point
   * @param maxDist - Maximum distance
   * @returns Closest control point that is within the given range or undefined otherwise
   */
  getClosestControlPointWithinDistance(
    point: Types.Point2,
    range: number
  ): ClosestControlPoint;
 
  /**
   * Finds the closest point on the spline curve given 2D point
   * @param point - Reference 2D point
   * @returns Closest point on the spline curve
   */
  getClosestPoint(point: Types.Point2): ClosestSplinePoint;
 
  /**
   * Finds the closest point on the straight line that connects all control points given a 2D point
   * @param point - Reference point
   * @returns Closest point on the straight line that connects all control points
   */
  getClosestPointOnControlPointLines(point: Types.Point2): ClosestPoint;
 
  /**
   * Get all points necessary to draw a spline curve
   * @returns Array with all points necessary to draw a spline curve
   */
  getPolylinePoints(): Types.Point2[];
 
  /**
   * Get all points necessary to draw the preview curve for a new possible control point
   * @returns Array with all points necessary to draw the preview curve
   */
  getPreviewPolylinePoints(
    controlPointPreview: Types.Point2,
    closeDistance: number
  ): Types.Point2[];
 
  /**
   * Checks if a point is near to the spline curve
   * @param point - Reference point
   * @param maxDist - Maximum allowed distance
   * @returns True if the point is close to the spline curve or false otherwise
   */
  isPointNearCurve(point: Types.Point2, maxDist: number): boolean;
 
  /**
   * Checks if a 2D point is inside the spline curve.
   *
   * A point is inside a curve/polygon if the number of intersections between the horizontal
   * ray emanating from the given point and to the right and the line segments is odd.
   * https://www.eecs.umich.edu/courses/eecs380/HANDOUTS/PROJ2/InsidePoly.html
   *
   * @param point - 2D Point
   * @returns True is the point is inside the spline curve or false otherwise
   */
  containsPoint(point: Types.Point2): boolean;
}