danmatrix
    Preparing search index...

    Class Coordinates

    Coordinates is the class representing the 2-Dimension coordinates (x,y)

    Index

    Constructors

    • The protected constructor

      Parameters

      • x: number

        The x non-negative integer number

      • y: number

        The y non-negative integer number

      Returns Coordinates

    Properties

    _x: number

    The x non-negative integer number

    _y: number

    The y non-negative integer number

    Methods

    • Reset the initial default values (0,0)

      Returns void

    • The x setter

      Parameters

      • x: string | number

        The x non-negative integer ("stringified") number

      Returns boolean

      • false if the input is not a correct value for the coordinates
      • otherwise true and the numeric value of the input is assigned to the protected _x class member
    • The y setter

      Parameters

      • y: string | number

        The y non-negative integer ("stringified") number

      Returns boolean

      • false if the input is not a correct value for the coordinates
      • otherwise true and the numeric value of the input is assigned to the protected _y class member
    • Get the coordinates as array [x,y]

      Returns number[]

      the coordinates as array [x,y]. Ex: [3,4]

    • Get the coordinates in string format separated by a separator

      Parameters

      • separator: string = '-'

        the separator of the stringified coordinates. Default '-'

      Returns string

      the stringified version of the coordinates. Ex: '2-7'

    • Utility function to transform an array of coordinates [x,y] into its "stringified" version 'x-y' based on the value of the separator (which defaults to '-').

      Parameters

      • coordsArr: (string | number)[]

        the array of coordinates [x,y]. Ex: [2,7]

      • separator: string = '-'

        the separator of the stringified coordinates in output

      Returns string | false

      • false if there's any error in the coordsArr parameter or in the separator
      • otherwise the stringified version of the coordinates. Ex: '2-7'
    • Utility static method to check that the 'val' in input in a non-negative integer number, or a "stringified" non-negative integer which will be transformed into a number

      Parameters

      • val: string | number

        the input which can be a string or a number

      Returns number | false

      • false if the input is not a non-negative ("stringified") integer
      • otherwise the numeric value of the input
    • Build a Coordinates class instance from array coordinates [x,y]

      Parameters

      • coordsArr: (string | number)[]

        the array of coordinates [x,y]. Ex: [5,1]

      Returns Coordinates

      • if there's any error in the coordsArr parameter it returns a default Coordinate instance with (0,0)
      • otherwise it returns an instance of the Coordinates class with (x,y)
    • Build a Coordinates class instance from string coordinates 'x-y'

      Parameters

      • strCoords: string

        the stringified coordinates. Ex: '4-7'

      • separator: string = '-'

        the separator of the stringified coordinates. Default '-'

      Returns Coordinates

      • if there's any error in the strCoords parameter or the separator it returns a default Coordinate instance with (0,0)
      • otherwise it returns an instance of the Coordinates class with (x,y)
    • Utility function to transform a stringified coordinates 'x-y' into the array of coordinates [x,y]

      Parameters

      • strCoords: string

        the stringified coordinates. Ex: '4-7'

      • separator: string = '-'

        the separator of the stringified coordinates. Default '-'

      Returns false | [number, number]

      • false if there's any error in the strCoords parameter or the separator
      • otherwise it returns the array of coordinates [x,y]. Ex: [4,7]