point

<script src="./point_src/point"></script>

Meta Data
dependencies ()
unused_keys ('title',)
unknown_keys ('files', 'doc_readme', 'doc_loader', 'doc_content', 'doc_imports', 'categories')
files ['', 'relative-xy.js', 'pointcast.js']
doc_readme ['point/readme.md']
doc_loader ['loadDocInfo']
doc_content ['point/*.md']
doc_imports ['point']
categories ['primary', 'point']
filepath_exists True
path point
filepath point.js
clean_files ('relative-xy.js', 'pointcast.js')

The entire library is focused upon the single 2D Point.

Getting Started

A Point accepts many properties, or an object.

Default properties:
// accepts: (x, y, radius, rotation)
new Point(100, 200, 20, 90)
Or array of the same four attributes
// accepts: (x, y, radius, rotation)
new Point([100, 200, 20, 90])
The same properties may be applied through an object:
new Point({
    x: 100
    , y: 200
    , radius: 20
    , rotation: 90
})
Anything can be applied to the point instance directly:
let point = new Point

point.x = 100
point.y = 200
point.radius = 20
point.rotation = 90
  • VariableDeclaration
    const

    isPoint

    =
    function ( value )
  • VariableDeclaration
    const

    isFunction

    =
    function ( value )
  • VariableDeclaration
    const

    point

    =
    function ( p , b )
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])
  • ClassDeclaration
    class comments:

    The base Positionable class provides functionality for plotting the X and Y of an entity. This includes any fundamental methods such as multiply().

    • set

      x

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      ABOVE X method

      Multiline - touching.

      Set the X (horizontal | latitude | across) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • set

      y

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the Y (vertical | height | longtitude) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • get

      x

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _x = this._opts.x;

    • get

      y

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _y = this._opts.y;

    • set

      radius

      (
      v
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      this._opts.radius = isFunction(v)? v(this, 'radius'): v

    • get

      radius

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the radius of this point in base units (pixels)

      const point = new Point(100,300, 20)
      point.radius == 20
      
    • method

      setSpecial

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the given key, value, assuming the given key is a "special" string, such as "radius". This method is called by the special getters and setters for this point:

      const point = new Point(100,300, 20)
      point.setSpecial('radius', 55)
      

      Synonymous to:

      point.radius = 55
      
    • method

      onSpecialSet

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      A callback executed by setSpecial when a "special" property is called.

      If a method on this point exists matching the set method pattern, the method is called with the given value:

      class MyPoint extends Point {
          radiusSet(value) {
              console.log('New Radius value is', value)
          }
      }
      
    • method

      getSpecial

      (
      key , relIndex = undefined , defaultValue
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return a stored special value given a key.

      If the relIndex property is not None, the relative value found at the index (within this points relative data Array), add the stashed relative value to the result.

      const point = new Point(100,300, 20)
      point.getSpecial('radius', 2)
      // 20
      

      if a default value is given, and the internal key value does not exist, return the default value:

      point.getSpecial('banana', 'yellow')
      'yellow'
      
    • method

      set

      (
      x , y , radius , rotation
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      set(x, y, radius, rotation) set(100) => x,y set([]) => [x,y,radius, rotation] set({}) => *

    • method

      _cast

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      subtract

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "subtract" this point to the other point, returning a new point.

    • method

      add

      (
      other , _b
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Add" this point to the other point, returning a new point.

    • method

      divide

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Divide" this point to the other point, returning a new point.

    • method

      multiply

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Multiply" this point to the other point, returning a new point.

    • method

      midpoint

      (
      other , offset = 0.5
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Returns a new point, with the XY set at the point that is offset times the distance from the current point to the other point.

      this function is also lerp for linear interpolation

    • property

      lerp

      from Positionable
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos', 'class_name'])
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ClassDeclaration
    class comments:

    Set the rotation in degrees (0 to 360). If this.modulusRotate is true (default), the given value is fixed through modulus 360

    point.rotation = 600
    // 240
    point.rotation += 1
    // 241
    

    To set the rotation (degrees) whilst accounting for the UP vector, consider the rotate() method.

    • set

      rotation

      (
      value
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the rotation in degrees (0 to 360). If this.modulusRotate is true (default), the given value is fixed through modulus 360

      point.rotation = 600
      // 240
      point.rotation += 1
      // 241
      

      To set the rotation (degrees) whilst accounting for the UP vector, consider the rotate() method.

    • method

      rotate

      (
      degrees
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      rotation

      (
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      radians

      (
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the radians of the current rotation, where _rotation returns the degrees

    • set

      radians

      (
      angle
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      by pushing through the existing rotations, we account for the up vector.

    • method

      lookAt

      (
      otherPoint , add , rotationMultiplier = undefined
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Rotate the point such that the angle relative to the otherPoint is 0, essentially looking at the other point.

      point.lookAt(otherPoint)
      

      Return the angle in radians.

    • method

      directionTo

      (
      otherPoint , rotationMultiplier = undefined , addRad
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Calculate the differences in x and y coordinates

    • method

      _normalizedRadians

      (
      otherPoint , rotationMultiplier , addRad
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Normalize the angle difference to be within the range -PI to PI

    • method

      turnTo

      (
      otherPoint , rotationMultiplier = 1
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      getTheta

      (
      other , direction = undefined
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the calculated theta value through atan2 and built to offload some of the boring. The direction denotes the "gravity" pull. Generally this is DOWN.

      Synonymous to:

      let theta = Math.atan2(point.y,
                             point.x);
      
      let theta = Math.atan2(point.y - other.y,
                             point.x - other.x);
      
      let theta = Math.atan2(point.y - other.y,
                             point.x - other.x) - DOWN;
      
    • set

      x

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      ABOVE X method

      Multiline - touching.

      Set the X (horizontal | latitude | across) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • set

      y

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the Y (vertical | height | longtitude) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • get

      x

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _x = this._opts.x;

    • get

      y

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _y = this._opts.y;

    • set

      radius

      (
      v
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      this._opts.radius = isFunction(v)? v(this, 'radius'): v

    • get

      radius

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the radius of this point in base units (pixels)

      const point = new Point(100,300, 20)
      point.radius == 20
      
    • method

      setSpecial

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the given key, value, assuming the given key is a "special" string, such as "radius". This method is called by the special getters and setters for this point:

      const point = new Point(100,300, 20)
      point.setSpecial('radius', 55)
      

      Synonymous to:

      point.radius = 55
      
    • method

      onSpecialSet

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      A callback executed by setSpecial when a "special" property is called.

      If a method on this point exists matching the set method pattern, the method is called with the given value:

      class MyPoint extends Point {
          radiusSet(value) {
              console.log('New Radius value is', value)
          }
      }
      
    • method

      getSpecial

      (
      key , relIndex = undefined , defaultValue
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return a stored special value given a key.

      If the relIndex property is not None, the relative value found at the index (within this points relative data Array), add the stashed relative value to the result.

      const point = new Point(100,300, 20)
      point.getSpecial('radius', 2)
      // 20
      

      if a default value is given, and the internal key value does not exist, return the default value:

      point.getSpecial('banana', 'yellow')
      'yellow'
      
    • method

      set

      (
      x , y , radius , rotation
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      set(x, y, radius, rotation) set(100) => x,y set([]) => [x,y,radius, rotation] set({}) => *

    • method

      _cast

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      subtract

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "subtract" this point to the other point, returning a new point.

    • method

      add

      (
      other , _b
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Add" this point to the other point, returning a new point.

    • method

      divide

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Divide" this point to the other point, returning a new point.

    • method

      multiply

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Multiply" this point to the other point, returning a new point.

    • method

      midpoint

      (
      other , offset = 0.5
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Returns a new point, with the XY set at the point that is offset times the distance from the current point to the other point.

      this function is also lerp for linear interpolation

    • property

      lerp

      from Positionable
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos', 'class_name'])
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ClassDeclaration
    class comments:

    str such as this["rotation"]

    • method

      resolveStringOrFunction

      (
      direction , defaultValue
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      str such as this["rotation"]

    • method

      atan2

      (
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the theta value through the atan2 function for this point.

    • method

      project

      (
      distance , rotation , relative = True
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      copy

      (
      position , deep
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Given another point, replicate the value into this node. Else, return a new node with the same information as this point.

    • method

      magnitude

      (
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      normalized

      (
      magnitude
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Synonymous to:

      {
          x: AB.x / magnitudeAB,
          y: AB.y / magnitudeAB
      };
      
    • method

      interpolateTo

      (
      other , offset , pointIndex
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      return a point relative from this point towards the other, offset by the given number offset value. The pointIndex (default 0) identifies from which point [this, other] to offset.

    • method

      interpolateFrom

      (
      other , offset , pointIndex
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      distance

      (
      a , b
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      quantize

      (
      amount = 1
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      protractorAngleTo

      (
      other , referencePoint
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      lerpPixel

      (
      other , pixelDistance
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Returns a new point, offset by pixelDistance pixels in the direction from this point to the other point.

    • set

      rotation

      (
      value
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the rotation in degrees (0 to 360). If this.modulusRotate is true (default), the given value is fixed through modulus 360

      point.rotation = 600
      // 240
      point.rotation += 1
      // 241
      

      To set the rotation (degrees) whilst accounting for the UP vector, consider the rotate() method.

    • method

      rotate

      (
      degrees
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      rotation

      (
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      radians

      (
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the radians of the current rotation, where _rotation returns the degrees

    • set

      radians

      (
      angle
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      by pushing through the existing rotations, we account for the up vector.

    • method

      lookAt

      (
      otherPoint , add , rotationMultiplier = undefined
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Rotate the point such that the angle relative to the otherPoint is 0, essentially looking at the other point.

      point.lookAt(otherPoint)
      

      Return the angle in radians.

    • method

      directionTo

      (
      otherPoint , rotationMultiplier = undefined , addRad
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Calculate the differences in x and y coordinates

    • method

      _normalizedRadians

      (
      otherPoint , rotationMultiplier , addRad
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Normalize the angle difference to be within the range -PI to PI

    • method

      turnTo

      (
      otherPoint , rotationMultiplier = 1
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      getTheta

      (
      other , direction = undefined
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the calculated theta value through atan2 and built to offload some of the boring. The direction denotes the "gravity" pull. Generally this is DOWN.

      Synonymous to:

      let theta = Math.atan2(point.y,
                             point.x);
      
      let theta = Math.atan2(point.y - other.y,
                             point.x - other.x);
      
      let theta = Math.atan2(point.y - other.y,
                             point.x - other.x) - DOWN;
      
    • set

      x

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      ABOVE X method

      Multiline - touching.

      Set the X (horizontal | latitude | across) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • set

      y

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the Y (vertical | height | longtitude) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • get

      x

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _x = this._opts.x;

    • get

      y

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _y = this._opts.y;

    • set

      radius

      (
      v
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      this._opts.radius = isFunction(v)? v(this, 'radius'): v

    • get

      radius

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the radius of this point in base units (pixels)

      const point = new Point(100,300, 20)
      point.radius == 20
      
    • method

      setSpecial

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the given key, value, assuming the given key is a "special" string, such as "radius". This method is called by the special getters and setters for this point:

      const point = new Point(100,300, 20)
      point.setSpecial('radius', 55)
      

      Synonymous to:

      point.radius = 55
      
    • method

      onSpecialSet

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      A callback executed by setSpecial when a "special" property is called.

      If a method on this point exists matching the set method pattern, the method is called with the given value:

      class MyPoint extends Point {
          radiusSet(value) {
              console.log('New Radius value is', value)
          }
      }
      
    • method

      getSpecial

      (
      key , relIndex = undefined , defaultValue
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return a stored special value given a key.

      If the relIndex property is not None, the relative value found at the index (within this points relative data Array), add the stashed relative value to the result.

      const point = new Point(100,300, 20)
      point.getSpecial('radius', 2)
      // 20
      

      if a default value is given, and the internal key value does not exist, return the default value:

      point.getSpecial('banana', 'yellow')
      'yellow'
      
    • method

      set

      (
      x , y , radius , rotation
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      set(x, y, radius, rotation) set(100) => x,y set([]) => [x,y,radius, rotation] set({}) => *

    • method

      _cast

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      subtract

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "subtract" this point to the other point, returning a new point.

    • method

      add

      (
      other , _b
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Add" this point to the other point, returning a new point.

    • method

      divide

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Divide" this point to the other point, returning a new point.

    • method

      multiply

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Multiply" this point to the other point, returning a new point.

    • method

      midpoint

      (
      other , offset = 0.5
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Returns a new point, with the XY set at the point that is offset times the distance from the current point to the other point.

      this function is also lerp for linear interpolation

    • property

      lerp

      from Positionable
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos', 'class_name'])
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ClassDeclaration
    class comments:

    The Point is the primary class for manipulating XY 2D points.

    Arguments:

    new Point(100, 200)
    

    Object | Array:

    new Point({x: 100, y: 200})
    new Point([100, 200])
    

    Properties:

    point = new Point
    point.x = 100
    point.y = 200
    
    • property

      UP

      from Point
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos', 'class_name'])
    • property

      _rotationDegrees

      from Point
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos', 'class_name'])
    • constructor

      constructor

      (
      opts = {}
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      A new point accepts arguments, an object, or an array.

      By default the Point accepts up to four arguments

      new Point(x, y, radius, rotation)
      

      The same properties may be supplied as a single Array:

      new Point([x, y, radius, rotation])
      

      If the given object is an object, we can assign properties immediately:

      point = new Point({x, y, radius, rotation, other:100})
      point.other
      // 100
      
    • method

      created

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      api hook for life.

    • method

      update

      (
      data
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Perform an update given a dictionary of other properties.

      point.update({ x: 200, color: 'red' })
      
    • get

      uuid

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Get or create the random _id for this point. Return a unique string.

    • set

      uuid

      (
      v
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      [[computed_Literal]]

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      return the X value of the point:

      point[0]
      

      Note:

      point[0] == point.x
      
    • set

      [[computed_Literal]]

      (
      value
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Sugar function to apply this.x:

      point[0] = 100
      point.x == 100
      
    • get

      [[computed_Literal]]

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      return the Y value of the point:

      point[0]
      

      Note:

      point[0] == point.y
      
    • set

      [[computed_Literal]]

      (
      value
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Sugar function to apply this.y:

      point[0] = 300
      point.y == 300
      
    • get

      [Symbol.toStringTag]

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      [Symbol.toPrimitive]

      (
      hint
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      return Reflect.apply(...arguments)

    • method

      toString

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      _liveProps

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      asArray

      (
      fix
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return this point as an Array of 4 values:

      const point = new Point(1,2,3,4);
      point.asArray();
      // [1,2,3,4]
      

      Keys:

      • x
      • y
      • radius
      • rotation
    • method

      asObject

      (
      )
      from Point
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the important information about this node, used for save or copy methods.

    • method

      resolveStringOrFunction

      (
      direction , defaultValue
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      str such as this["rotation"]

    • method

      atan2

      (
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the theta value through the atan2 function for this point.

    • method

      project

      (
      distance , rotation , relative = True
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      copy

      (
      position , deep
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Given another point, replicate the value into this node. Else, return a new node with the same information as this point.

    • method

      magnitude

      (
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      normalized

      (
      magnitude
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Synonymous to:

      {
          x: AB.x / magnitudeAB,
          y: AB.y / magnitudeAB
      };
      
    • method

      interpolateTo

      (
      other , offset , pointIndex
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      return a point relative from this point towards the other, offset by the given number offset value. The pointIndex (default 0) identifies from which point [this, other] to offset.

    • method

      interpolateFrom

      (
      other , offset , pointIndex
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      distance

      (
      a , b
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      quantize

      (
      amount = 1
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      protractorAngleTo

      (
      other , referencePoint
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      lerpPixel

      (
      other , pixelDistance
      )
      from Tooling
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Returns a new point, offset by pixelDistance pixels in the direction from this point to the other point.

    • set

      rotation

      (
      value
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the rotation in degrees (0 to 360). If this.modulusRotate is true (default), the given value is fixed through modulus 360

      point.rotation = 600
      // 240
      point.rotation += 1
      // 241
      

      To set the rotation (degrees) whilst accounting for the UP vector, consider the rotate() method.

    • method

      rotate

      (
      degrees
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      rotation

      (
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      radians

      (
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the radians of the current rotation, where _rotation returns the degrees

    • set

      radians

      (
      angle
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      by pushing through the existing rotations, we account for the up vector.

    • method

      lookAt

      (
      otherPoint , add , rotationMultiplier = undefined
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Rotate the point such that the angle relative to the otherPoint is 0, essentially looking at the other point.

      point.lookAt(otherPoint)
      

      Return the angle in radians.

    • method

      directionTo

      (
      otherPoint , rotationMultiplier = undefined , addRad
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Calculate the differences in x and y coordinates

    • method

      _normalizedRadians

      (
      otherPoint , rotationMultiplier , addRad
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Normalize the angle difference to be within the range -PI to PI

    • method

      turnTo

      (
      otherPoint , rotationMultiplier = 1
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      getTheta

      (
      other , direction = undefined
      )
      from Rotation
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the calculated theta value through atan2 and built to offload some of the boring. The direction denotes the "gravity" pull. Generally this is DOWN.

      Synonymous to:

      let theta = Math.atan2(point.y,
                             point.x);
      
      let theta = Math.atan2(point.y - other.y,
                             point.x - other.x);
      
      let theta = Math.atan2(point.y - other.y,
                             point.x - other.x) - DOWN;
      
    • set

      x

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      ABOVE X method

      Multiline - touching.

      Set the X (horizontal | latitude | across) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • set

      y

      (
      value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the Y (vertical | height | longtitude) value of the positionable. From cooridinate top left `(0,0)``

      point.x = 100
      

      If the given value is a function, the function is called immediately, with this positionable as the first argument.

      stage.center.x = (p)=>200
      
    • get

      x

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _x = this._opts.x;

    • get

      y

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      const _y = this._opts.y;

    • set

      radius

      (
      v
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      this._opts.radius = isFunction(v)? v(this, 'radius'): v

    • get

      radius

      (
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the radius of this point in base units (pixels)

      const point = new Point(100,300, 20)
      point.radius == 20
      
    • method

      setSpecial

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Set the given key, value, assuming the given key is a "special" string, such as "radius". This method is called by the special getters and setters for this point:

      const point = new Point(100,300, 20)
      point.setSpecial('radius', 55)
      

      Synonymous to:

      point.radius = 55
      
    • method

      onSpecialSet

      (
      key , value
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      A callback executed by setSpecial when a "special" property is called.

      If a method on this point exists matching the set method pattern, the method is called with the given value:

      class MyPoint extends Point {
          radiusSet(value) {
              console.log('New Radius value is', value)
          }
      }
      
    • method

      getSpecial

      (
      key , relIndex = undefined , defaultValue
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return a stored special value given a key.

      If the relIndex property is not None, the relative value found at the index (within this points relative data Array), add the stashed relative value to the result.

      const point = new Point(100,300, 20)
      point.getSpecial('radius', 2)
      // 20
      

      if a default value is given, and the internal key value does not exist, return the default value:

      point.getSpecial('banana', 'yellow')
      'yellow'
      
    • method

      set

      (
      x , y , radius , rotation
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      set(x, y, radius, rotation) set(100) => x,y set([]) => [x,y,radius, rotation] set({}) => *

    • method

      _cast

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      subtract

      (
      other , _2 = other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "subtract" this point to the other point, returning a new point.

    • method

      add

      (
      other , _b
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Add" this point to the other point, returning a new point.

    • method

      divide

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Divide" this point to the other point, returning a new point.

    • method

      multiply

      (
      other
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      "Multiply" this point to the other point, returning a new point.

    • method

      midpoint

      (
      other , offset = 0.5
      )
      from Positionable
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Returns a new point, with the XY set at the point that is offset times the distance from the current point to the other point.

      this function is also lerp for linear interpolation

    • property

      lerp

      from Positionable
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos', 'class_name'])
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])

dirty flag

Boolean

The dirty flag exists on all Points as a natural attribute. If the core attributes change: x y radius rotation, the point is dirty until tested.

This allows you to actively track a Point without special wiring

p = new Point()
p.dirty
// true 

Be aware; A new point is dirty by default.

Importantly, this is a gaurded attribute, restricting you from manually switching the boolean:

p = new Point()
p.dirty 
// true 

p.dirty = false // Attempt a manual flag.

// Didn't work.
p.dirty  
// true 

wasDirty

A common pattern is to test if the target point has changed and react to it. The convenient Point.wasDirty allows you to test for a change, and signal the flag was seen.

p = new Point()
p.dirty == true  // Expected

p.wasDirty
// true 

/* Any subsequent calls yield false */
p.wasDirty
// false

p.dirty
// false

This provides a nice feature where we can test for change to save render cycles or provide easy double-binding:

/* If the control point was manipulated, edit the main point. */
if(other.wasDirty) {
    point.lookAt(other)
    point.radius = point.distanceTo(other)
}

/* If the point was altered, edit the control point. */
if(point.wasDirty) {
    other.copy(point.getTip()) // grab the new tip position 
}

Because the flag wasDirty is only true if the point dirty=true, when the if statement is called, and the dirty is set to false.

Fields

The dirty-flag provides three attributes:

Attribute Description
dirty always returns the current state of the point as a boolean.
wasDirty returns a boolean matching the dirty flag, and always sets dirty=false
_dirty the Point internal true state, typically matching dirty. This can be manipulated manually

Notes

A new point is always dirty.

This ensures any logic dependant upon the state of a point will react at first draw.

wasDirty works once

The Point.wasDirty flag is safe once for the first call. Therefore subsequent calls immediately after this call will return false.

A nice solution is to use dirty until your last check


if(point.dirty) {
    // ...
}


if(point.dirty) {
    // ...
}

if(point.wasDirty) {
    // ...
}
// Was dirty; Now is not dirty.

// WON'T WORK; Dirty is now false;
if(point.dirty) {
    // ...
}

Recursive error for double-bound objects

Force the dirty state of a point to disable recursive dependencies:

point._dirty = false        // Force dirty off.

You may find where two points depend upon each other, they collide during tests:

if(other.wasDirty) {    
    point.radius = point.distanceTo(other) // edit A 
    // point.dirty == true 
}

if(point.wasDirty) {
    // point.false == true 
    other.copy(point.getTip()) // Edit B
    // other.dirty == true 
}

This logic will always call both statements as the last action is other.dirty == true, and cause tracking glitches.

To manually fix this, we can use the internal flag to turn off the dirty:

if(other.wasDirty) {    
    point.radius = point.distanceTo(other) // edit A 
    // point.dirty == true 
}

if(point.wasDirty) {
    // point.false == true 
    other.copy(point.getTip()) 
    other._dirty = false        // Force dirty off.
}

Therefore the other.wasDirty will only flag true if the other point was manipulated elsewhere.

Example

Here's an example of a tip control point tracking it's primary point.

class MainStage extends Stage {
    canvas = 'playspace'

    mounted(){
        this.point = new Point(100, 100, 20)
        this.cp = new Point(this.point.getTip())
        this.cp._dirty = false;
        this.dragging.add(this.point, this.cp)
    }

    draw(ctx){
        this.clear(ctx)

        /* If the control point was manipulated, edit the main point. */
        if(this.cp.wasDirty) {
            this.point.lookAt(this.cp)
            this.point.radius = this.point.distanceTo(this.cp)
        }

        /* If the point was altered, edit the control point. */
        if(this.point.wasDirty) {
            this.cp.copy(this.point.getTip())
            this.cp._dirty = false;
        }

        this.point.pen.indicator(ctx);
        this.cp.pen.indicator(ctx);
    }
}

stage = MainStage.go(/*{ loop: true }*/)

lerp()

Point

The lerp() method accepts a Point and a float. The float value 0 to 1 is a represents a percent amount along the distance to the other point.

point.lerp(other, .5)