Skip to content

Instantly share code, notes, and snippets.

@fatihacet fatihacet/Box.coffee
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.