Last active
August 29, 2015 14:11
-
-
Save fatihacet/1ece4fc516b5dda8b9d7 to your computer and use it in GitHub Desktop.
Sample Box class for FE-CI blog post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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