ellipse.d.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { Line } from './line';
  2. import { Point } from './point';
  3. import { Rectangle } from './rectangle';
  4. import { Geometry } from './geometry';
  5. export declare class Ellipse extends Geometry implements Ellipse.EllipseLike {
  6. x: number;
  7. y: number;
  8. a: number;
  9. b: number;
  10. get center(): Point;
  11. constructor(x?: number, y?: number, a?: number, b?: number);
  12. /**
  13. * Returns a rectangle that is the bounding box of the ellipse.
  14. */
  15. bbox(): Rectangle;
  16. /**
  17. * Returns a point that is the center of the ellipse.
  18. */
  19. getCenter(): Point;
  20. /**
  21. * Returns ellipse inflated in axis-x by `2 * amount` and in axis-y by
  22. * `2 * amount`.
  23. */
  24. inflate(amount: number): this;
  25. /**
  26. * Returns ellipse inflated in axis-x by `2 * dx` and in axis-y by `2 * dy`.
  27. */
  28. inflate(dx: number, dy: number): this;
  29. /**
  30. * Returns a normalized distance from the ellipse center to point `p`.
  31. * Returns `n < 1` for points inside the ellipse, `n = 1` for points
  32. * lying on the ellipse boundary and `n > 1` for points outside the ellipse.
  33. */
  34. normalizedDistance(x: number, y: number): number;
  35. normalizedDistance(p: Point.PointLike | Point.PointData): number;
  36. /**
  37. * Returns `true` if the point `p` is inside the ellipse (inclusive).
  38. * Returns `false` otherwise.
  39. */
  40. containsPoint(x: number, y: number): boolean;
  41. containsPoint(p: Point.PointLike | Point.PointData): boolean;
  42. /**
  43. * Returns an array of the intersection points of the ellipse and the line.
  44. * Returns `null` if no intersection exists.
  45. */
  46. intersectsWithLine(line: Line): Point[] | null;
  47. /**
  48. * Returns the point on the boundary of the ellipse that is the
  49. * intersection of the ellipse with a line starting in the center
  50. * of the ellipse ending in the point `p`.
  51. *
  52. * If angle is specified, the intersection will take into account
  53. * the rotation of the ellipse by angle degrees around its center.
  54. */
  55. intersectsWithLineFromCenterToPoint(p: Point.PointLike | Point.PointData, angle?: number): Point;
  56. /**
  57. * Returns the angle between the x-axis and the tangent from a point. It is
  58. * valid for points lying on the ellipse boundary only.
  59. */
  60. tangentTheta(p: Point.PointLike | Point.PointData): number;
  61. scale(sx: number, sy: number): this;
  62. rotate(angle: number, origin?: Point.PointLike | Point.PointData): this;
  63. translate(dx: number, dy: number): this;
  64. translate(p: Point.PointLike | Point.PointData): this;
  65. equals(ellipse: Ellipse): boolean;
  66. clone(): Ellipse;
  67. toJSON(): {
  68. x: number;
  69. y: number;
  70. a: number;
  71. b: number;
  72. };
  73. serialize(): string;
  74. }
  75. export declare namespace Ellipse {
  76. function isEllipse(instance: any): instance is Ellipse;
  77. }
  78. export declare namespace Ellipse {
  79. interface EllipseLike extends Point.PointLike {
  80. x: number;
  81. y: number;
  82. a: number;
  83. b: number;
  84. }
  85. type EllipseData = [number, number, number, number];
  86. }
  87. export declare namespace Ellipse {
  88. function create(x?: number | Ellipse | EllipseLike | EllipseData, y?: number, a?: number, b?: number): Ellipse;
  89. function parse(e: Ellipse | EllipseLike | EllipseData): Ellipse;
  90. function fromRect(rect: Rectangle): Ellipse;
  91. }