forked from microsoft/maker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
3339 lines (3295 loc) · 126 KB
/
index.d.ts
File metadata and controls
3339 lines (3295 loc) · 126 KB
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Maker.js 0.9.65
// Project: https://github.com/Microsoft/maker.js
// Definitions by: Dan Marshall <https://github.com/danmarshall>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="pdfkit" />
/// <reference types="bezier-js" />
/**
* Schema objects for Maker.js.
*
*/
declare namespace MakerJs {
/**
* An x-y point in a two-dimensional space.
* Implemented as an array with 2 elements. The first element is x, the second element is y.
*
* Examples:
* ```
* var p: IPoint = [0, 0]; //typescript
* var p = [0, 0]; //javascript
* ```
*/
interface IPoint {
[index: number]: number;
}
/**
* A line, curved line or other simple two dimensional shape.
*/
interface IPath {
/**
* The type of the path, e.g. "line", "circle", or "arc". These strings are enumerated in pathType.
*/
"type": string;
/**
* The main point of reference for this path.
*/
origin: IPoint;
/**
* Optional layer of this path.
*/
layer?: string;
}
/**
* A line path.
*
* Examples:
* ```
* var line: IPathLine = { type: 'line', origin: [0, 0], end: [1, 1] }; //typescript
* var line = { type: 'line', origin: [0, 0], end: [1, 1] }; //javascript
* ```
*/
interface IPathLine extends IPath {
/**
* The end point defining the line. The start point is the origin.
*/
end: IPoint;
}
/**
* A circle path.
*
* Examples:
* ```
* var circle: IPathCircle = { type: 'circle', origin: [0, 0], radius: 7 }; //typescript
* var circle = { type: 'circle', origin: [0, 0], radius: 7 }; //javascript
* ```
*/
interface IPathCircle extends IPath {
/**
* The radius of the circle.
*/
radius: number;
}
/**
* An arc path.
*
* Examples:
* ```
* var arc: IPathArc = { type: 'arc', origin: [0, 0], radius: 7, startAngle: 0, endAngle: 45 }; //typescript
* var arc = { type: 'arc', origin: [0, 0], radius: 7, startAngle: 0, endAngle: 45 }; //javascript
* ```
*/
interface IPathArc extends IPathCircle {
/**
* The angle (in degrees) to begin drawing the arc, in polar (counter-clockwise) direction.
*/
startAngle: number;
/**
* The angle (in degrees) to end drawing the arc, in polar (counter-clockwise) direction. May be less than start angle if it past 360.
*/
endAngle: number;
}
/**
* A bezier seed defines the endpoints and control points of a bezier curve.
*/
interface IPathBezierSeed extends IPathLine {
/**
* The bezier control points. One point for quadratic, 2 points for cubic.
*/
controls: IPoint[];
/**
* T values of the parent if this is a child that represents a split.
*/
parentRange?: IBezierRange;
}
/**
* Bezier t values for an arc path segment in a bezier curve.
*/
interface IBezierRange {
/**
* The bezier t-value at the starting point.
*/
startT: number;
/**
* The bezier t-value at the end point.
*/
endT: number;
}
/**
* An arc path segment in a bezier curve.
*/
interface IPathArcInBezierCurve extends IPath {
bezierData: IBezierRange;
}
/**
* Path objects by id.
*/
interface IPathMap {
[id: string]: IPath | IPathArc | IPathCircle | IPathLine;
}
/**
* Model objects by id.
*/
interface IModelMap {
[id: string]: IModel;
}
/**
* A model is a composite object which may contain an array of paths, or an array of models recursively.
*
* Example:
* ```
* var m = {
* paths: {
* "line1": { type: 'line', origin: [0, 0], end: [1, 1] },
* "line2": { type: 'line', origin: [0, 0], end: [-1, -1] }
* }
* };
* ```
*/
interface IModel {
/**
* Optional origin location of this model.
*/
origin?: IPoint;
/**
* A model may want to specify its type, but this value is not employed yet.
*/
"type"?: string;
/**
* Optional array of path objects in this model.
*/
paths?: IPathMap;
/**
* Optional array of models within this model.
*/
models?: IModelMap;
/**
* Optional unit system of this model. See UnitType for possible values.
*/
units?: string;
/**
* An author may wish to add notes to this model instance.
*/
notes?: string;
/**
* Optional layer of this model.
*/
layer?: string;
/**
* Optional exporter options for this model.
*/
exporterOptions?: {
[exporterName: string]: any;
};
}
}
/**
* Root module for Maker.js.
*
* Example: get a reference to Maker.js
* ```
* var makerjs = require('makerjs');
* ```
*
*/
declare namespace MakerJs {
/**
* Version info
*/
var version: string;
/**
* Enumeration of environment types.
*/
var environmentTypes: {
BrowserUI: string;
NodeJs: string;
WebWorker: string;
Unknown: string;
};
/**
* Current execution environment type, should be one of environmentTypes.
*/
var environment: string;
/**
* String-based enumeration of unit types: imperial, metric or otherwise.
* A model may specify the unit system it is using, if any. When importing a model, it may have different units.
* Unit conversion function is makerjs.units.conversionScale().
* Important: If you add to this, you must also add a corresponding conversion ratio in the unit.ts file!
*/
var unitType: {
Centimeter: string;
Foot: string;
Inch: string;
Meter: string;
Millimeter: string;
};
/**
* Numeric rounding
*
* Example: round to 3 decimal places
* ```
* makerjs.round(3.14159, .001); //returns 3.142
* ```
*
* @param n The number to round off.
* @param accuracy Optional exemplar of number of decimal places.
* @returns Rounded number.
*/
function round(n: number, accuracy?: number): number;
/**
* Create a string representation of a route array.
*
* @param route Array of strings which are segments of a route.
* @returns String of the flattened array.
*/
function createRouteKey(route: string[]): string;
/**
* Travel along a route inside of a model to extract a specific node in its tree.
*
* @param modelContext Model to travel within.
* @param route String of a flattened route, or a string array of route segments.
* @returns Model or Path object within the modelContext tree.
*/
function travel(modelContext: IModel, route: string | string[]): {
path: IPath | IModel;
offset: IPoint;
};
/**
* Clone an object.
*
* @param objectToClone The object to clone.
* @returns A new clone of the original object.
*/
function cloneObject<T>(objectToClone: T): T;
/**
* Copy the properties from one object to another object.
*
* Example:
* ```
* makerjs.extendObject({ abc: 123 }, { xyz: 789 }); //returns { abc: 123, xyz: 789 }
* ```
*
* @param target The object to extend. It will receive the new properties.
* @param other An object containing properties to merge in.
* @returns The original object after merging.
*/
function extendObject(target: Object, other: Object): Object;
/**
* Test to see if a variable is a function.
*
* @param value The object to test.
* @returns True if the object is a function type.
*/
function isFunction(value: any): boolean;
/**
* Test to see if a variable is a number.
*
* @param value The object to test.
* @returns True if the object is a number type.
*/
function isNumber(value: any): boolean;
/**
* Test to see if a variable is an object.
*
* @param value The object to test.
* @returns True if the object is an object type.
*/
function isObject(value: any): boolean;
/**
* Test to see if an object implements the required properties of a point.
*
* @param item The item to test.
*/
function isPoint(item: any): boolean;
/**
* A measurement of extents, the high and low points.
*/
interface IMeasure {
/**
* The point containing both the lowest x and y values of the rectangle containing the item being measured.
*/
low: IPoint;
/**
* The point containing both the highest x and y values of the rectangle containing the item being measured.
*/
high: IPoint;
}
/**
* A measurement of extents, with a center point.
*/
interface IMeasureWithCenter extends IMeasure {
/**
* The center point of the rectangle containing the item being measured.
*/
center: IPoint;
/**
* The width of the rectangle containing the item being measured.
*/
width: number;
/**
* The height of the rectangle containing the item being measured.
*/
height: number;
}
/**
* A map of measurements.
*/
interface IMeasureMap {
[key: string]: IMeasure;
}
/**
* A path that was removed in a combine operation.
*/
interface IPathRemoved extends IPath {
/**
* Reason the path was removed.
*/
reason: string;
/**
* Original routekey of the path, to identify where it came from.
*/
routeKey: string;
}
/**
* Options to pass to measure.isPointInsideModel().
*/
interface IMeasurePointInsideOptions {
/**
* Optional point of reference which is outside the bounds of the modelContext.
*/
farPoint?: IPoint;
/**
* Optional atlas of measurements of paths within the model (to prevent intersection calculations).
*/
measureAtlas?: measure.Atlas;
/**
* Output variable which will contain an array of points where the ray intersected the model. The ray is a line from pointToCheck to options.farPoint.
*/
out_intersectionPoints?: IPoint[];
}
/**
* Test to see if an object implements the required properties of a path.
*
* @param item The item to test.
*/
function isPath(item: any): boolean;
/**
* Test to see if an object implements the required properties of a line.
*
* @param item The item to test.
*/
function isPathLine(item: any): boolean;
/**
* Test to see if an object implements the required properties of a circle.
*
* @param item The item to test.
*/
function isPathCircle(item: any): boolean;
/**
* Test to see if an object implements the required properties of an arc.
*
* @param item The item to test.
*/
function isPathArc(item: any): boolean;
/**
* Test to see if an object implements the required properties of an arc in a bezier curve.
*
* @param item The item to test.
*/
function isPathArcInBezierCurve(item: any): boolean;
/**
* String-based enumeration of all paths types.
*
* Examples: use pathType instead of string literal when creating a circle.
* ```
* var circle: IPathCircle = { type: pathType.Circle, origin: [0, 0], radius: 7 }; //typescript
* var circle = { type: pathType.Circle, origin: [0, 0], radius: 7 }; //javascript
* ```
*/
var pathType: {
Line: string;
Circle: string;
Arc: string;
BezierSeed: string;
};
/**
* Slope and y-intercept of a line.
*/
interface ISlope {
/**
* Boolean to see if line has slope or is vertical.
*/
hasSlope: boolean;
/**
* Optional value of non-vertical slope.
*/
slope?: number;
/**
* Line used to calculate this slope.
*/
line: IPathLine;
/**
* Optional value of y when x = 0.
*/
yIntercept?: number;
}
/**
* Options to pass to path.intersection()
*/
interface IPathIntersectionBaseOptions {
/**
* Optional boolean to only return deep intersections, i.e. not on an end point or tangent.
*/
excludeTangents?: boolean;
/**
* Optional output variable which will be set to true if the paths are overlapped.
*/
out_AreOverlapped?: boolean;
}
/**
* Options to pass to path.intersection()
*/
interface IPathIntersectionOptions extends IPathIntersectionBaseOptions {
/**
* Optional boolean to only return deep intersections, i.e. not on an end point or tangent.
*/
path1Offset?: IPoint;
/**
* Optional output variable which will be set to true if the paths are overlapped.
*/
path2Offset?: IPoint;
}
/**
* An intersection of two paths.
*/
interface IPathIntersection {
/**
* Array of points where the two paths intersected. The length of the array may be either 1 or 2 points.
*/
intersectionPoints: IPoint[];
/**
* This Array property will only be defined if the first parameter passed to pathIntersection is either an Arc or a Circle.
* It contains the angles of intersection relative to the first path parameter.
* The length of the array may be either 1 or 2.
*/
path1Angles?: number[];
/**
* This Array property will only be defined if the second parameter passed to pathIntersection is either an Arc or a Circle.
* It contains the angles of intersection relative to the second path parameter.
* The length of the array may be either 1 or 2.
*/
path2Angles?: number[];
}
/**
* Options when matching points
*/
interface IPointMatchOptions {
/**
* Max distance to consider two points as the same.
*/
pointMatchingDistance?: number;
}
/**
* Options to pass to model.combine.
*/
interface ICombineOptions extends IPointMatchOptions {
/**
* Flag to remove paths which are not part of a loop.
*/
trimDeadEnds?: boolean;
/**
* Point which is known to be outside of the model.
*/
farPoint?: IPoint;
/**
* Cached measurements for model A.
*/
measureA?: measure.Atlas;
/**
* Cached measurements for model B.
*/
measureB?: measure.Atlas;
/**
* Output array of 2 models (corresponding to the input models) containing paths that were deleted in the combination.
* Each path will be of type IPathRemoved, which has a .reason property describing why it was removed.
*/
out_deleted?: IModel[];
}
/**
* Options to pass to model.findLoops.
*/
interface IFindLoopsOptions extends IPointMatchOptions {
/**
* Flag to remove looped paths from the original model.
*/
removeFromOriginal?: boolean;
}
/**
* Options to pass to model.simplify()
*/
interface ISimplifyOptions extends IPointMatchOptions {
/**
* Optional
*/
scalarMatchingDistance?: number;
}
/**
* A path that may be indicated to "flow" in either direction between its endpoints.
*/
interface IPathDirectional extends IPath {
/**
* The endpoints of the path.
*/
endPoints: IPoint[];
/**
* Path flows forwards or reverse.
*/
reversed?: boolean;
}
/**
* Callback signature for model.walkPaths().
*/
interface IModelPathCallback {
(modelContext: IModel, pathId: string, pathContext: IPath): void;
}
/**
* Test to see if an object implements the required properties of a model.
*/
function isModel(item: any): boolean;
/**
* Reference to a path id within a model.
*/
interface IRefPathIdInModel {
modelContext: IModel;
pathId: string;
}
/**
* A route to either a path or a model, and the absolute offset of it.
*/
interface IRouteOffset {
layer: string;
offset: IPoint;
route: string[];
routeKey: string;
}
/**
* A path reference in a walk.
*/
interface IWalkPath extends IRefPathIdInModel, IRouteOffset {
pathContext: IPath;
}
/**
* Callback signature for path in model.walk().
*/
interface IWalkPathCallback {
(context: IWalkPath): void;
}
/**
* Callback for returning a boolean from an IWalkPath.
*/
interface IWalkPathBooleanCallback {
(context: IWalkPath): boolean;
}
/**
* A link in a chain, with direction of flow.
*/
interface IChainLink {
/**
* Reference to the path.
*/
walkedPath: IWalkPath;
/**
* Path flows forwards or reverse.
*/
reversed: boolean;
/**
* The endpoints of the path, in absolute coords.
*/
endPoints: IPoint[];
/**
* Length of the path.
*/
pathLength: number;
}
/**
* A chain of paths which connect end to end.
*/
interface IChain {
/**
* The links in this chain.
*/
links: IChainLink[];
/**
* Flag if this chain forms a loop end to end.
*/
endless?: boolean;
/**
* Total length of all paths in the chain.
*/
pathLength: number;
/**
* Chains that are contained within this chain. Populated when chains are found with the 'contain: true' option
*/
contains?: IChain[];
}
/**
* A map of chains by layer.
*/
interface IChainsMap {
[layer: string]: IChain[];
}
/**
* Test to see if an object implements the required properties of a chain.
*
* @param item The item to test.
*/
function isChain(item: any): boolean;
/**
* Callback to model.findChains() with resulting array of chains and unchained paths.
*/
interface IChainCallback {
(chains: IChain[], loose: IWalkPath[], layer: string, ignored?: IWalkPath[]): void;
}
/**
* Options to pass to model.findChains.
*/
interface IFindChainsOptions extends IPointMatchOptions {
/**
* Flag to separate chains by layers.
*/
byLayers?: boolean;
/**
* Flag to not recurse models, look only within current model's immediate paths.
*/
shallow?: boolean;
/**
* Flag to order chains in a heirarchy by their paths being within one another.
*/
contain?: boolean | IContainChainsOptions;
/**
* Flag to flatten BezierCurve arc segments into IPathBezierSeeds.
*/
unifyBeziers?: boolean;
}
/**
* Sub-options to pass to model.findChains.contain option.
*/
interface IContainChainsOptions {
/**
* Flag to alternate winding direction of contained chains.
*/
alernateWindings?: boolean;
}
/**
* Reference to a model within a model.
*/
interface IRefModelInModel {
parentModel: IModel;
childId: string;
childModel: IModel;
}
/**
* A model reference in a walk.
*/
interface IWalkModel extends IRefModelInModel, IRouteOffset {
}
/**
* Callback signature for model.walk().
*/
interface IWalkModelCallback {
(context: IWalkModel): void;
}
/**
* Callback signature for model.walk(), which may return false to halt any further walking.
*/
interface IWalkModelCancellableCallback {
(context: IWalkModel): boolean;
}
/**
* Options to pass to model.walk().
*/
interface IWalkOptions {
/**
* Callback for every path in every model.
*/
onPath?: IWalkPathCallback;
/**
* Callback for every child model in every model. Return false to stop walking down further models.
*/
beforeChildWalk?: IWalkModelCancellableCallback;
/**
* Callback for every child model in every model, after all of its children have been walked.
*/
afterChildWalk?: IWalkModelCallback;
}
/**
* A hexagon which surrounds a model.
*/
interface IBoundingHex extends IModel {
/**
* Radius of the hexagon, which is also the length of a side.
*/
radius: number;
}
/**
* Describes a parameter and its limits.
*/
interface IMetaParameter {
/**
* Display text of the parameter.
*/
title: string;
/**
* Type of the parameter. Currently supports "range".
*/
type: string;
/**
* Optional minimum value of the range.
*/
min?: number;
/**
* Optional maximum value of the range.
*/
max?: number;
/**
* Optional step value between min and max.
*/
step?: number;
/**
* Initial sample value for this parameter.
*/
value: any;
}
/**
* An IKit is a model-producing class with some sample parameters. Think of it as a packaged model with instructions on how to best use it.
*/
interface IKit {
/**
* The constructor. The kit must be "new-able" and it must produce an IModel.
* It can have any number of any type of parameters.
*/
new (...args: any[]): IModel;
/**
* Attached to the constructor is a property named metaParameters which is an array of IMetaParameter objects.
* Each element of the array corresponds to a parameter of the constructor, in order.
*/
metaParameters?: IMetaParameter[];
/**
* Information about this kit, in plain text or markdown format.
*/
notes?: string;
}
/**
* A container that allows a series of functions to be called upon an object.
*/
interface ICascade {
/**
* The initial context object of the cascade.
*/
$initial: any;
/**
* The current final value of the cascade.
*/
$result: any;
/**
* Use the $original as the $result.
*/
$reset: () => this;
}
/**
* Create a container to cascade a series of functions upon a model. This allows JQuery-style method chaining, e.g.:
* ```
* makerjs.$(shape).center().rotate(45).$result
* ```
* The output of each function call becomes the first parameter input to the next function call.
* The returned value of the last function call is available via the `.$result` property.
*
* @param modelContext The initial model to execute functions upon.
* @returns A new cascade container with ICascadeModel methods.
*/
function $(modelContext: IModel): ICascadeModel;
/**
* Create a container to cascade a series of functions upon a path. This allows JQuery-style method chaining, e.g.:
* ```
* makerjs.$(path).center().rotate(90).$result
* ```
* The output of each function call becomes the first parameter input to the next function call.
* The returned value of the last function call is available via the `.$result` property.
*
* @param pathContext The initial path to execute functions upon.
* @returns A new cascade container with ICascadePath methods.
*/
function $(pathContext: IModel): ICascadePath;
/**
* Create a container to cascade a series of functions upon a point. This allows JQuery-style method chaining, e.g.:
* ```
* makerjs.$([1,0]).scale(5).rotate(60).$result
* ```
* The output of each function call becomes the first parameter input to the next function call.
* The returned value of the last function call is available via the `.$result` property.
*
* @param pointContext The initial point to execute functions upon.
* @returns A new cascade container with ICascadePoint methods.
*/
function $(pointContext: IPoint): ICascadePoint;
}
declare module "makerjs" {
export = MakerJs;
}
declare namespace MakerJs {
interface ICascadeModel extends ICascade {
/**
* Add a model as a child. This is basically equivalent to:
```
parentModel.models[childModelId] = childModel;
```
with additional checks to make it safe for cascading.
*
* @param childModel The model to add.
* @param childModelId The id of the child model.
* @param overWrite (default false) Optional flag to overwrite any model referenced by childModelId. Default is false, which will create an id similar to childModelId.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
addModel(childModel: IModel, childModelId: string, overWrite?: boolean): ICascadeModel;
/**
* Add a path as a child. This is basically equivalent to:
```
parentModel.paths[childPathId] = childPath;
```
with additional checks to make it safe for cascading.
*
* @param pathContext The path to add.
* @param pathId The id of the path.
* @param overWrite (default false) Optional flag to overwrite any path referenced by pathId. Default is false, which will create an id similar to pathId.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
addPath(pathContext: IPath, pathId: string, overWrite?: boolean): ICascadeModel;
/**
* Add a model as a child of another model. This is basically equivalent to:
```
parentModel.models[childModelId] = childModel;
```
with additional checks to make it safe for cascading.
*
* @param parentModel The model to add to.
* @param childModelId The id of the child model.
* @param overWrite (default false) Optional flag to overwrite any model referenced by childModelId. Default is false, which will create an id similar to childModelId.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
addTo(parentModel: IModel, childModelId: string, overWrite?: boolean): ICascadeModel;
/**
* Break a model's paths everywhere they intersect with another path.
*
* @param modelToIntersect Optional model containing paths to look for intersection, or else the modelToBreak will be used.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
breakPathsAtIntersections(modelToIntersect?: IModel): ICascadeModel;
/**
* Center a model at [0, 0].
*
* @param centerX (default true) Boolean to center on the x axis. Default is true.
* @param centerY (default true) Boolean to center on the y axis. Default is true.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
center(centerX?: boolean, centerY?: boolean): ICascadeModel;
/**
* Combine 2 models. Each model will be modified accordingly.
*
* @param modelB Second model to combine.
* @param includeAInsideB (default false) Flag to include paths from modelA which are inside of modelB.
* @param includeAOutsideB (default true) Flag to include paths from modelA which are outside of modelB.
* @param includeBInsideA (default false) Flag to include paths from modelB which are inside of modelA.
* @param includeBOutsideA (default true) Flag to include paths from modelB which are outside of modelA.
* @param options Optional ICombineOptions object.
* @returns this cascade container, this.$result will be A new model containing both of the input models as "a" and "b".
*/
combine(modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, options?: ICombineOptions): ICascadeModel;
/**
* Combine 2 models, resulting in a intersection. Each model will be modified accordingly.
*
* @param modelB Second model to combine.
* @returns this cascade container, this.$result will be A new model containing both of the input models as "a" and "b".
*/
combineIntersection(modelB: IModel): ICascadeModel;
/**
* Combine 2 models, resulting in a subtraction of B from A. Each model will be modified accordingly.
*
* @param modelB Second model to combine.
* @returns this cascade container, this.$result will be A new model containing both of the input models as "a" and "b".
*/
combineSubtraction(modelB: IModel): ICascadeModel;
/**
* Combine 2 models, resulting in a union. Each model will be modified accordingly.
*
* @param modelB Second model to combine.
* @returns this cascade container, this.$result will be A new model containing both of the input models as "a" and "b".
*/
combineUnion(modelB: IModel): ICascadeModel;
/**
* Convert a model to match a different unit system.
*
* @param destUnitType The unit system.
* @returns this cascade container, this.$result will be The scaled model (for cascading).
*/
convertUnits(destUnitType: string): ICascadeModel;
/**
* Expand all paths in a model, then combine the resulting expansions.
*
* @param distance Distance to expand.
* @param joints (default 0) Number of points at a joint between paths. Use 0 for round joints, 1 for pointed joints, 2 for beveled joints.
* @param combineOptions (default {}) Optional object containing combine options.
* @returns this cascade container, this.$result will be Model which surrounds the paths of the original model.
*/
expandPaths(distance: number, joints?: number, combineOptions?: ICombineOptions): ICascadeModel;
/**
* Find paths that have common endpoints and form loops.
*
* @param options Optional options object.
* @returns this cascade container, this.$result will be A new model with child models ranked according to their containment within other found loops. The paths of models will be IPathDirectionalWithPrimeContext.
*/
findLoops(options?: IFindLoopsOptions): ICascadeModel;
/**
* Create a clone of a model, mirrored on either or both x and y axes.
*
* @param mirrorX Boolean to mirror on the x axis.
* @param mirrorY Boolean to mirror on the y axis.
* @returns this cascade container, this.$result will be Mirrored model.
*/
mirror(mirrorX: boolean, mirrorY: boolean): ICascadeModel;
/**
* Move a model to an absolute point. Note that this is also accomplished by directly setting the origin property. This function exists for cascading.
*
* @param origin The new position of the model.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
move(origin: IPoint): ICascadeModel;
/**
* Move a model's origin by a relative amount.
*
* @param delta The x & y adjustments as a point object.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
moveRelative(delta: IPoint): ICascadeModel;
/**
* Moves all of a model's children (models and paths, recursively) in reference to a single common origin. Useful when points between children need to connect to each other.
*
* @param origin Optional offset reference point.
* @returns this cascade container, this.$result will be The original model (for cascading).
*/
originate(origin?: IPoint): ICascadeModel;
/**
* Outline a model by a specified distance. Useful for accommodating for kerf.
*
* @param distance Distance to outline.
* @param joints (default 0) Number of points at a joint between paths. Use 0 for round joints, 1 for pointed joints, 2 for beveled joints.
* @param inside (default false) Optional boolean to draw lines inside the model instead of outside.