point

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

Meta Data
dependencies ()
unused_keys ('title',)
unknown_keys ('doc_imports', 'files', 'categories', 'doc_readme', 'doc_content', 'doc_loader')
doc_imports ['point']
files ['', 'relative-xy.js', 'pointcast.js']
categories ['primary', 'point']
doc_readme ['point/readme.md']
doc_content ['point/*.md']
doc_loader ['loadDocInfo']
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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      const _x = this._opts.x;

    • get

      y

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

      const _y = this._opts.y;

    • set

      radius

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

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

    • get

      radius

      (
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
              set(x, y, radius, rotation)
              set(100)    => x,y
              set([])     => [x,y,radius, rotation]
              set({})     => *
      
    • method

      _cast

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

      subtract

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

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

    • method

      add

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

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

    • method

      divide

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

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

    • method

      multiply

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

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

    • method

      midpoint

      (
      other , offset = 0.5
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          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 class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • get

      rotation

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

      radians

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

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

    • set

      radians

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

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

    • method

      lookAt

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

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Calculate the differences in x and y coordinates

    • method

      _normalizedRadians

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

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

    • method

      turnTo

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

      getTheta

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

      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;
      
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ClassDeclaration
    class comments:
    str such as this["rotation"]
    • method

      resolveStringOrFunction

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

      str such as this["rotation"]

    • method

      atan2

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

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

    • method

      project

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

      copy

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

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

    • method

      magnitude

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

      normalized

      (
      magnitude
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          Synonymous to:
      
              {
                  x: AB.x / magnitudeAB,
                  y: AB.y / magnitudeAB
              };
      
    • method

      interpolateTo

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

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      distance

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

      quantize

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

      protractorAngleTo

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

      lerpPixel

      (
      other , pixelDistance
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          Returns a new point, offset by `pixelDistance` pixels in the direction
          from this point to the other point.
      
    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 class_name
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • property

      _rotationDegrees

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

      constructor

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

      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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      api hook for life.

    • method

      update

      (
      data
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          Perform an _update_ given a dictionary of other properties.
      
              point.update({ x: 200, color: 'red' })
      
    • get

      uuid

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

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

    • set

      uuid

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

      [[computed_Literal]]

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

      return the X value of the point:

              point[0]
      
          Note:
      
              point[0] == point.x
      
    • set

      [[computed_Literal]]

      (
      value
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          Sugar function to apply `this.x`:
      
              point[0] = 100
              point.x == 100
      
    • get

      [[computed_Literal]]

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

      return the Y value of the point:

              point[0]
      
          Note:
      
              point[0] == point.y
      
    • set

      [[computed_Literal]]

      (
      value
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          Sugar function to apply `this.y`:
      
              point[0] = 300
              point.y == 300
      
    • get

      [Symbol.toStringTag]

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

      [Symbol.toPrimitive]

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

      return Reflect.apply(...arguments)

    • method

      toString

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

      _liveProps

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

      asArray

      (
      fix
      )
      from class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
          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 class_name
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

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

    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'])

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)