AWT. Path

A Path is a module:AWT.Shape formed by a serie of strokes, represented by
module:AWT.PathStroke objects

Constructor

new Path(strokes)

Path constructor

Parameters:
NameTypeDescription
strokesArray.<module:AWT.PathStroke>

The array of module:AWT.PathStroke objects defining this Path.

Extends

Members

enclosing :module:AWT.Rectangle

The Rectangle enclosing this Path (when drawing, this Rectangle don't include border width!)

enclosingPoints :Array.<module:AWT.Point>

Set of vertexs of a polygon close to the real path of this shape

Type:

pos :module:AWT.Point

The current position of the shape

strokes :Array.<module:AWT.PathStroke>

The strokes forming this Path.

type :string

Shape type id

Type:
  • string

Methods

addStroke(stroke)

Adds a module:AWT.PathStroke to strokes

Parameters:
NameTypeDescription
strokemodule:AWT.PathStroke

calcEnclosingRect() → {module:AWT.Rectangle}

Calculates the polygon and the rectangle that (approximately) encloses this shape

Returns:
Type: 
module:AWT.Rectangle

clip(ctx, fillRuleopt) → {external:CanvasRenderingContext2D}

Creates a clipping region on the specified HTML canvas 2D rendering context

Parameters:
NameTypeAttributesDefaultDescription
ctxexternal:CanvasRenderingContext2D

The rendering context

fillRulestring<optional>
'nonzero'

Can be 'nonzero' (default when not set) or 'evenodd'

Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

contains(_p) → {boolean}

Checks if the provided module:AWT.Point is inside this shape.

Parameters:
NameTypeDescription
_pmodule:AWT.Point

The point to check

Returns:
Type: 
boolean

equals(p) → {boolean}

Checks if two shapes are equivalent.

Parameters:
NameTypeDescription
pmodule:AWT.Shape

The Shape to compare against

Returns:
Type: 
boolean

fill(ctx, dirtyRegionopt) → {external:CanvasRenderingContext2D}

Fills the Shape with the current style in the provided HTML canvas context

Parameters:
NameTypeAttributesDescription
ctxexternal:CanvasRenderingContext2D

The canvas 2D rendering context where to fill this shape.

dirtyRegionmodule:AWT.Rectangle<optional>

The context region to be updated. Used as clipping
region when drawing.

Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

getAttributes() → {object}

Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.

Returns:
  • The resulting object, with minimal attrributes
Type: 
object

getBounds() → {module:AWT.Rectangle}

Gets the enclosing Rectangle of this Shape.

Returns:
Type: 
module:AWT.Rectangle

getShape(rect) → {module:AWT.Shape}

Gets a clone of this shape moved to the pos component of the rectangle and scaled
by its dim value.

Parameters:
NameTypeDescription
rectmodule:AWT.Rectangle

The rectangle to be taken as a base for moving and scaling
this shape.

Returns:
Type: 
module:AWT.Shape

intersects(_r) → {boolean}

Checks if the provided Rectangle r intersects with this shape.

Parameters:
NameTypeDescription
_rmodule:AWT.Rectangle
Returns:
Type: 
boolean

isRect() → {boolean}

Shorthand method for determining if a Shape is an Rectangle

Returns:
Type: 
boolean

moveBy(delta) → {module:AWT.Shape}

Shifts the shape a specified amount in horizontal and vertical directions

Parameters:
NameTypeDescription
deltaPoint | Dimension

The amount to shift the Shape

Returns:
Type: 
module:AWT.Shape

moveTo(newPos) → {module:AWT.Shape}

Moves this shape to a new position

Parameters:
NameTypeDescription
newPosmodule:AWT.Point

The new position of the shape

Returns:
Type: 
module:AWT.Shape

preparePath(ctx) → {external:CanvasRenderingContext2D}

Prepares an HTML canvas 2D rendering context with a path that can be used to stroke a line,
to fill a surface or to define a clipping region.

Parameters:
NameTypeDescription
ctxexternal:CanvasRenderingContext2D
Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

scaleBy(_delta) → {module:AWT.Shape}

Multiplies the dimension of the Shape by the specified delta amount.

Parameters:
NameTypeDescription
_deltaPoint | Dimension

Object containing the X and Y ratio to be scaled.

Returns:
Type: 
module:AWT.Shape

setAttributes(data) → {module:AWT.Path}

Reads the properties of this Path from a data object

Parameters:
NameTypeDescription
dataobject

The data object to be parsed

Returns:
Type: 
module:AWT.Path

stroke(ctx) → {external:CanvasRenderingContext2D}

Draws this shape in the provided HTML canvas 2D rendering context.

Parameters:
NameTypeDescription
ctxexternal:CanvasRenderingContext2D

The canvas 2D rendering context where to draw the shape.

Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

toString() → {string}

Overwrites the original 'Object.toString' method with a more descriptive text

Returns:
Type: 
string