Class: ChunkyPNG::Dimension
- Inherits:
-
Object
- Object
- ChunkyPNG::Dimension
- Defined in:
- lib/chunky_png/dimension.rb
Overview
Class that represents the dimension of something, e.g. a Canvas.
This class contains some methods to simplify performing dimension related checks.
Instance Attribute Summary collapse
-
#height ⇒ Integer
The height-component of this dimension.
-
#width ⇒ Integer
The width-component of this dimension.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compares the size of 2 dimensions.
-
#area ⇒ Integer
Returns the area of this dimension.
-
#eql?(other) ⇒ true, false
(also: #==)
Checks whether 2 dimensions are identical.
-
#hash ⇒ Integer
Calculates a hash for the dimension object, based on width and height.
-
#include?(*point_like) ⇒ true, false
Checks whether a point is within bounds of this dimension.
-
#initialize(width, height) ⇒ Dimension
constructor
Initializes a new dimension instance.
-
#to_a ⇒ Array<Integer>
(also: #to_ary)
Casts this dimension into an array.
Constructor Details
#initialize(width, height) ⇒ Dimension
Initializes a new dimension instance.
82 83 84 |
# File 'lib/chunky_png/dimension.rb', line 82 def initialize(width, height) @width, @height = width.to_i, height.to_i end |
Instance Attribute Details
#height ⇒ Integer
Returns The height-component of this dimension.
77 78 79 |
# File 'lib/chunky_png/dimension.rb', line 77 def height @height end |
#width ⇒ Integer
Returns The width-component of this dimension.
74 75 76 |
# File 'lib/chunky_png/dimension.rb', line 74 def width @width end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compares the size of 2 dimensions.
121 122 123 |
# File 'lib/chunky_png/dimension.rb', line 121 def <=>(other) other.area <=> area end |
#area ⇒ Integer
Returns the area of this dimension.
88 89 90 |
# File 'lib/chunky_png/dimension.rb', line 88 def area width * height end |
#eql?(other) ⇒ true, false Also known as: ==
Checks whether 2 dimensions are identical.
104 105 106 107 |
# File 'lib/chunky_png/dimension.rb', line 104 def eql?(other) return false unless other.respond_to?(:width) && other.respond_to?(:height) other.width == width && other.height == height end |
#hash ⇒ Integer
Calculates a hash for the dimension object, based on width and height
113 114 115 |
# File 'lib/chunky_png/dimension.rb', line 113 def hash [width, height].hash end |
#include?(*point_like) ⇒ true, false
Checks whether a point is within bounds of this dimension.
96 97 98 99 |
# File 'lib/chunky_png/dimension.rb', line 96 def include?(*point_like) point = ChunkyPNG::Point(*point_like) point.x >= 0 && point.x < width && point.y >= 0 && point.y < height end |
#to_a ⇒ Array<Integer> Also known as: to_ary
Casts this dimension into an array.
127 128 129 |
# File 'lib/chunky_png/dimension.rb', line 127 def to_a [width, height] end |