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 - path Namespace

Index

Functions

addTo

  • addTo(childPath: IPath, parentModel: IModel, pathId: string, overwrite?: boolean): IPath
  • Add a path to a model. This is basically equivalent to:

    parentModel.paths[pathId] = childPath;
    

    with additional checks to make it safe for cascading.

    Parameters

    • childPath: IPath

      The path to add.

    • parentModel: IModel

      The model to add to.

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

    The original path (for cascading).

alterLength

  • alterLength(pathToAlter: IPath, distance: number, useOrigin?: boolean): IPath
  • Alter a path by lengthening or shortening it.

    Parameters

    • pathToAlter: IPath

      Path to alter.

    • distance: number

      Numeric amount of length to add or remove from the path. Use a positive number to lengthen, negative to shorten. When shortening: this function will not alter the path and will return null if the resulting path length is less than or equal to zero.

    • Default value useOrigin: boolean = false

      Optional flag to alter from the origin instead of the end of the path.

    Returns IPath

    The original path (for cascading), or null if the path could not be altered.

breakAtPoint

  • Breaks a path in two. The supplied path will end at the supplied pointOfBreak, a new path is returned which begins at the pointOfBreak and ends at the supplied path's initial end point. For Circle, the original path will be converted in place to an Arc, and null is returned.

    Parameters

    • pathToBreak: IPath

      The path to break.

    • pointOfBreak: IPoint

      The point at which to break the path.

    Returns IPath

    A new path of the same type, when path type is line or arc. Returns null for circle.

center

clone

converge

  • Connect 2 lines at their slope intersection point.

    Parameters

    • lineA: IPathLine

      First line to converge.

    • lineB: IPathLine

      Second line to converge.

    • Optional useOriginA: boolean

      Optional flag to converge the origin point of lineA instead of the end point.

    • Optional useOriginB: boolean

      Optional flag to converge the origin point of lineB instead of the end point.

    Returns IPoint

    point of convergence.

copyProps

distort

  • Distort a path - scale x and y individually.

    Parameters

    • pathToDistort: IPath

      The path to distort.

    • scaleX: number

      The amount of x scaling.

    • scaleY: number

      The amount of y scaling.

    Returns IModel | IPath

    A new IModel (for circles and arcs) or IPath (for lines and bezier seeds).

dogbone

expand

  • expand(pathToExpand: IPath, expansion: number, isolateCaps?: boolean): IModel
  • Expand path by creating a model which surrounds it.

    Parameters

    • pathToExpand: IPath

      Path to expand.

    • expansion: number

      Distance to expand.

    • Optional isolateCaps: boolean

      Optional flag to put the end caps into a separate model named "caps".

    Returns IModel

    Model which surrounds the path.

fillet

  • Adds a round corner to the inside angle between 2 paths. The paths must meet at one point.

    Parameters

    • pathA: IPath

      First path to fillet, which will be modified to fit the fillet.

    • pathB: IPath

      Second path to fillet, which will be modified to fit the fillet.

    • filletRadius: number

      Radius of the fillet.

    • Optional options: IPointMatchOptions

      Optional IPointMatchOptions object to specify pointMatchingDistance.

    Returns IPathArc

    Arc path object of the new fillet.

intersection

layer

mirror

  • mirror(pathToMirror: IPath, mirrorX: boolean, mirrorY: boolean): IPath
  • Create a clone of a path, mirrored on either or both x and y axes.

    Parameters

    • pathToMirror: IPath

      The path to mirror.

    • mirrorX: boolean

      Boolean to mirror on the x axis.

    • mirrorY: boolean

      Boolean to mirror on the y axis.

    Returns IPath

    Mirrored path.

move

moveRelative

moveTemporary

  • moveTemporary(pathsToMove: IPath[], deltas: IPoint[], task: Function): void
  • Move some paths relatively during a task execution, then unmove them.

    Parameters

    • pathsToMove: IPath[]

      The paths to move.

    • deltas: IPoint[]

      The x & y adjustments as a point object array.

    • task: Function

      The function to call while the paths are temporarily moved.

    Returns void

rotate

  • rotate(pathToRotate: IPath, angleInDegrees: number, rotationOrigin?: IPoint): IPath

scale

  • scale(pathToScale: IPath, scaleValue: number): IPath

straighten

  • straighten(arc: IPathArc, bevel?: boolean, prefix?: string, close?: boolean): IModel
  • Represent an arc using straight lines.

    Parameters

    • arc: IPathArc

      Arc to straighten.

    • Optional bevel: boolean

      Optional flag to bevel the angle to prevent it from being too sharp.

    • Optional prefix: string

      Optional string prefix to apply to path ids.

    • Optional close: boolean

      Optional flag to make a closed geometry by connecting the endpoints.

    Returns IModel

    Model of straight lines with same endpoints as the arc.

toKeyPoints

  • toKeyPoints(pathContext: IPath, maxArcFacet?: number): IPoint[]
  • Get key points (a minimal a number of points) along a path.

    Parameters

    • pathContext: IPath

      Path to get points from.

    • Optional maxArcFacet: number

      Optional maximum length between points on an arc or circle.

    Returns IPoint[]

    Array of points which are on the path.

toPoints

  • toPoints(pathContext: IPath, numberOfPoints: number): IPoint[]
  • Get points along a path.

    Parameters

    • pathContext: IPath

      Path to get points from.

    • numberOfPoints: number

      Number of points to divide the path.

    Returns IPoint[]

    Array of points which are on the path spread at a uniform interval.

zero

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