Skip to content

Instantly share code, notes, and snippets.

@fatihacet
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatihacet/1ece4fc516b5dda8b9d7 to your computer and use it in GitHub Desktop.
Save fatihacet/1ece4fc516b5dda8b9d7 to your computer and use it in GitHub Desktop.
Sample Box class for FE-CI blog post.
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 = {}) ->
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment