-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathindex.d.ts
672 lines (575 loc) · 21.3 KB
/
index.d.ts
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
// Type definitions for flatten-js library
// Project: https://github.com/alexbol99/flatten-js
// Definitions by: Alex Bol
import IntervalTree from "@flatten-js/interval-tree";
/// <reference types="@flatten-js/interval-tree" />
declare namespace Flatten {
interface SVGAttributes {
r?: number,
stroke?: string | number,
strokeWidth?: number,
fill?: string | number,
fillRule?: "nonzero" | "evenodd",
fillOpacity?: number,
id? : string,
className?: string
}
type Comparable = any; // any object that implements operators '<' and '==' and 'max'
type Value = any;
interface Interval {
low: Comparable;
high: Comparable;
readonly max: Comparable;
clone(): Interval;
less_than(other_interval: Interval) : boolean;
equal_to(other_interval: Interval) : boolean;
intersect(other_interval: Interval) : boolean;
not_intersect(other_interval: Interval) : boolean;
output() : any;
comparable_max(arg1: Comparable, arg2: Comparable) : Comparable;
comparable_less_than(arg1: Comparable, arg2: Comparable ) : boolean;
}
class LinkedListElement {
next: LinkedListElement | null;
prev: LinkedListElement | null;
}
class LinkedList {
// members
first: LinkedListElement;
last: LinkedListElement;
// getters
readonly size: number;
// public methods
append(element: LinkedListElement): LinkedList;
insert(newElement: LinkedListElement, prevElement: LinkedListElement): LinkedList;
remove(element: LinkedListElement): LinkedList;
toArray(start?: LinkedListElement, end?: LinkedListElement): LinkedListElement[];
isEmpty(): boolean;
static testInfiniteLoop(first: LinkedListElement): undefined;
}
class CircularLinkedList extends LinkedList {}
type DE9IM_element = Array<AnyShape> | undefined;
/* Impossible to set length for tuple ? Really ? */
type DE9IM_matrix = [
DE9IM_element,DE9IM_element,DE9IM_element,
DE9IM_element,DE9IM_element,DE9IM_element,
DE9IM_element,DE9IM_element,DE9IM_element
];
class DE9IM {
// member
m: DE9IM_matrix;
get I2I();
set I2I(geom: Array<AnyShape>);
get I2B();
set I2B(geom: Array<AnyShape>);
get I2E();
set I2E(geom: Array<AnyShape>);
get B2I();
set B2I(geom: Array<AnyShape>);
get B2B();
set B2B(geom: Array<AnyShape>);
get B2E();
set B2E(geom: Array<AnyShape>);
get E2I();
set E2I(geom: Array<AnyShape>);
get E2B();
set E2B(geom: Array<AnyShape>);
get E2E();
set E2E(geom: Array<AnyShape>);
toString() : string;
}
const CCW = true;
const CW = false;
class Shape {
translate(vec: Vector): Shape;
translate(x:number, y:number): Shape;
rotate(angle: number, center?: Point): Shape;
scale(scaleX: number, scaleY: number) : Shape;
transform(matrix: Matrix): Shape;
}
class Arc extends Shape {
counterClockwise: boolean;
// members
ps: Point;
r: Number;
startAngle: number;
endAngle: number;
constructor(
pc?: Point,
r?: number,
startAngle?: number,
endAngle?: number,
counterClockwise?: boolean
);
// getters
readonly start: Point;
readonly end: Point;
readonly center: Point;
readonly length: number;
readonly sweep: number;
readonly vertices: [Point, Point];
readonly box: Box;
// public methods
clone(): Arc;
contains(pt: Point): boolean;
split(pt: Point): [Arc | undefined, Arc | undefined];
middle(): Point;
pointAtLength(length: number): Point|null;
chordHeight(): number;
intersect(shape: AnyShape): Array<Point>;
distanceTo(geom: AnyShape | PlanarSet): [number, Segment];
breakToFunctional(): Array<Arc>;
tangentInEnd(): Vector;
tangentInStart(): Vector;
reverse(): Arc;
translate(vec: Vector): Arc;
translate(x:number, y:number): Arc;
rotate(angle: number, center?: Point): Arc;
scale(scaleX: number, scaleY: number) : Arc;
transform(matrix: Matrix): Arc;
sortPoints(pts: Array<Point>): Array<Point>;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}
class Box extends Shape implements Interval {
constructor(xmin?: number, ymin?: number, xmax?: number, ymax?: number);
//members
xmin: number;
ymin: number;
xmax: number;
ymax: number;
// getters
readonly center: Point;
readonly high: Point;
readonly low: Point;
readonly max: Box;
readonly width: number;
readonly height: number;
// public methods
clone(): Box;
not_intersect(box: Box): boolean;
intersect(box: Box): boolean;
contains(shape: AnyShape): boolean;
distanceTo(shape: AnyShape): [number, Point];
merge(box: Box): Box;
less_than(box: Box): boolean;
equal_to(box: Box): boolean;
set(xmin: number, ymin: number, xmax: number, ymax: number): void;
toPoints() : Array<Point>;
toSegments() : Array<Segment>;
translate(vec: Vector): Box;
translate(x:number, y:number): Box;
rotate(angle: number, center?: Point): never;
scale(scaleX: number, scaleY: number) : Box;
transform(matrix: Matrix): Box;
output(): Box; // required by base type Interval
svg(attrs?: SVGAttributes): string;
comparable_max(arg1: Comparable, arg2: Comparable) : Comparable;
comparable_less_than(arg1: Comparable, arg2: Comparable ) : boolean;
}
class Circle extends Shape {
constructor(pc: Point, r: number);
// members
pc: Point;
r: number;
// getters
readonly box: Box;
readonly center: Point;
// public methods
clone(): Circle;
contains(shape: AnyShape): boolean;
toArc(counterclockwise?: boolean): Arc;
intersect(shape: AnyShape): Array<Point>;
distanceTo(geom: AnyShape | PlanarSet): [number, Segment];
translate(vec: Vector): Circle;
translate(x:number, y:number): Circle;
rotate(angle: number, center?: Point): Circle;
scale(scaleX: number, scaleY: number) : Circle | never;
transform(matrix: Matrix): Circle;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}
class Line extends Shape {
constructor(pt?: Point, norm?: Vector);
constructor(norm: Vector, pt: Point);
constructor(pt1: Point, pt2: Point);
// members
pt: Point;
norm: Vector;
// getters
readonly start: undefined;
readonly end: undefined;
readonly box: Box;
readonly length: number;
readonly slope: number;
readonly standard: [number, number, number];
// public methods
clone(): Line;
parallelTo(line: Line): boolean;
incidentTo(line: Line): boolean;
contains(pt: Point): boolean;
coord(pt: Point): number;
intersect(shape: AnyShape): Point[];
distanceTo(shape: AnyShape): [number, Segment];
split(pt: Point | Point[]): AnyShape[];
sortPoints(points: Point[]): Point[];
translate(vec: Vector): Line;
translate(x:number, y:number): Line;
rotate(angle: number, center?: Point): Line;
scale(scaleX: number, scaleY: number) : Line;
transform(matrix: Matrix): Line;
toJSON() : Object;
svg(box: Box, attrs?: SVGAttributes): string;
}
class Point extends Shape {
constructor(x?: number, y?: number);
constructor(arg?: [number, number]);
// members
x: number;
y: number;
//getters
readonly box: Box;
readonly vertices: [Point];
// public methods
clone(): Point;
equalTo(pt: Point): boolean;
lessThan(pt: Point): boolean;
translate(vec: Vector): Point;
translate(x: number, y: number): Point;
rotate(angle: number, center?: Point): Point;
scale(scaleX: number, scaleY: number) : Point;
transform(matrix: Matrix): Point;
projectionOn(line: Line): Point;
distanceTo(geom: AnyShape | PlanarSet): [number, Segment];
leftTo(line: Line): boolean;
on(shape: Point | AnyShape): boolean;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}
class Ray extends Shape {
// members
pt: Point;
norm: Vector;
// getters
readonly start: Point;
readonly box: Box;
readonly slope: number;
constructor(pt?: Point, norm?: Vector);
// public methods
clone(): Ray;
contains(pt: Point): boolean;
split(pt: Point[]): AnyShape[];
intersect(shape: AnyShape): Point[];
translate(vec: Vector): Ray;
translate(x:number, y:number): Ray;
rotate(angle: number, center?: Point): Ray;
scale(scaleX: number, scaleY: number) : Ray;
transform(matrix: Matrix): Ray;
svg(box: Box, attrs?: SVGAttributes): string;
}
class Segment extends Shape {
constructor(ps?: Point, pe?: Point);
// members
ps: Point;
pe: Point;
// getters
readonly start: Point;
readonly end: Point;
readonly box: Box;
readonly length: number;
readonly slope: number;
readonly vertices: [Point, Point];
// public methods
clone(): Segment;
equalTo(seg: Segment): boolean;
contains(pt: Point): boolean;
intersect(shape: AnyShape): Point[];
distanceTo(shape: AnyShape): [number, Segment];
tangentInStart(): Vector;
tangentInEnd(): Vector;
reverse(): Segment;
split(pt: Point): [Segment|null,Segment|null];
middle(): Point;
pointAtLength(length: number): Point|null;
translate(vec: Vector): Segment;
translate(x:number, y:number): Segment;
rotate(angle: number, center?: Point): Segment;
scale(scaleX: number, scaleY: number) : Segment;
transform(matrix: Matrix): Segment;
isZeroLength(): boolean;
sortPoints(points: Array<Point>) : Array<Point>;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}
class Vector extends Shape {
constructor(x?: number, y?: number);
constructor(ps: Point, pe: Point);
// members
x: number;
y: number;
// getters
readonly length: number;
readonly slope: number;
// public methods
clone(): Vector;
equalTo(v: Vector): boolean;
multiply(scalar: number): Vector;
dot(v: Vector): number;
cross(v: Vector): number;
normalize(): Vector;
rotate(angle: number): Vector;
rotate90CCW(): Vector;
rotate90CW(): Vector;
translate(vec: Vector): Vector;
translate(x:number, y:number): Vector;
rotate(angle: number, center?: Point): Vector;
scale(scaleX: number, scaleY: number) : Vector;
transform(matrix: Matrix): Vector;
invert(): Vector;
add(v: Vector): Vector;
subtract(v: Vector): Vector;
angleTo(v: Vector): number;
projectionOn(v: Vector): Vector;
toJSON() : Object;
}
class Matrix {
constructor(a?: number, b?: number, c?: number, d?: number, tx?: number, ty?: number);
// members
a: number;
b: number;
c: number;
d: number;
tx: number;
ty: number;
// public methods
clone(): Matrix;
equalTo(matrix: Matrix): boolean;
multiply(matrix: Matrix): Matrix;
rotate(angle: number, centerX?: number, centerY?: number): Matrix;
scale(sx: number, sy: number): Matrix;
transform(vector: [number,number]): [number, number];
translate(tx: number, ty: number): Matrix;
translate(vector: Vector) : Matrix;
}
type PlanarSetEntry = AnyShape | {key: Box, value: AnyShape}
// @ts-ignore (Set)
class PlanarSet extends Set {
// @ts-ignore (Set)
constructor(shapes?: PlanarSetEntry[] | Set<PlanarSetEntry>);
// members
index: IntervalTree;
// public methods
add(element: PlanarSetEntry): this;
delete(element: PlanarSetEntry): boolean;
clear() : void;
hit(pt: Point): AnyShape[];
search(box: Box): AnyShape[];
svg(): string;
}
const INSIDE = 1;
const OUTSIDE = 0;
const BOUNDARY = 2;
enum EdgeRelationType {INSIDE, OUTSIDE, BOUNDARY}
const OVERLAP_SAME = 1;
const OVERLAP_OPPOSITE = 2;
enum EdgeOverlappingType {OVERLAP_SAME, OVERLAP_OPPOSITE}
// Base class Edge for PolygonEdge and MultilineEdge
class Edge {
// members
shape: any
constructor(shape: any);
face: Face;
next: Edge;
prev: Edge;
bvStart: EdgeRelationType;
bvEnd: EdgeRelationType;
bv: EdgeRelationType;
overlap: EdgeOverlappingType;
arc_length: number;
// getters
readonly start: Point;
readonly end: Point;
readonly length: number;
readonly box: Box;
readonly isSegment: boolean;
readonly isArc: boolean;
readonly isLine: boolean;
readonly isRay: boolean
// public methods
contains(pt: Point): boolean;
middle(): Point;
pointAtLength(length: number): Point|null;
setInclusion(polygon: Polygon): EdgeRelationType;
setOverlap(edge: Edge) : EdgeOverlappingType;
}
class PolygonEdge extends Edge {
shape: Segment | Arc;
constructor(shape: Segment | Arc);
}
class Face extends CircularLinkedList {
// constructor is not documented and should not be called implicitly
// members
first: PolygonEdge;
last: PolygonEdge;
// getters
readonly box: Box;
readonly size: number;
readonly length: number;
readonly perimeter: number;
readonly edges: PolygonEdge[];
// public methods
append(edge: PolygonEdge): Face;
insert(element: PolygonEdge): Face;
remove(element: PolygonEdge): Face;
reverse(): void;
setArcLength(): void;
area(): number;
signedArea(): number;
orientation(): Flatten.ORIENTATION.PolygonOrientationType;
isSimple(edges: PolygonEdge[]): boolean;
findEdgeByPoint(pt: Point): PolygonEdge | undefined;
pointAtLength(length: number): Point|null;
toPolygon(): Polygon;
svg(attrs?: SVGAttributes, pathDefined? : boolean): string;
}
type NumericPair = [number,number];
type ConstructorEdgeShape = Point | Segment | Arc ;
type LoopOfShapes = Array<ConstructorEdgeShape | NumericPair>;
type MultiLoopOfShapes = Array<LoopOfShapes | Circle | Box>;
class Polygon {
constructor(args?: LoopOfShapes | Circle | Box | MultiLoopOfShapes);
// members
edges: PlanarSet;
faces: PlanarSet;
// getters
readonly box: Box;
readonly vertices: Point[];
// public methods
clone(): Polygon;
isEmpty(): boolean;
isValid(): boolean;
area(): number;
addFace(args: Array<Point> | Array<Segment | Arc> | Circle | Box): Face;
addFace(edge_from: Edge, edge_to: Edge): Face;
deleteFace(face: Face): boolean;
recreateFaces(): void;
removeChain(face: Face, edgeFrom: PolygonEdge, edgeTo: PolygonEdge): void;
addVertex(pt: Point, edge: PolygonEdge): PolygonEdge;
removeEndVertex(edge: Edge): void;
cut(multiline: Multiline): Polygon[];
cutWithLine(line: Line): Polygon;
findEdgeByPoint(pt: Point): PolygonEdge;
splitToIslands() : Polygon[];
reverse(): Polygon;
contains(shape: AnyShape): boolean;
distanceTo(shape: AnyShape): [number, Segment];
intersect(shape: AnyShape): Point[];
rotate(angle?: number, center?: Point): Polygon;
scale(sx: number, sy: number): Polygon;
transform(matrix?: Matrix): Polygon;
translate(vec: Vector): Polygon;
toJSON() : Object;
toArray() : Polygon[];
svg(attrs?: SVGAttributes): string;
}
type MultilineEdgeShape = Segment | Arc | Ray | Line;
type MultilineShapes = Array<MultilineEdgeShape> | [Line]
class MultilineEdge extends Edge {
shape: MultilineEdgeShape; // there may be only one line edge and only terminal ray edges
constructor(shape: MultilineEdgeShape);
}
class Multiline extends LinkedList {
constructor(args?: MultilineShapes);
// getters
get edges() : MultilineEdge[];
get vertices(): Point[];
get box(): Box;
get length(): number;
clone(): Multiline;
addVertex(pt: Point, edge: MultilineEdge): MultilineEdge;
split(ip: Point[]) : Multiline;
pointAtLength(length: number): Point|null;
findEdgeByPoint(pt: Point): MultilineEdge | undefined;
contains(shape: AnyShape): boolean;
distanceTo(shape: AnyShape): [number, Segment];
intersect(shape: AnyShape): Point[];
rotate(angle?: number, center?: Point): Multiline;
transform(matrix?: Matrix): Multiline;
translate(vec: Vector): Multiline;
toShapes(): MultilineShapes;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}
class Inversion {
circle: Circle; // inversion circle
constructor(circle: Circle);
get inversion_circle() : Circle;
inverse(Point: Point) : Point;
inverse(Line: Line) : Line | Circle;
inverse(Circle: Circle) : Line | Circle;
}
class Errors {
readonly ILLEGAL_PARAMETERS: ReferenceError;
readonly ZERO_DIVISION: Error;
readonly UNRESOLVED_BOUNDARY_CONFLICT: Error;
readonly INFINITE_LOOP: Error;
readonly CANNOT_COMPLETE_BOOLEAN_OPERATION: Error;
readonly CANNOT_INVOKE_ABSTRACT_METHOD: Error;
readonly OPERATION_IS_NOT_SUPPORTED: Error;
}
type AnyShape = Point | Vector | Line | Ray | Circle | Box | Segment | Arc | Polygon | Multiline;
function point(x?: number, y?: number): Point;
function point(arr?: [number, number]): Point;
function circle(pc: Point, r: number) : Circle;
function line(pt?: Point, norm?: Vector) : Line;
function line(norm?: Vector, pt?: Point) : Line;
function line(pt1?: Point, pt2?: Point) : Line;
function segment(ps?: Point, pe?: Point) : Segment;
function segment(arr: [number, number, number, number]) : Segment;
function segment(psx: number, psy: number, pex: number, pey: number) : Segment;
function arc(pc?: Point, r?: number, startAngle?: number, endAngle?: number, counterClockwise?: boolean) : Arc;
function vector(x?: number, y?: number) : Vector;
function vector(arr: [number, number]) : Vector;
function vector(p1: Point, p2: Point) : Vector;
function ray(pt?: Point) : Ray;
function ray(x: number, y: number): Ray;
function matrix(a: number, b: number, c: number, d: number, tx: number, ty: number) : Matrix;
function isWktString(wkt: string): boolean;
function parseWKT(wkt: string): Point | Point[] | Multiline | Multiline[] | Polygon | null ;
}
declare namespace Flatten.ORIENTATION {
const CCW: -1;
const CW: 1;
const NOT_ORIENTABLE: 0;
enum PolygonOrientationType {CCW, CW, NOT_ORIENTABLE}
}
declare namespace Flatten.Utils {
function getTolerance() : number;
function setTolerance(tolerance: number): void;
function EQ(x: number, y: number) : boolean;
function EQ_0(x: number) : boolean;
function GT(x: number, y: number) : boolean;
function GE(x: number, y: number) : boolean;
function LT(x: number, y: number) : boolean;
function LE(x: number, y: number) : boolean;
}
declare namespace Flatten.BooleanOperations {
function unify(polygon1: Polygon, polygon2: Polygon): Polygon;
function subtract(polygon1: Polygon, polygon2: Polygon): Polygon;
function intersect(polygon1: Polygon, polygon2: Polygon): Polygon;
function innerClip(polygon1: Polygon, polygon2: Polygon): [AnyShape[], AnyShape[]];
function outerClip(polygon1: Polygon, polygon2: Polygon): AnyShape[];
function calculateIntersections(polygon1: Polygon, polygon2: Polygon): [Point[],Point[]];
}
declare namespace Flatten.Relations {
function relate(shape1: AnyShape, shape2: AnyShape): DE9IM;
function equal(shape1: AnyShape, shape2: AnyShape): boolean;
function intersect(shape1: AnyShape, shape2: AnyShape): boolean;
function touch(shape1: AnyShape, shape2: AnyShape): boolean;
function disjoint(shape1: AnyShape, shape2: AnyShape): boolean;
function inside(shape1: AnyShape, shape2: AnyShape): boolean;
function covered(shape1: AnyShape, shape2: AnyShape): boolean;
function cover(shape1: AnyShape, shape2: AnyShape): boolean;
}
export = Flatten;
export as namespace Flatten;