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 Module

Index

Variables

Private alterMap

alterMap: object

Type declaration

  • [pathType: string]: function
      • (pathValue: IPath, pathLength: number, distance: number, useOrigin: boolean): void
      • Parameters

        • pathValue: IPath
        • pathLength: number
        • distance: number
        • useOrigin: boolean

        Returns void

Private breakPathFunctionMap

breakPathFunctionMap: IBreakPathFunctionMap

Private copyPropsMap

copyPropsMap: object

Type declaration

Private distortMap

distortMap: object

Type declaration

  • [pathType: string]: function

Private filletResultMap

filletResultMap: object

Type declaration

  • [pathType: string]: function

Private guidePathMap

guidePathMap: object

Type declaration

  • [pathType: string]: function
      • Parameters

        • pathContext: IPath
        • filletRadius: number
        • nearPoint: IPoint
        • shardPoint: IPoint
        • isStart: boolean

        Returns IPath

Private map

Private mirrorMap

mirrorMap: object

Type declaration

  • [pathType: string]: function
      • (pathToMirror: IPath, origin: IPoint, mirrorX: boolean, mirrorY: boolean): IPath
      • Parameters

        • pathToMirror: IPath
        • origin: IPoint
        • mirrorX: boolean
        • mirrorY: boolean

        Returns IPath

Private moveMap

moveMap: object

Type declaration

  • [pathType: string]: function

Private moveRelativeMap

moveRelativeMap: object

Type declaration

  • [pathType: string]: function
      • (pathToMove: IPath, delta: IPoint, subtract: boolean): void
      • Parameters

        Returns void

Private numberOfKeyPointsMap

numberOfKeyPointsMap: object

Type declaration

  • [type: string]: function
      • (pathContext: IPath, maxPointDistance?: number): number
      • Parameters

        • pathContext: IPath
        • Optional maxPointDistance: number

        Returns number

Private propertyNamesMap

propertyNamesMap: object

Type declaration

  • [pathType: string]: function
      • (pathToInspect: IPath): string[]
      • Parameters

        Returns string[]

Private rotateMap

rotateMap: object

Type declaration

  • [pathType: string]: function
      • (pathToRotate: IPath, angleInDegrees: number, rotationOrigin: IPoint): void
      • Parameters

        • pathToRotate: IPath
        • angleInDegrees: number
        • rotationOrigin: IPoint

        Returns void

Private scaleMap

scaleMap: object

Type declaration

  • [pathType: string]: function
      • (pathValue: IPath, scaleValue: number): void
      • Parameters

        • pathValue: IPath
        • scaleValue: number

        Returns void

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

  • Center a path at [0, 0].

    Parameters

    • pathToCenter: IPath

      The path to center.

    Returns IPath

    The original path (for cascading).

Private circleToCircle

clone

  • Create a clone of a path. This is faster than cloneObject.

    Parameters

    • pathToClone: IPath

      The path to clone.

    • Optional offset: IPoint

      Optional point to move path a relative distance.

    Returns IPath

    Cloned path.

Private cloneAndBreakPath

  • cloneAndBreakPath(pathToShard: IPath, shardPoint: IPoint): IPath[]

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.

Private copyLayer

copyProps

  • Copy the schema properties of one path to another.

    Parameters

    • srcPath: IPath

      The source path to copy property values from.

    • destPath: IPath

      The destination path to copy property values to.

    Returns IPath

    The source path.

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

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

    Parameters

    • lineA: IPathLine

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

    • lineB: IPathLine

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

    • filletRadius: number
    • Optional options: IPointMatchOptions

    Returns IPathArc

    Arc path object of the new fillet.

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.

Private findCorrespondingAngleIndex

  • findCorrespondingAngleIndex(circleAngles: number[], arcAngle: number): number

Private getAnglesWithinArc

Private getDogboneResult

Private getFilletResult

Private getGuidePath

Private getLineRatio

  • getLineRatio(lines: IPathLine[]): number

Private getMatchingPointProperties

Private getPointProperties

  • getPointProperties(pathToInspect: IPath): IPointProperty[]

intersection

  • Find the point(s) where 2 paths intersect.

    Parameters

    • path1: IPath

      First path to find intersection.

    • path2: IPath

      Second path to find intersection.

    • Default value options: IPathIntersectionOptions = {}

      Optional IPathIntersectionOptions.

    Returns IPathIntersection

    IPathIntersection object, with points(s) of intersection (and angles, when a path is an arc or circle); or null if the paths did not intersect.

layer

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

    pathContext.layer = layer;
    

    Parameters

    • pathContext: IPath

      The path to set the layer.

    • layer: string

      The layer name.

    Returns IPath

    The original path (for cascading).

Private lineToCircle

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

  • Move a path to an absolute point.

    Parameters

    • pathToMove: IPath

      The path to move.

    • origin: IPoint

      The new origin for the path.

    Returns IPath

    The original path (for cascading).

moveRelative

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

    Parameters

    • pathToMove: IPath

      The path to move.

    • delta: IPoint

      The x & y adjustments as a point object.

    • Optional subtract: boolean

      Optional boolean to subtract instead of add.

    Returns IPath

    The original path (for cascading).

Private moveTemp

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

Private pointsFromAnglesOnCircle

  • pointsFromAnglesOnCircle(anglesInDegrees: number[], circle: IPathCircle): IPoint[]

Private populateShardPointsFromReferenceCircle

  • populateShardPointsFromReferenceCircle(filletRadius: number, center: IPoint, properties: IMatchPointProperty[], options: IPointMatchOptions): boolean

rotate

  • rotate(pathToRotate: IPath, angleInDegrees: number, rotationOrigin?: IPoint): IPath
  • Rotate a path.

    Parameters

    • pathToRotate: IPath

      The path to rotate.

    • angleInDegrees: number

      The amount of rotation, in degrees.

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

      The center point of rotation.

    Returns IPath

    The original path (for cascading).

scale

  • scale(pathToScale: IPath, scaleValue: number): IPath
  • Scale a path.

    Parameters

    • pathToScale: IPath

      The path to scale.

    • scaleValue: number

      The amount of scaling.

    Returns IPath

    The original path (for cascading).

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.

Private swapAngles

Private testFilletResult

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

  • Move a path so its bounding box begins at [0, 0].

    Parameters

    • pathToZero: IPath

      The path to zero.

    Returns IPath

    The original path (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