Skip to content

Commit b287a94

Browse files
committed
makerjs 0.6.1
1 parent 208be81 commit b287a94

File tree

2 files changed

+134
-56
lines changed

2 files changed

+134
-56
lines changed

maker.js/makerjs-tests.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ function test() {
6666
}
6767

6868
function testModel(){
69-
makerjs.model.combine(model, model, true, false, true, false);
69+
makerjs.model.breakPathsAtIntersections(model, { paths:{ } });
70+
var opts: MakerJs.ICombineOptions = { trimDeadEnds: true, pointMatchingDistance: 2 };
71+
makerjs.model.combine(model, model, true, false, true, false, opts);
7072
makerjs.model.convertUnits(model, makerjs.unitType.Centimeter);
7173
makerjs.model.countChildModels(model);
7274
makerjs.model.detachLoop(model);
7375
makerjs.model.findLoops(model);
76+
makerjs.model.getSimilarModelId(model, 'foo');
7477
makerjs.model.getSimilarPathId(model, 'foo');
7578
makerjs.model.isPathInsideModel(paths.line, model);
7679
makerjs.model.mirror(model, false, true);
@@ -89,19 +92,20 @@ function test() {
8992
new makerjs.models.ConnectTheDots(true, [ [0,0], [1,1] ]),
9093
new makerjs.models.Dome(5, 7),
9194
new makerjs.models.Oval(7, 7),
92-
new makerjs.models.OvalArc(6, 4, 2, 12),
95+
new makerjs.models.OvalArc(6, 4, 2, 12, true),
9396
new makerjs.models.Polygon(7, 5),
9497
new makerjs.models.Rectangle(8, 9),
9598
new makerjs.models.Ring(7, 7),
9699
new makerjs.models.RoundRectangle(2, 2, 0),
97100
new makerjs.models.SCurve(5, .9),
101+
new makerjs.models.Slot([0, 0], [1, 1], 7),
98102
new makerjs.models.Square(8),
99103
new makerjs.models.Star(5, 10, 5)
100104
];
101105
}
102106

103107
function testPath() {
104-
makerjs.path.areEqual(paths.line, paths.circle);
108+
makerjs.path.areEqual(paths.line, paths.circle, 4);
105109
makerjs.path.breakAtPoint(paths.arc, [0,0]).type;
106110
makerjs.path.dogbone(paths.line, paths.line, 7);
107111
makerjs.path.fillet(paths.arc, paths.line, 4);
@@ -140,6 +144,7 @@ function test() {
140144
makerjs.point.add(p1, p2);
141145
makerjs.point.areEqual(p1, p2);
142146
makerjs.point.areEqualRounded(p1, p2);
147+
makerjs.point.average(p1, p2);
143148
makerjs.point.clone(p1);
144149
makerjs.point.closest([0,0], [p1, p2]);
145150
makerjs.point.fromAngleOnCircle(22, paths.circle);

maker.js/makerjs.d.ts

Lines changed: 126 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,22 @@ declare module MakerJs {
252252
*/
253253
interface IPointMatchOptions {
254254
/**
255-
* Optional exemplar of number of decimal places.
255+
* Max distance to consider two points as the same.
256256
*/
257-
accuracy?: number;
257+
pointMatchingDistance?: number;
258+
}
259+
/**
260+
* Options to pass to model.combine.
261+
*/
262+
interface ICombineOptions extends IPointMatchOptions {
263+
/**
264+
* Flag to remove paths which are not part of a loop.
265+
*/
266+
trimDeadEnds?: boolean;
267+
/**
268+
* Point which is known to be outside of the model.
269+
*/
270+
farPoint?: IPoint;
258271
}
259272
/**
260273
* Options to pass to model.findLoops.
@@ -343,6 +356,63 @@ declare module MakerJs {
343356
* Test to see if an object implements the required properties of a model.
344357
*/
345358
function isModel(item: any): boolean;
359+
/**
360+
* Reference to a path id within a model.
361+
*/
362+
interface IRefPathIdInModel {
363+
modelContext: IModel;
364+
pathId: string;
365+
}
366+
/**
367+
* Path and its reference id within a model
368+
*/
369+
interface IRefPathInModel extends IRefPathIdInModel {
370+
pathContext: IPath;
371+
}
372+
/**
373+
* Describes a parameter and its limits.
374+
*/
375+
interface IMetaParameter {
376+
/**
377+
* Display text of the parameter.
378+
*/
379+
title: string;
380+
/**
381+
* Type of the parameter. Currently supports "range".
382+
*/
383+
type: string;
384+
/**
385+
* Optional minimum value of the range.
386+
*/
387+
min?: number;
388+
/**
389+
* Optional maximum value of the range.
390+
*/
391+
max?: number;
392+
/**
393+
* Optional step value between min and max.
394+
*/
395+
step?: number;
396+
/**
397+
* Initial sample value for this parameter.
398+
*/
399+
value: any;
400+
}
401+
/**
402+
* 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.
403+
*/
404+
interface IKit {
405+
/**
406+
* The constructor. The kit must be "new-able" and it must produce an IModel.
407+
* It can have any number of any type of parameters.
408+
*/
409+
new (...args: any[]): IModel;
410+
/**
411+
* Attached to the constructor is a property named metaParameters which is an array of IMetaParameter objects.
412+
* Each element of the array corresponds to a parameter of the constructor, in order.
413+
*/
414+
metaParameters?: IMetaParameter[];
415+
}
346416
}
347417
declare module MakerJs.angle {
348418
/**
@@ -352,7 +422,7 @@ declare module MakerJs.angle {
352422
* @param b Second angle.
353423
* @returns true if angles are the same, false if they are not
354424
*/
355-
function areEqual(angle1: number, angle2: number): boolean;
425+
function areEqual(angle1: number, angle2: number, accuracy?: number): boolean;
356426
/**
357427
* Ensures an angle is not greater than 360
358428
*
@@ -439,7 +509,7 @@ declare module MakerJs.point {
439509
* @param b Second point.
440510
* @returns true if points are the same, false if they are not
441511
*/
442-
function areEqual(a: IPoint, b: IPoint): boolean;
512+
function areEqual(a: IPoint, b: IPoint, withinDistance?: number): boolean;
443513
/**
444514
* Find out if two points are equal after rounding.
445515
*
@@ -449,6 +519,14 @@ declare module MakerJs.point {
449519
* @returns true if points are the same, false if they are not
450520
*/
451521
function areEqualRounded(a: IPoint, b: IPoint, accuracy?: number): boolean;
522+
/**
523+
* Get the average of two points.
524+
*
525+
* @param a First point.
526+
* @param b Second point.
527+
* @returns New point object which is the average of a and b.
528+
*/
529+
function average(a: IPoint, b: IPoint): IPoint;
452530
/**
453531
* Clone a point into a new point.
454532
*
@@ -567,7 +645,7 @@ declare module MakerJs.path {
567645
* @param b Second path.
568646
* @returns true if paths are the same, false if they are not
569647
*/
570-
function areEqual(path1: IPath, path2: IPath): boolean;
648+
function areEqual(path1: IPath, path2: IPath, withinPointDistance?: number): boolean;
571649
/**
572650
* Create a clone of a path, mirrored on either or both x and y axes.
573651
*
@@ -698,11 +776,18 @@ declare module MakerJs.model {
698776
* @returns Number of child models.
699777
*/
700778
function countChildModels(modelContext: IModel): number;
779+
/**
780+
* Get an unused id in the models map with the same prefix.
781+
*
782+
* @param modelContext The model containing the models map.
783+
* @param modelId The id to use directly (if unused), or as a prefix.
784+
*/
785+
function getSimilarModelId(modelContext: IModel, modelId: string): string;
701786
/**
702787
* Get an unused id in the paths map with the same prefix.
703788
*
704789
* @param modelContext The model containing the paths map.
705-
* @param pathId The pathId to use directly (if unused), or as a prefix.
790+
* @param pathId The id to use directly (if unused), or as a prefix.
706791
*/
707792
function getSimilarPathId(modelContext: IModel, pathId: string): string;
708793
/**
@@ -782,7 +867,14 @@ declare module MakerJs.model {
782867
*/
783868
function isPathInsideModel(pathContext: IPath, modelContext: IModel, farPoint?: IPoint): boolean;
784869
/**
785-
* Combine 2 models. The models should be originated.
870+
* Break a model's paths everywhere they intersect with another path.
871+
*
872+
* @param modelToBreak The model containing paths to be broken.
873+
* @param modelToIntersect Optional model containing paths to look for intersection, or else the modelToBreak will be used.
874+
*/
875+
function breakPathsAtIntersections(modelToBreak: IModel, modelToIntersect?: IModel): void;
876+
/**
877+
* Combine 2 models. The models should be originated, and every path within each model should be part of a loop.
786878
*
787879
* @param modelA First model to combine.
788880
* @param modelB Second model to combine.
@@ -793,7 +885,7 @@ declare module MakerJs.model {
793885
* @param keepDuplicates Flag to include paths which are duplicate in both models.
794886
* @param farPoint Optional point of reference which is outside the bounds of both models.
795887
*/
796-
function combine(modelA: IModel, modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, keepDuplicates?: boolean, farPoint?: IPoint): void;
888+
function combine(modelA: IModel, modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, options?: ICombineOptions): void;
797889
}
798890
declare module MakerJs.units {
799891
/**
@@ -1003,50 +1095,6 @@ declare module MakerJs.path {
10031095
function fillet(path1: IPath, path2: IPath, filletRadius: number, options?: IPointMatchOptions): IPathArc;
10041096
}
10051097
declare module MakerJs.kit {
1006-
/**
1007-
* Describes a parameter and its limits.
1008-
*/
1009-
interface IMetaParameter {
1010-
/**
1011-
* Display text of the parameter.
1012-
*/
1013-
title: string;
1014-
/**
1015-
* Type of the parameter. Currently supports "range".
1016-
*/
1017-
type: string;
1018-
/**
1019-
* Optional minimum value of the range.
1020-
*/
1021-
min?: number;
1022-
/**
1023-
* Optional maximum value of the range.
1024-
*/
1025-
max?: number;
1026-
/**
1027-
* Optional step value between min and max.
1028-
*/
1029-
step?: number;
1030-
/**
1031-
* Initial sample value for this parameter.
1032-
*/
1033-
value: any;
1034-
}
1035-
/**
1036-
* 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.
1037-
*/
1038-
interface IKit {
1039-
/**
1040-
* The constructor. The kit must be "new-able" and it must produce an IModel.
1041-
* It can have any number of any type of parameters.
1042-
*/
1043-
new (...args: any[]): IModel;
1044-
/**
1045-
* Attached to the constructor is a property named metaParameters which is an array of IMetaParameter objects.
1046-
* Each element of the array corresponds to a parameter of the constructor, in order.
1047-
*/
1048-
metaParameters?: IMetaParameter[];
1049-
}
10501098
/**
10511099
* Helper function to use the JavaScript "apply" function in conjunction with the "new" keyword.
10521100
*
@@ -1064,6 +1112,23 @@ declare module MakerJs.kit {
10641112
function getParameterValues(ctor: IKit): any[];
10651113
}
10661114
declare module MakerJs.model {
1115+
/**
1116+
* @private
1117+
*/
1118+
interface IPointMappedItem<T> {
1119+
averagePoint: IPoint;
1120+
item: T;
1121+
}
1122+
/**
1123+
* @private
1124+
*/
1125+
class PointMap<T> {
1126+
matchingDistance: number;
1127+
list: IPointMappedItem<T>[];
1128+
constructor(matchingDistance?: number);
1129+
add(pointToAdd: IPoint, item: T): void;
1130+
find(pointToFind: IPoint, saveAverage: boolean): T;
1131+
}
10671132
/**
10681133
* Find paths that have common endpoints and form loops.
10691134
*
@@ -1078,6 +1143,7 @@ declare module MakerJs.model {
10781143
* @param loopToDetach The model to search for loops.
10791144
*/
10801145
function detachLoop(loopToDetach: IModel): void;
1146+
function removeDeadEnds(modelContext: IModel, pointMatchingDistance?: number): void;
10811147
}
10821148
declare module MakerJs.exporter {
10831149
/**
@@ -1247,7 +1313,7 @@ declare module MakerJs.models {
12471313
declare module MakerJs.models {
12481314
class OvalArc implements IModel {
12491315
paths: IPathMap;
1250-
constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number);
1316+
constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, selfIntersect?: boolean);
12511317
}
12521318
}
12531319
declare module MakerJs.models {
@@ -1267,6 +1333,13 @@ declare module MakerJs.models {
12671333
constructor(width: number, height: number);
12681334
}
12691335
}
1336+
declare module MakerJs.models {
1337+
class Slot implements IModel {
1338+
paths: IPathMap;
1339+
origin: IPoint;
1340+
constructor(origin: IPoint, endPoint: IPoint, radius: number);
1341+
}
1342+
}
12701343
declare module MakerJs.models {
12711344
class Square extends Rectangle {
12721345
constructor(side: number);

0 commit comments

Comments
 (0)