Point

Description

Represents a point in a buffer in row/column coordinates.

Every public method that takes a point also accepts a point-compatible Array. This means a 2-element array containing Numbers representing the row and column. So the following are equivalent:

new Point(1, 2)
[1, 2] # Point compatible Array

API documentation

Properties

::row

A zero-indexed Number representing the row of the Point.

::column

A zero-indexed Number representing the column of the Point.

Construction

.fromObject(object, copy)

Convert any point-compatible object to a Point.

Argument Description
object

This can be an object that's already a Point, in which case it's simply returned, or an array containing two Numbers representing the row and column.

copy

An optional boolean indicating whether to force the copying of objects that are already points.

Return values
  • Returns: A Point based on the given object.

::constructor(row, column)

Construct a Point object

Argument Description
row

Number row

column

Number column

::copy()

Return values
  • Returns a new Point with the same row and column.

::negate()

Return values
  • Returns a new Point with the row and column negated.

Comparison

.min(point1, point2)

Argument Description
point1

Point

point2

Point

Return values
  • Returns the given Point that is earlier in the buffer.

::compare(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns -1 if this point precedes the argument.

  • Returns 0 if this point is equivalent to the argument.

  • Returns 1 if this point follows the argument.

::isEqual(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point has the same row and column as the given Point or point-compatible Array.

::isLessThan(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point precedes the given Point or point-compatible Array.

::isLessThanOrEqual(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point precedes or is equal to the given Point or point-compatible Array.

::isGreaterThan(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point follows the given Point or point-compatible Array.

::isGreaterThanOrEqual(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point follows or is equal to the given Point or point-compatible Array.

Construction

.fromObject(object, copy)

Convert any point-compatible object to a Point.

Argument Description
object

This can be an object that's already a Point, in which case it's simply returned, or an array containing two Numbers representing the row and column.

copy

An optional boolean indicating whether to force the copying of objects that are already points.

Return values
  • Returns: A Point based on the given object.

::constructor(row, column)

Construct a Point object

Argument Description
row

Number row

column

Number column

::copy()

Return values
  • Returns a new Point with the same row and column.

::negate()

Return values
  • Returns a new Point with the row and column negated.

Operations

::freeze()

Makes this point immutable and returns itself.

Return values
  • Returns an immutable version of this Point

::translate(other)

Build and return a new point by adding the rows and columns of the given point.

Argument Description
other

A Point whose row and column will be added to this point's row and column to build the returned point.

Return values

::traverse(other)

Build and return a new Point by traversing the rows and columns specified by the given point.

This method differs from the direct, vector-style addition offered by Point::translate. Rather than adding the rows and columns directly, it derives the new point from traversing in "typewriter space". At the end of every row traversed, a carriage return occurs that returns the columns to 0 before continuing the traversal.

Argument Description
other

A Point providing the rows and columns to traverse by.

Return values

Comparison

.min(point1, point2)

Argument Description
point1

Point

point2

Point

Return values
  • Returns the given Point that is earlier in the buffer.

::compare(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns -1 if this point precedes the argument.

  • Returns 0 if this point is equivalent to the argument.

  • Returns 1 if this point follows the argument.

::isEqual(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point has the same row and column as the given Point or point-compatible Array.

::isLessThan(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point precedes the given Point or point-compatible Array.

::isLessThanOrEqual(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point precedes or is equal to the given Point or point-compatible Array.

::isGreaterThan(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point follows the given Point or point-compatible Array.

::isGreaterThanOrEqual(other)

Argument Description
other

A Point or point-compatible Array.

Return values
  • Returns a Boolean indicating whether this point follows or is equal to the given Point or point-compatible Array.

Conversion

::toArray()

Return values
  • Returns an array of this point's row and column.

::serialize()

Return values
  • Returns an array of this point's row and column.

::toString()

Return values
  • Returns a string representation of the point.