<commit_before>Point = require './point'

module.exports =
class Range
  @deserialize: (array) ->
    new this(array...)

  @fromObject: (object, copy) ->
    if Array.isArray(object)
      new this(object...)
    else if object instanceof this
      if copy then object.copy() else object
    else
      new this(object.start, object.end)

  @fromText: (args...) ->
    if args.length > 1
      startPoint = Point.fromObject(args.shift())
    else
      startPoint = new Point(0, 0)
    text = args.shift()
    endPoint = startPoint.copy()
    lines = text.split('\n')
    if lines.length > 1
      lastIndex = lines.length - 1
      endPoint.row += lastIndex
      endPoint.column = lines[lastIndex].length
    else
      endPoint.column += lines[0].length
    new this(startPoint, endPoint)

  constructor: (pointA = new Point(0, 0), pointB = new Point(0, 0)) ->
    pointA = Point.fromObject(pointA)
    pointB = Point.fromObject(pointB)

    if pointA.isLessThanOrEqual(pointB)
      @start = pointA
      @end = pointB
    else
      @start = pointB
      @end = pointA

  serialize: ->
    [@start.serialize(), @end.serialize()]

  copy: ->
    new @constructor(@start.copy(), @end.copy())

  freeze: ->
    @start.freeze()
    @end.freeze()
    Object.freeze(this)

  isEqual: (other) ->
    return false unless other?

    if Array.isArray(other) and other.length == 2
      other = new @constructor(other...)

    other.start.isEqual(@start) and other.end.isEqual(@end)

  compare: (other) ->
    other = @constructor.fromObject(other)
    if value = @start.compare(other.start)
      value
    else
      other.end.compare(@end)

  isSingleLine: ->
    @start.row == @end.row

  coversSameRows: (other) ->
    @start.row == other.start.row && @end.row == other.end.row

  translate: (startPoint, endPoint=startPoint) ->
    new @constructor(@start.translate(startPoint), @end.translate(endPoint))

  intersectsWith: (otherRange) ->
    if @start.isLessThanOrEqual(otherRange.start)
      @end.isGreaterThanOrEqual(otherRange.start)<commit_msg>Only accept a single delta argument in ::translate<commit_after>Point = require './point'

module.exports =
class Range
  @deserialize: (array) ->
    new this(array...)

  @fromObject: (object, copy) ->
    if Array.isArray(object)
      new this(object...)
    else if object instanceof this
      if copy then object.copy() else object
    else
      new this(object.start, object.end)

  @fromText: (args...) ->
    if args.length > 1
      startPoint = Point.fromObject(args.shift())
    else
      startPoint = new Point(0, 0)
    text = args.shift()
    endPoint = startPoint.copy()
    lines = text.split('\n')
    if lines.length > 1
      lastIndex = lines.length - 1
      endPoint.row += lastIndex
      endPoint.column = lines[lastIndex].length
    else
      endPoint.column += lines[0].length
    new this(startPoint, endPoint)

  constructor: (pointA = new Point(0, 0), pointB = new Point(0, 0)) ->
    pointA = Point.fromObject(pointA)
    pointB = Point.fromObject(pointB)

    if pointA.isLessThanOrEqual(pointB)
      @start = pointA
      @end = pointB
    else
      @start = pointB
      @end = pointA

  serialize: ->
    [@start.serialize(), @end.serialize()]

  copy: ->
    new @constructor(@start.copy(), @end.copy())

  freeze: ->
    @start.freeze()
    @end.freeze()
    Object.freeze(this)

  isEqual: (other) ->
    return false unless other?

    if Array.isArray(other) and other.length == 2
      other = new @constructor(other...)

    other.start.isEqual(@start) and other.end.isEqual(@end)

  compare: (other) ->
    other = @constructor.fromObject(other)
    if value = @start.compare(other.start)
      value
    else
      other.end.compare(@end)

  isSingleLine: ->
    @start.row == @end.row

  coversSameRows: (other) ->
    @start.row == other.start.row && @end.row == other.end.row

  translate: (delta) ->
    new @constructor(@start.translate(delta), @end.translate(delta))

  intersectsWith: (otherRange) ->
    if @start.isLessThanOrEqual(otherRange.start)
      @end.isGreaterThanOrEqual(otherRange.start)
{'fraction_non_alphanumeric': 0.14157139382145464, 'fraction_numerical': 0.00535149598637801, 'mean_word_length': 2.782888684452622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1254809', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1314, 'n_words': 301}