Skip to content

Instantly share code, notes, and snippets.

@fatihacet
Last active August 29, 2015 14:11
Show Gist options
  • Save fatihacet/1ece4fc516b5dda8b9d7 to your computer and use it in GitHub Desktop.
Save fatihacet/1ece4fc516b5dda8b9d7 to your computer and use it in GitHub Desktop.

Revisions

  1. fatihacet revised this gist Dec 20, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Box.coffee
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,10 @@ class Box
    ###*
    Class for representing a box. A box is specified as a top, right, bottom
    and left.
    @constructor
    @param {Object} options Options object to hold top, right, bottom
    and left values.
    ###
    constructor: (options = {}) ->

  2. fatihacet created this gist Dec 20, 2014.
    51 changes: 51 additions & 0 deletions Box.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    class Box

    ###*
    Class for representing a box. A box is specified as a top, right, bottom
    and left.
    ###
    constructor: (options = {}) ->

    @top = options.top or 0
    @right = options.right or 0
    @bottom = options.bottom or 0
    @left = options.left or 0


    ###*
    Returns box width.
    @return {number} Box width.
    ###
    getWidth: ->
    return @right - @left


    ###*
    Returns box height.
    @return {number} Box height.
    ###
    getHeight: ->
    return @top - @bottom


    ###*
    Creates a copy of the box with the same dimensions.
    @return {Box} Cloned box.
    ###
    clone: ->
    return new Box { @top, @right, @bottom, @left }


    ###*
    Scales the box with given ratio.
    @param {!number} ratio Ratio to scale all dimensions.
    ###
    scale: (ratio) ->
    @top *= ratio
    @right *= ratio
    @top *= ratio
    @bottom *= ratio