Merge pull request #7294 from danmarshall/master

MakerJs 0.6.1
This commit is contained in:
Masahiro Wakame
2015-12-23 17:51:43 +09:00
2 changed files with 136 additions and 58 deletions

View File

@@ -49,8 +49,8 @@ function test() {
function testKit() {
makerjs.kit.construct(null, null);
makerjs.kit.getParameterValues(null);
(<MakerJs.kit.IMetaParameter>{}).max;
(<MakerJs.kit.IKit>{}).metaParameters;
(<MakerJs.IMetaParameter>{}).max;
(<MakerJs.IKit>{}).metaParameters;
}
function testMeasure() {
@@ -66,11 +66,14 @@ function test() {
}
function testModel(){
makerjs.model.combine(model, model, true, false, true, false);
makerjs.model.breakPathsAtIntersections(model, { paths:{ } });
var opts: MakerJs.ICombineOptions = { trimDeadEnds: true, pointMatchingDistance: 2 };
makerjs.model.combine(model, model, true, false, true, false, opts);
makerjs.model.convertUnits(model, makerjs.unitType.Centimeter);
makerjs.model.countChildModels(model);
makerjs.model.detachLoop(model);
makerjs.model.findLoops(model);
makerjs.model.getSimilarModelId(model, 'foo');
makerjs.model.getSimilarPathId(model, 'foo');
makerjs.model.isPathInsideModel(paths.line, model);
makerjs.model.mirror(model, false, true);
@@ -89,19 +92,20 @@ function test() {
new makerjs.models.ConnectTheDots(true, [ [0,0], [1,1] ]),
new makerjs.models.Dome(5, 7),
new makerjs.models.Oval(7, 7),
new makerjs.models.OvalArc(6, 4, 2, 12),
new makerjs.models.OvalArc(6, 4, 2, 12, true),
new makerjs.models.Polygon(7, 5),
new makerjs.models.Rectangle(8, 9),
new makerjs.models.Ring(7, 7),
new makerjs.models.RoundRectangle(2, 2, 0),
new makerjs.models.SCurve(5, .9),
new makerjs.models.Slot([0, 0], [1, 1], 7),
new makerjs.models.Square(8),
new makerjs.models.Star(5, 10, 5)
];
}
function testPath() {
makerjs.path.areEqual(paths.line, paths.circle);
makerjs.path.areEqual(paths.line, paths.circle, 4);
makerjs.path.breakAtPoint(paths.arc, [0,0]).type;
makerjs.path.dogbone(paths.line, paths.line, 7);
makerjs.path.fillet(paths.arc, paths.line, 4);
@@ -140,6 +144,7 @@ function test() {
makerjs.point.add(p1, p2);
makerjs.point.areEqual(p1, p2);
makerjs.point.areEqualRounded(p1, p2);
makerjs.point.average(p1, p2);
makerjs.point.clone(p1);
makerjs.point.closest([0,0], [p1, p2]);
makerjs.point.fromAngleOnCircle(22, paths.circle);

179
maker.js/makerjs.d.ts vendored
View File

@@ -252,9 +252,22 @@ declare module MakerJs {
*/
interface IPointMatchOptions {
/**
* Optional exemplar of number of decimal places.
* Max distance to consider two points as the same.
*/
accuracy?: number;
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;
}
/**
* Options to pass to model.findLoops.
@@ -343,6 +356,63 @@ declare module MakerJs {
* 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;
}
/**
* Path and its reference id within a model
*/
interface IRefPathInModel extends IRefPathIdInModel {
pathContext: IPath;
}
/**
* 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[];
}
}
declare module MakerJs.angle {
/**
@@ -352,7 +422,7 @@ declare module MakerJs.angle {
* @param b Second angle.
* @returns true if angles are the same, false if they are not
*/
function areEqual(angle1: number, angle2: number): boolean;
function areEqual(angle1: number, angle2: number, accuracy?: number): boolean;
/**
* Ensures an angle is not greater than 360
*
@@ -439,7 +509,7 @@ declare module MakerJs.point {
* @param b Second point.
* @returns true if points are the same, false if they are not
*/
function areEqual(a: IPoint, b: IPoint): boolean;
function areEqual(a: IPoint, b: IPoint, withinDistance?: number): boolean;
/**
* Find out if two points are equal after rounding.
*
@@ -449,6 +519,14 @@ declare module MakerJs.point {
* @returns true if points are the same, false if they are not
*/
function areEqualRounded(a: IPoint, b: IPoint, accuracy?: number): boolean;
/**
* Get the average of two points.
*
* @param a First point.
* @param b Second point.
* @returns New point object which is the average of a and b.
*/
function average(a: IPoint, b: IPoint): IPoint;
/**
* Clone a point into a new point.
*
@@ -567,7 +645,7 @@ declare module MakerJs.path {
* @param b Second path.
* @returns true if paths are the same, false if they are not
*/
function areEqual(path1: IPath, path2: IPath): boolean;
function areEqual(path1: IPath, path2: IPath, withinPointDistance?: number): boolean;
/**
* Create a clone of a path, mirrored on either or both x and y axes.
*
@@ -698,11 +776,18 @@ declare module MakerJs.model {
* @returns Number of child models.
*/
function countChildModels(modelContext: IModel): number;
/**
* Get an unused id in the models map with the same prefix.
*
* @param modelContext The model containing the models map.
* @param modelId The id to use directly (if unused), or as a prefix.
*/
function getSimilarModelId(modelContext: IModel, modelId: string): string;
/**
* Get an unused id in the paths map with the same prefix.
*
* @param modelContext The model containing the paths map.
* @param pathId The pathId to use directly (if unused), or as a prefix.
* @param pathId The id to use directly (if unused), or as a prefix.
*/
function getSimilarPathId(modelContext: IModel, pathId: string): string;
/**
@@ -782,7 +867,14 @@ declare module MakerJs.model {
*/
function isPathInsideModel(pathContext: IPath, modelContext: IModel, farPoint?: IPoint): boolean;
/**
* Combine 2 models. The models should be originated.
* Break a model's paths everywhere they intersect with another path.
*
* @param modelToBreak The model containing paths to be broken.
* @param modelToIntersect Optional model containing paths to look for intersection, or else the modelToBreak will be used.
*/
function breakPathsAtIntersections(modelToBreak: IModel, modelToIntersect?: IModel): void;
/**
* Combine 2 models. The models should be originated, and every path within each model should be part of a loop.
*
* @param modelA First model to combine.
* @param modelB Second model to combine.
@@ -793,7 +885,7 @@ declare module MakerJs.model {
* @param keepDuplicates Flag to include paths which are duplicate in both models.
* @param farPoint Optional point of reference which is outside the bounds of both models.
*/
function combine(modelA: IModel, modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, keepDuplicates?: boolean, farPoint?: IPoint): void;
function combine(modelA: IModel, modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, options?: ICombineOptions): void;
}
declare module MakerJs.units {
/**
@@ -1003,50 +1095,6 @@ declare module MakerJs.path {
function fillet(path1: IPath, path2: IPath, filletRadius: number, options?: IPointMatchOptions): IPathArc;
}
declare module MakerJs.kit {
/**
* 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[];
}
/**
* Helper function to use the JavaScript "apply" function in conjunction with the "new" keyword.
*
@@ -1064,6 +1112,23 @@ declare module MakerJs.kit {
function getParameterValues(ctor: IKit): any[];
}
declare module MakerJs.model {
/**
* @private
*/
interface IPointMappedItem<T> {
averagePoint: IPoint;
item: T;
}
/**
* @private
*/
class PointMap<T> {
matchingDistance: number;
list: IPointMappedItem<T>[];
constructor(matchingDistance?: number);
add(pointToAdd: IPoint, item: T): void;
find(pointToFind: IPoint, saveAverage: boolean): T;
}
/**
* Find paths that have common endpoints and form loops.
*
@@ -1078,6 +1143,7 @@ declare module MakerJs.model {
* @param loopToDetach The model to search for loops.
*/
function detachLoop(loopToDetach: IModel): void;
function removeDeadEnds(modelContext: IModel, pointMatchingDistance?: number): void;
}
declare module MakerJs.exporter {
/**
@@ -1247,7 +1313,7 @@ declare module MakerJs.models {
declare module MakerJs.models {
class OvalArc implements IModel {
paths: IPathMap;
constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number);
constructor(startAngle: number, endAngle: number, sweepRadius: number, slotRadius: number, selfIntersect?: boolean);
}
}
declare module MakerJs.models {
@@ -1267,6 +1333,13 @@ declare module MakerJs.models {
constructor(width: number, height: number);
}
}
declare module MakerJs.models {
class Slot implements IModel {
paths: IPathMap;
origin: IPoint;
constructor(origin: IPoint, endPoint: IPoint, radius: number);
}
}
declare module MakerJs.models {
class Square extends Rectangle {
constructor(side: number);