mirror of
https://github.com/atom/atom.git
synced 2026-02-07 13:14:55 -05:00
When passing arrays between child processes with node's IPC machanism, `instance of Array` will return false for the deserialized array, we should use the reiable way of detecting Array provided by underscore. Read this for more: http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/ This bug was found when moving spell-check to use ProcessTask, and the wrong Range object was returned for the passed misspelling value.
92 lines
1.7 KiB
CoffeeScript
92 lines
1.7 KiB
CoffeeScript
_ = require 'underscore'
|
|
|
|
module.exports =
|
|
class Point
|
|
@fromObject: (object) ->
|
|
if object instanceof Point
|
|
object
|
|
else
|
|
if _.isArray(object)
|
|
[row, column] = object
|
|
else
|
|
{ row, column } = object
|
|
|
|
new Point(row, column)
|
|
|
|
@min: (point1, point2) ->
|
|
point1 = @fromObject(point1)
|
|
point2 = @fromObject(point2)
|
|
if point1.isLessThanOrEqual(point2)
|
|
point1
|
|
else
|
|
point2
|
|
|
|
constructor: (@row=0, @column=0) ->
|
|
|
|
copy: ->
|
|
new Point(@row, @column)
|
|
|
|
add: (other) ->
|
|
other = Point.fromObject(other)
|
|
row = @row + other.row
|
|
if other.row == 0
|
|
column = @column + other.column
|
|
else
|
|
column = other.column
|
|
|
|
new Point(row, column)
|
|
|
|
translate: (other) ->
|
|
other = Point.fromObject(other)
|
|
new Point(@row + other.row, @column + other.column)
|
|
|
|
splitAt: (column) ->
|
|
if @row == 0
|
|
rightColumn = @column - column
|
|
else
|
|
rightColumn = @column
|
|
|
|
[new Point(0, column), new Point(@row, rightColumn)]
|
|
|
|
compare: (other) ->
|
|
if @row > other.row
|
|
1
|
|
else if @row < other.row
|
|
-1
|
|
else
|
|
if @column > other.column
|
|
1
|
|
else if @column < other.column
|
|
-1
|
|
else
|
|
0
|
|
|
|
isEqual: (other) ->
|
|
return false unless other
|
|
other = Point.fromObject(other)
|
|
@row == other.row and @column == other.column
|
|
|
|
isLessThan: (other) ->
|
|
@compare(other) < 0
|
|
|
|
isLessThanOrEqual: (other) ->
|
|
@compare(other) <= 0
|
|
|
|
isGreaterThan: (other) ->
|
|
@compare(other) > 0
|
|
|
|
isGreaterThanOrEqual: (other) ->
|
|
@compare(other) >= 0
|
|
|
|
inspect: ->
|
|
"(#{@row}, #{@column})"
|
|
|
|
toString: ->
|
|
"#{@row},#{@column}"
|
|
|
|
toArray: ->
|
|
[@row, @column]
|
|
|
|
serialize: ->
|
|
@toArray()
|