API Docs for: 6.0.1
Show:

Point Class

Extends Base
Module: scrawlPath

Point

Instantiation

  • Objects created via Path factories
  • scrawl.makeCartesianPoints() - deprecated
  • scrawl.makePolarPoints() - deprecated

Purpose

  • Defines a movable point within a Path entity object
  • Acts as a coordinate vector for Link drawing

Path creation factories will all create Point objects automatically as part of the generation process. Point objects will be named regularly, depending on the factory:

  • scrawl.makeLine(): SPRITENAME_p1 (start point), SPRITENAME_p2 (end point)
  • scrawl.makeQuadratic(): SPRITENAME_p1 (start point), SPRITENAME_p2 (control point), SPRITENAME_p3 (end point)
  • scrawl.makeBezier(): SPRITENAME_p1 (start point), SPRITENAME_p2 (first control point), SPRITENAME_p3 (second control point), SPRITENAME_p4 (end point)
  • scrawl.makeRegularShape(): each angle point is numbered consecutively, starting at SPRITENAME_p1
  • scrawl.makePath(): points are numbered consecutively, beginning from SPRITENAME_p1 at the start of the path; the end point of a line, quadratic curve or bezier curve will also act as the start point for the next line or curve

Access

  • scrawl.point.POINTNAME - for the Point object

Constructor

Point

(
  • [items]
)

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Methods

clone

(
  • items
)
chainable

Clone a Scrawl.js object, optionally altering attribute values in the cloned object

Note that any callback or fn attribute functions will be referenced by the clone, not copied to the clone; these can be overwritten with new anonymous functions by including them in the items argument object

(This function is replaced by the path extension)

Parameters:

  • items Object

    Object containing attribute key:value pairs; will overwrite existing values in the cloned, but not the source, Object

Returns:

Cloned object

Example:

var box = scrawl.makeBlock({
    width: 50,
    height: 50
    });
var newBox = box.clone({
    height: 100
    });
newBox.get('width');        //returns 50
newBox.get('height');       //returns 100

get

(
  • item
)

Retrieve an attribute value. If the attribute value has not been set, then the default value for that attribute will be returned.

Parameters:

  • item String

    Attribute key

Returns:

Attribute value

Example:

var box = scrawl.makeBlock({
    width: 50,
    });
box.get('width');               //returns 50
box.get('height');              //returns 0
box.get('favouriteAnimal');     //returns undefined

getCurrentCoordinates

()

Retrieve Point object's coordinates

  • Coordinate reference frame determined by the value of Point.local
  • Coordinate values determined by setting of Point.fixed, Point.local and the parent Shape object's position and settings

Returns:

Coordinate Vector

getData

() private

Retrieve Point object's coordinates, together with additional data

  • Coordinate reference frame determined by the value of Point.local
  • Coordinate values determined by setting of Point.fixed, Point.local and the parent Shape object's position and settings

Return object has the following attributes:

  • name - Point.name
  • current - coordinate Vector
  • startLink - Point.startLink

Returns:

Result object

numberConvert

(
  • val
  • dim
)
private

Stamp helper function - convert string percentage values to numerical values

Parameters:

  • val String

    coordinate String

  • dim Number

    dimension value

Returns:

Number - value

parse

()

Turn the object into a JSON String

Returns:

object of object's currently set attributes

set

(
  • items
)
chainable

Inherited from Base but overwritten in source\scrawlPath.js:1591

Augments Base.set(), to allow users to set the local attributes using startX, startY, currentX, currentY, distance, angle

Parameters:

  • items Object

    Object consisting of key:value attributes

Returns:

This

setDelta

(
  • items
)
chainable

Add values to the local attribute. Permitted attributes of the argument object include:

  • startX, currentX - added to _local.x
  • startY, currentY - added to _local.y
  • distance - recalculates the local vector to set its values to equal vector's current magnitude + distance (in pixels)
  • angle - recalculates the local vector to rotate it by the angle value (in degrees)

Parameters:

  • items Object

    Object consisting of key:value attributes

Returns:

This

setLocal

(
  • items
)
private chainable

Set helpere function

Parameters:

  • items Object

    Object consisting of key:value attributes

Returns:

This

setPolar

(
  • items
)
chainable

Sets the local attribute using angle and/or distance parameters:

  • distance - calculates the local vector to set its values to equal vector's current magnitude + distance (in pixels)
  • angle - calculates the local vector to rotate it by the angle value (in degrees)

Parameters:

  • items Object

    Object consisting of key:value attributes

Returns:

This

setToFixed

(
  • items
  • [y]
)
chainable

Set Point.fixed attribute

Parameters:

  • items Mixed
    • either a coordinate Vector; or an Object with x and y attributes; or a Number representing the horizontal coordinate, in pixels, from <canvas> element's left edge; or a pivot SPRITENAME, POINTNAME or PARTICLENAME String
  • [y] Number optional
    • vertical coordinate, in pixels, from <canvas> element's top edge

Returns:

This

Properties

comment

String

Comment, for accessibility

Default: ''

current

Vector private

Point's coordinate current Vector - generally the Vector marks the Point's position (in pixels) from the Parent entity's start coordinates, though this can be changed by setting the fixed attribute to true.

The following argument attributes can be used to initialize, set and get this attribute's component values:

  • startX or currentX to set the x coordinate value
  • startY or currentY to set the y coordinate value

Default: zero value Vector

entity

String

SPRITENAME String of point object's parent entity

Default: ''

fixed

Boolean

Fixed attribute is used to fix the Point to a specific Cell coordinate Vector (true), or to a Entity start Vector (SPRITENAME). Default action is to treat the Point as local to its parent Entity's start coordinate

Default: false

local

Vector

Point's coordinate Vector - generally the Vector marks the Point's position (in pixels) from the Parent entity's start coordinates, though this can be changed by setting the fixed attribute to true.

The following argument attributes can be used to initialize, set and get this attribute's component values:

  • startX or currentX to set the x coordinate value
  • startY or currentY to set the y coordinate value

Default: zero value Vector

name

String

Unique identifier for each object; default: computer-generated String based on Object's type

timestamp

String

Creation timestamp

Default: ''

title

String

Title, for accessibility

Default: ''

type

String final

Inherited from Base but overwritten in source\scrawlPath.js:1525

Default: 'Point'