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 Module

Index

Functions

Private addDistortedPath

  • addDistortedPath(parentModel: IModel, pathToDistort: IPath, pathId: string, layer: string, scaleX: number, scaleY: number, bezierAccuracy?: number): void
  • Parameters

    • parentModel: IModel
    • pathToDistort: IPath
    • pathId: string
    • layer: string
    • scaleX: number
    • scaleY: number
    • Optional bezierAccuracy: number

    Returns void

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

Private addOrDeleteSegments

  • addOrDeleteSegments(crossedPath: ICrossedPath, includeInside: boolean, includeOutside: boolean, keepDuplicates: boolean, atlas: Atlas, trackDeleted: ITrackDeleted): void

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

Private breakAllPathsAtIntersections

Private breakAlongForeignPath

  • breakAlongForeignPath(crossedPath: ICrossedPath, overlappedSegments: ICrossedPathSegment[], foreignWalkedPath: IWalkPath): void

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

Private checkForEqualOverlaps

  • checkForEqualOverlaps(crossedPathsA: ICrossedPathSegment[], crossedPathsB: ICrossedPathSegment[], pointMatchingDistance: number): void
  • Parameters

    • crossedPathsA: ICrossedPathSegment[]
    • crossedPathsB: ICrossedPathSegment[]
    • pointMatchingDistance: number

    Returns void

Private checkForOverlaps

  • checkForOverlaps(refPaths: IWalkPath[], isOverlapping: function, overlapUnion: function): void
  • Parameters

    • refPaths: IWalkPath[]
    • isOverlapping: function
        • (pathA: IPath, pathB: IPath, excludeTangents: boolean): boolean
        • Parameters

          • pathA: IPath
          • pathB: IPath
          • excludeTangents: boolean

          Returns boolean

    • overlapUnion: function

    Returns void

clone

  • Clone a model. Alias of makerjs.cloneObject(modelToClone)

    Parameters

    • modelToClone: IModel

      The model to clone.

    Returns IModel

    A clone of the model you passed.

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
  • Convert a model to match a different unit system.

    Parameters

    • modeltoConvert: IModel

      The model to convert.

    • destUnitType: string

      The unit system.

    Returns IModel

    The scaled model (for cascading).

countChildModels

  • countChildModels(modelContext: IModel): number
  • Count the number of child models within a given model.

    Parameters

    • modelContext: IModel

      The model containing other models.

    Returns number

    Number of child models.

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

  • Find paths that have common endpoints and form chains.

    Parameters

    Returns IChain[] | IChainsMap

    An array of chains, or a map (keyed by layer id) of arrays of chains - if options.byLayers is true.

  • Find paths that have common endpoints and form chains.

    Parameters

    Returns IChain[] | IChainsMap

    An array of chains, or a map (keyed by layer id) of arrays of chains - if options.byLayers is true.

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.

Private followLinks

  • followLinks(pointGraph: PointGraph<IChainLink>, chainFound: function, chainNotFound?: function): void

Private getBezierModels

  • getBezierModels(modelContext: IModel): IWalkModel[]

Private getClosedGeometries

Private getContainment

Private getEndlessChains

  • getEndlessChains(modelContext: IModel): IChain[]

Private getNonZeroSegments

  • getNonZeroSegments(pathToSegment: IPath, breakPoint: IPoint): IPath[]

Private getOpposedLink

  • getOpposedLink(linkedPaths: IChainLink[], pathContext: IPath): IChainLink

Private getPointsOnPath

Private getSimilarId

  • getSimilarId(map: object, id: string): string
  • Parameters

    • map: object
      • [id: string]: any
    • id: string

    Returns string

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

Private linkEndpoint

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

  • Move a model's origin by a relative amount.

    Parameters

    • modelToMove: IModel

      The model to move.

    • delta: IPoint

      The x & y adjustments as a point object.

    Returns IModel

    The original model (for cascading).

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
  • Prefix the ids of paths in a model.

    Parameters

    • modelToPrefix: IModel

      The model to prefix.

    • prefix: string

      The prefix to prepend on paths ids.

    Returns IModel

    The original model (for cascading).

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

  • Simplify a model's paths by reducing redundancy: combine multiple overlapping paths into a single path. The model must be originated.

    Parameters

    Returns IModel

    The simplified model (for cascading).

Private swapBezierPathsWithSeeds

  • swapBezierPathsWithSeeds(beziers: IWalkModel[], swap: boolean): void
  • Parameters

    • beziers: IWalkModel[]
    • swap: boolean

    Returns void

walk

  • Recursively walk through all child models and paths for a given model.

    Parameters

    • modelContext: IModel

      The model to walk.

    • options: IWalkOptions

      Object containing callbacks.

    Returns IModel

    The original model (for cascading).

walkPaths

  • DEPRECATED - use model.walk instead. Recursively walk through all paths for a given model.

    Parameters

    Returns void

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