Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.

View project on GitHub Star

Api - model Namespace

Index

Functions

addCaption

  • Add a Caption object to a model.

    Parameters

    • modelContext: IModel

      The model to add to.

    • text: string

      Text to add.

    • Optional leftAnchorPoint: IPoint

      Optional Point on left side middle of text.

    • Optional rightAnchorPoint: IPoint

      Optional Point on right side middle of text.

    Returns IModel

    The original model (for cascading).

addModel

  • addModel(parentModel: IModel, childModel: IModel, childModelId: string, overWrite?: boolean): IModel
  • Add a model as a child. This is basically equivalent to:

    parentModel.models[childModelId] = childModel;

    with additional checks to make it safe for cascading.

    Parameters

    • parentModel: IModel

      The model to add to.

    • childModel: IModel

      The model to add.

    • childModelId: string

      The id of the child model.

    • Default value overWrite: boolean = false

      Optional flag to overwrite any model referenced by childModelId. Default is false, which will create an id similar to childModelId.

    Returns IModel

    The original model (for cascading).

addPath

  • addPath(modelContext: IModel, pathContext: IPath, pathId: string, overWrite?: boolean): IModel
  • Add a path as a child. This is basically equivalent to:

    parentModel.paths[childPathId] = childPath;

    with additional checks to make it safe for cascading.

    Parameters

    • modelContext: IModel

      The model to add to.

    • pathContext: IPath

      The path to add.

    • pathId: string

      The id of the path.

    • Default value overWrite: boolean = false

      Optional flag to overwrite any path referenced by pathId. Default is false, which will create an id similar to pathId.

    Returns IModel

    The original model (for cascading).

addTo

  • addTo(childModel: IModel, parentModel: IModel, childModelId: string, overWrite?: boolean): IModel
  • 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.

    Parameters

    • childModel: IModel

      The model to add.

    • parentModel: IModel

      The model to add to.

    • childModelId: string

      The id of the child model.

    • Default value overWrite: boolean = false

      Optional flag to overwrite any model referenced by childModelId. Default is false, which will create an id similar to childModelId.

    Returns IModel

    The original model (for cascading).

breakPathsAtIntersections

  • DEPRECATED Break a model's paths everywhere they intersect with another path.

    Parameters

    • modelToBreak: IModel

      The model containing paths to be broken.

    • Optional modelToIntersect: IModel

      Optional model containing paths to look for intersection, or else the modelToBreak will be used.

    Returns IModel

    The original model (for cascading).

center

  • center(modelToCenter: IModel, centerX?: boolean, centerY?: boolean): IModel
  • Center a model at [0, 0].

    Parameters

    • modelToCenter: IModel

      The model to center.

    • Default value centerX: boolean = true

      Boolean to center on the x axis. Default is true.

    • Default value centerY: boolean = true

      Boolean to center on the y axis. Default is true.

    Returns IModel

    The original model (for cascading).

clone

combine

  • combine(modelA: IModel, modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, options?: ICombineOptions): IModel
  • Combine 2 models. Each model will be modified accordingly.

    Parameters

    • modelA: IModel

      First model to combine.

    • modelB: IModel

      Second model to combine.

    • Default value includeAInsideB: boolean = false

      Flag to include paths from modelA which are inside of modelB.

    • Default value includeAOutsideB: boolean = true

      Flag to include paths from modelA which are outside of modelB.

    • Default value includeBInsideA: boolean = false

      Flag to include paths from modelB which are inside of modelA.

    • Default value includeBOutsideA: boolean = true

      Flag to include paths from modelB which are outside of modelA.

    • Optional options: ICombineOptions

      Optional ICombineOptions object.

    Returns IModel

    A new model containing both of the input models as "a" and "b".

combineIntersection

  • Combine 2 models, resulting in a intersection. Each model will be modified accordingly.

    Parameters

    • modelA: IModel

      First model to combine.

    • modelB: IModel

      Second model to combine.

    Returns IModel

    A new model containing both of the input models as "a" and "b".

combineSubtraction

  • Combine 2 models, resulting in a subtraction of B from A. Each model will be modified accordingly.

    Parameters

    • modelA: IModel

      First model to combine.

    • modelB: IModel

      Second model to combine.

    Returns IModel

    A new model containing both of the input models as "a" and "b".

combineUnion

  • Combine 2 models, resulting in a union. Each model will be modified accordingly.

    Parameters

    • modelA: IModel

      First model to combine.

    • modelB: IModel

      Second model to combine.

    Returns IModel

    A new model containing both of the input models as "a" and "b".

convertUnits

  • convertUnits(modeltoConvert: IModel, destUnitType: string): IModel

countChildModels

  • countChildModels(modelContext: IModel): number

distort

  • distort(modelToDistort: IModel, scaleX: number, scaleY: number, scaleOrigin?: boolean, bezierAccuracy?: number): IModel
  • Create a distorted copy of a model - scale x and y individually.

    Parameters

    • modelToDistort: IModel

      The model to distort.

    • scaleX: number

      The amount of x scaling.

    • scaleY: number

      The amount of y scaling.

    • Default value scaleOrigin: boolean = false

      Optional boolean to scale the origin point. Typically false for the root model.

    • Optional bezierAccuracy: number

      Optional accuracy of Bezier curves.

    Returns IModel

    New model (for cascading).

expandPaths

  • Expand all paths in a model, then combine the resulting expansions.

    Parameters

    • modelToExpand: IModel

      Model to expand.

    • distance: number

      Distance to expand.

    • Default value joints: number = 0

      Number of points at a joint between paths. Use 0 for round joints, 1 for pointed joints, 2 for beveled joints.

    • Default value combineOptions: ICombineOptions = {}

      Optional object containing combine options.

    Returns IModel

    Model which surrounds the paths of the original model.

findChains

findSingleChain

  • Find a single chain within a model, across all layers. Shorthand of findChains; useful when you know there is only one chain to find in your model.

    Parameters

    • modelContext: IModel

      The model to search for a chain.

    Returns IChain

    A chain object or null if chains were not found.

getAllCaptionsOffset

  • getAllCaptionsOffset(modelContext: IModel): (ICaption & object)[]
  • Gets all Caption objects, in absolute position, in this model and its children.

    Parameters

    • modelContext: IModel

      The model to search for Caption objects.

    Returns (ICaption & object)[]

    Array of Caption objects.

getSimilarModelId

  • getSimilarModelId(modelContext: IModel, modelId: string): string
  • Get an unused id in the models map with the same prefix.

    Parameters

    • modelContext: IModel

      The model containing the models map.

    • modelId: string

      The id to use directly (if unused), or as a prefix.

    Returns string

getSimilarPathId

  • getSimilarPathId(modelContext: IModel, pathId: string): string
  • Get an unused id in the paths map with the same prefix.

    Parameters

    • modelContext: IModel

      The model containing the paths map.

    • pathId: string

      The id to use directly (if unused), or as a prefix.

    Returns string

isPathInsideModel

  • DEPRECATED - use measure.isPointInsideModel instead. Check to see if a path is inside of a model.

    Parameters

    • pathContext: IPath

      The path to check.

    • modelContext: IModel

      The model to check against.

    • Optional pathOffset: IPoint
    • Optional farPoint: IPoint

      Optional point of reference which is outside the bounds of the modelContext.

    • Optional measureAtlas: Atlas

    Returns boolean

    Boolean true if the path is inside of the modelContext.

layer

  • Set the layer of a model. This is equivalent to:

    modelContext.layer = layer;

    Parameters

    • modelContext: IModel

      The model to set the layer.

    • layer: string

      The layer name.

    Returns IModel

    The original model (for cascading).

mirror

  • mirror(modelToMirror: IModel, mirrorX: boolean, mirrorY: boolean): IModel
  • Create a clone of a model, mirrored on either or both x and y axes.

    Parameters

    • modelToMirror: IModel

      The model to mirror.

    • mirrorX: boolean

      Boolean to mirror on the x axis.

    • mirrorY: boolean

      Boolean to mirror on the y axis.

    Returns IModel

    Mirrored model.

move

  • Move a model to an absolute point. Note that this is also accomplished by directly setting the origin property. This function exists for cascading.

    Parameters

    • modelToMove: IModel

      The model to move.

    • origin: IPoint

      The new position of the model.

    Returns IModel

    The original model (for cascading).

moveRelative

originate

  • 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.

    Parameters

    • modelToOriginate: IModel

      The model to originate.

    • Optional origin: IPoint

      Optional offset reference point.

    Returns IModel

    The original model (for cascading).

outline

  • Outline a model by a specified distance. Useful for accommodating for kerf.

    Parameters

    • modelToOutline: IModel

      Model to outline.

    • distance: number

      Distance to outline.

    • Default value joints: number = 0

      Number of points at a joint between paths. Use 0 for round joints, 1 for pointed joints, 2 for beveled joints.

    • Default value inside: boolean = false

      Optional boolean to draw lines inside the model instead of outside.

    • Default value options: ICombineOptions = {}

      Options to send to combine() function.

    Returns IModel

    Model which surrounds the paths outside of the original model.

prefixPathIds

  • prefixPathIds(modelToPrefix: IModel, prefix: string): IModel

removeDeadEnds

  • Remove paths from a model which have endpoints that do not connect to other paths.

    Parameters

    • modelContext: IModel

      The model to search for dead ends.

    • Optional pointMatchingDistance: number

      Optional max distance to consider two points as the same.

    • Optional keep: IWalkPathBooleanCallback

      Optional callback function (which should return a boolean) to decide if a dead end path should be kept instead.

    • Optional trackDeleted: function

      Optional callback function which will log discarded paths and the reason they were discarded.

        • Parameters

          Returns void

    Returns IModel

    The input model (for cascading).

rotate

  • Rotate a model.

    Parameters

    • modelToRotate: IModel

      The model to rotate.

    • angleInDegrees: number

      The amount of rotation, in degrees.

    • Default value rotationOrigin: IPoint = [0, 0]

      The center point of rotation.

    Returns IModel

    The original model (for cascading).

scale

  • scale(modelToScale: IModel, scaleValue: number, scaleOrigin?: boolean): IModel
  • Scale a model.

    Parameters

    • modelToScale: IModel

      The model to scale.

    • scaleValue: number

      The amount of scaling.

    • Default value scaleOrigin: boolean = false

      Optional boolean to scale the origin point. Typically false for the root model.

    Returns IModel

    The original model (for cascading).

simplify

walk

walkPaths

zero

  • zero(modelToZero: IModel, zeroX?: boolean, zeroY?: boolean): IModel
  • Move a model so its bounding box begins at [0, 0].

    Parameters

    • modelToZero: IModel

      The model to zero.

    • Default value zeroX: boolean = true

      Boolean to zero on the x axis. Default is true.

    • Default value zeroY: boolean = true

      Boolean to zero on the y axis. Default is true.

    Returns IModel

    The original model (for cascading).

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc