path.d.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import * as PathUtil from './util';
  2. import { Line } from '../line';
  3. import { Point } from '../point';
  4. import { Curve } from '../curve';
  5. import { Polyline } from '../polyline';
  6. import { Rectangle } from '../rectangle';
  7. import { Geometry } from '../geometry';
  8. import { Close } from './close';
  9. import { LineTo } from './lineto';
  10. import { MoveTo } from './moveto';
  11. import { CurveTo } from './curveto';
  12. import { normalizePathData } from './normalize';
  13. import { Segment } from './segment';
  14. export declare class Path extends Geometry {
  15. protected readonly PRECISION: number;
  16. segments: Segment[];
  17. constructor();
  18. constructor(line: Line);
  19. constructor(curve: Curve);
  20. constructor(polyline: Polyline);
  21. constructor(segment: Segment);
  22. constructor(segments: Segment[]);
  23. constructor(lines: Line[]);
  24. constructor(curves: Curve[]);
  25. get start(): Point | null;
  26. get end(): Point | null;
  27. moveTo(x: number, y: number): this;
  28. moveTo(point: Point.PointLike): this;
  29. moveTo(line: Line): this;
  30. moveTo(curve: Curve): this;
  31. moveTo(point: Point.PointLike, ...points: Point.PointLike[]): this;
  32. moveTo(x: number, y: number, ...coords: number[]): this;
  33. lineTo(x: number, y: number): this;
  34. lineTo(point: Point.PointLike): this;
  35. lineTo(line: Line): this;
  36. lineTo(x: number, y: number, ...coords: number[]): this;
  37. lineTo(point: Point.PointLike, ...points: Point.PointLike[]): this;
  38. curveTo(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number): this;
  39. curveTo(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, ...coords: number[]): this;
  40. curveTo(p1: Point.PointLike, p2: Point.PointLike, p3: Point.PointLike): this;
  41. curveTo(p1: Point.PointLike, p2: Point.PointLike, p3: Point.PointLike, ...points: Point.PointLike[]): this;
  42. arcTo(rx: number, ry: number, xAxisRotation: number, largeArcFlag: 0 | 1, sweepFlag: 0 | 1, endX: number, endY: number): this;
  43. arcTo(rx: number, ry: number, xAxisRotation: number, largeArcFlag: 0 | 1, sweepFlag: 0 | 1, endPoint: Point.PointLike): this;
  44. quadTo(controlPoint: Point.PointLike, endPoint: Point.PointLike): this;
  45. quadTo(controlPointX: number, controlPointY: number, endPointX: number, endPointY: number): this;
  46. close(): this;
  47. drawPoints(points: (Point.PointLike | Point.PointData)[], options?: PathUtil.DrawPointsOptions): void;
  48. bbox(): Rectangle | null;
  49. appendSegment(seg: Segment | Segment[]): this;
  50. insertSegment(index: number, seg: Segment | Segment[]): this;
  51. removeSegment(index: number): Segment;
  52. replaceSegment(index: number, seg: Segment | Segment[]): void;
  53. getSegment(index: number): Segment;
  54. protected fixIndex(index: number): number;
  55. segmentAt(ratio: number, options?: Path.Options): Segment | null;
  56. segmentAtLength(length: number, options?: Path.Options): Segment | null;
  57. segmentIndexAt(ratio: number, options?: Path.Options): number | null;
  58. segmentIndexAtLength(length: number, options?: Path.Options): number | null;
  59. getSegmentSubdivisions(options?: Path.Options): Segment[][];
  60. protected updateSubpathStartSegment(segment: Segment): void;
  61. protected prepareSegment(segment: Segment, previousSegment: Segment | null, nextSegment: Segment | null): Segment;
  62. closestPoint(p: Point.PointLike, options?: Path.Options): Point | null;
  63. closestPointLength(p: Point.PointLike, options?: Path.Options): number;
  64. closestPointNormalizedLength(p: Point.PointLike, options?: Path.Options): number;
  65. closestPointT(p: Point.PointLike, options?: Path.Options): {
  66. segmentIndex: number;
  67. value: number;
  68. } | null;
  69. closestPointTangent(p: Point.PointLike, options?: Path.Options): Line | null;
  70. containsPoint(p: Point.PointLike, options?: Path.Options): boolean;
  71. pointAt(ratio: number, options?: Path.Options): Point | null;
  72. pointAtLength(length: number, options?: Path.Options): Point | null;
  73. pointAtT(t: {
  74. segmentIndex: number;
  75. value: number;
  76. }): Point | null;
  77. divideAt(ratio: number, options?: Path.Options): Path[] | null;
  78. divideAtLength(length: number, options?: Path.Options): Path[] | null;
  79. intersectsWithLine(line: Line, options?: Path.Options): Point[] | null;
  80. isDifferentiable(): boolean;
  81. isValid(): boolean;
  82. length(options?: Path.Options): number;
  83. lengthAtT(t: {
  84. segmentIndex: number;
  85. value: number;
  86. }, options?: Path.Options): number;
  87. tangentAt(ratio: number, options?: Path.Options): Line | null;
  88. tangentAtLength(length: number, options?: Path.Options): Line | null;
  89. tangentAtT(t: {
  90. segmentIndex: number;
  91. value: number;
  92. }): Line | null;
  93. protected getPrecision(options?: Path.Options): number;
  94. protected getSubdivisions(options?: Path.Options): Segment[][];
  95. protected getOptions(options?: Path.Options): {
  96. precision: number;
  97. segmentSubdivisions: Segment[][];
  98. };
  99. toPoints(options?: Path.Options): Point[][] | null;
  100. toPolylines(options?: Path.Options): Polyline[] | null;
  101. scale(sx: number, sy: number, origin?: Point.PointLike): this;
  102. rotate(angle: number, origin?: Point.PointLike | Point.PointData): this;
  103. translate(tx: number, ty: number): this;
  104. translate(p: Point.PointLike): this;
  105. clone(): Path;
  106. equals(p: Path): boolean;
  107. toJSON(): (import("../types").JSONObject | import("../types").JSONArray)[];
  108. serialize(): string;
  109. toString(): string;
  110. }
  111. export declare namespace Path {
  112. function isPath(instance: any): instance is Path;
  113. }
  114. export declare namespace Path {
  115. interface Options {
  116. precision?: number | null;
  117. segmentSubdivisions?: Segment[][] | null;
  118. }
  119. }
  120. export declare namespace Path {
  121. function parse(pathData: string): Path;
  122. function createSegment(type: 'M', x: number, y: number): MoveTo;
  123. function createSegment(type: 'M', point: Point.PointLike): MoveTo;
  124. function createSegment(type: 'M', line: Line): MoveTo;
  125. function createSegment(type: 'M', curve: Curve): MoveTo;
  126. function createSegment(type: 'M', point: Point.PointLike, ...points: Point.PointLike[]): Segment[];
  127. function createSegment(type: 'M', x: number, y: number, ...coords: number[]): Segment[];
  128. function createSegment(type: 'L', x: number, y: number): LineTo;
  129. function createSegment(type: 'L', point: Point.PointLike): LineTo;
  130. function createSegment(type: 'L', line: Line): LineTo;
  131. function createSegment(type: 'L', point: Point.PointLike, ...points: Point.PointLike[]): LineTo[];
  132. function createSegment(type: 'L', x: number, y: number, ...coords: number[]): LineTo[];
  133. function createSegment(type: 'C', x0: number, y0: number, x1: number, y1: number, x2: number, y2: number): CurveTo;
  134. function createSegment(type: 'C', x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, ...coords: number[]): CurveTo[];
  135. function createSegment(type: 'C', p1: Point.PointLike, p2: Point.PointLike, p3: Point.PointLike): CurveTo;
  136. function createSegment(type: 'C', p1: Point.PointLike, p2: Point.PointLike, p3: Point.PointLike, ...points: Point.PointLike[]): CurveTo[];
  137. function createSegment(type: 'Z' | 'z'): Close;
  138. }
  139. export declare namespace Path {
  140. const normalize: typeof normalizePathData;
  141. const isValid: typeof PathUtil.isValid;
  142. const drawArc: typeof PathUtil.drawArc;
  143. const drawPoints: typeof PathUtil.drawPoints;
  144. const arcToCurves: typeof PathUtil.arcToCurves;
  145. }