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
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
|
|
point2
|
Return values
-
Returns the given Point that is earlier in the buffer.
::compare(other)
| Argument | Description |
|---|---|
other
|
Return values
-
Returns
-1if this point precedes the argument. -
Returns
0if this point is equivalent to the argument. -
Returns
1if this point follows the argument.
::isEqual(other)
| Argument | Description |
|---|---|
other
|
Return values
::isLessThan(other)
| Argument | Description |
|---|---|
other
|
Return values
::isLessThanOrEqual(other)
| Argument | Description |
|---|---|
other
|
Return values
::isGreaterThan(other)
| Argument | Description |
|---|---|
other
|
Return values
::isGreaterThanOrEqual(other)
| Argument | Description |
|---|---|
other
|
Return values
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
-
Returns a Point.
::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
-
Returns a Point.
Comparison
.min(point1, point2)
| Argument | Description |
|---|---|
point1
|
|
point2
|
Return values
-
Returns the given Point that is earlier in the buffer.
::compare(other)
| Argument | Description |
|---|---|
other
|
Return values
-
Returns
-1if this point precedes the argument. -
Returns
0if this point is equivalent to the argument. -
Returns
1if this point follows the argument.
::isEqual(other)
| Argument | Description |
|---|---|
other
|
Return values
::isLessThan(other)
| Argument | Description |
|---|---|
other
|
Return values
::isLessThanOrEqual(other)
| Argument | Description |
|---|---|
other
|
Return values
::isGreaterThan(other)
| Argument | Description |
|---|---|
other
|
Return values
::isGreaterThanOrEqual(other)
| Argument | Description |
|---|---|
other
|
Return values
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.