Class: RubySprites::Block
- Inherits:
-
Object
- Object
- RubySprites::Block
- Defined in:
- lib/lash-sprites/block.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #area ⇒ Object
- #fits?(img) ⇒ Boolean
-
#initialize(x, y, width, height) ⇒ Block
constructor
A new instance of Block.
- #split(img) ⇒ Object
Constructor Details
#initialize(x, y, width, height) ⇒ Block
Returns a new instance of Block.
6 7 8 9 10 11 |
# File 'lib/lash-sprites/block.rb', line 6 def initialize(x, y, width, height) @x = x @y = y @width = width @height = height end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/lash-sprites/block.rb', line 4 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/lash-sprites/block.rb', line 4 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/lash-sprites/block.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/lash-sprites/block.rb', line 4 def y @y end |
Instance Method Details
#area ⇒ Object
29 30 31 32 |
# File 'lib/lash-sprites/block.rb', line 29 def area @area = @width * @height if @area.nil? return @area end |
#fits?(img) ⇒ Boolean
13 14 15 |
# File 'lib/lash-sprites/block.rb', line 13 def fits?(img) return img.width <= @width && img.height <= @height end |
#split(img) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lash-sprites/block.rb', line 17 def split(img) blocks = [] if (@width - img.width) * img.height > (@height - img.height) * img.width blocks.push Block.new(@x + img.width, @y, @width - img.width, @height) if @width != img.width blocks.push Block.new(@x, @y + img.height, img.width, @height - img.height) if @height != img.height else blocks.push Block.new(@x + img.width, @y, @width - img.width, img.height) if @width != img.width blocks.push Block.new(@x, @y + img.height, @width, @height - img.height) if @height != img.height end return blocks end |