class ChunkyPNG::Dimension
Class that represents the dimension of something, e.g. a {ChunkyPNG::Canvas}.
This class contains some methods to simplify performing dimension related checks.
Constants
- DIMENSION_REGEXP
-
@return [Regexp] The regexp to parse dimensions from a string. @private
Attributes
@return [Integer] The height-component of this dimension.
@return [Integer] The width-component of this dimension.
Public Class Methods
Source
# File lib/chunky_png/dimension.rb 82 def initialize(width, height) 83 @width, @height = width.to_i, height.to_i 84 end
Initializes a new dimension instance. @param [Integer] width The width-component of the new dimension. @param [Integer] height The height-component of the new dimension.
Public Instance Methods
Source
# File lib/chunky_png/dimension.rb 121 def <=>(other) 122 other.area <=> area 123 end
Compares the size of 2 dimensions. @param [ChunkyPNG::Dimension] other The dimension to compare with. @return [-1, 0, 1] -1 if the other dimension has a larger area, 1 of this
dimension is larger, 0 if both are identical in size.
Source
# File lib/chunky_png/dimension.rb 88 def area 89 width * height 90 end
Returns the area of this dimension. @return [Integer] The area in number of pixels.
Source
# File lib/chunky_png/dimension.rb 104 def eql?(other) 105 return false unless other.respond_to?(:width) && other.respond_to?(:height) 106 other.width == width && other.height == height 107 end
Checks whether 2 dimensions are identical. @param [ChunkyPNG::Dimension] other The dimension to compare with. @return [true, false] true
iff width and height match.
Source
# File lib/chunky_png/dimension.rb 113 def hash 114 [width, height].hash 115 end
Calculates a hash for the dimension object, based on width and height @return [Integer] A hashed value of the dimensions
Source
# File lib/chunky_png/dimension.rb 96 def include?(*point_like) 97 point = ChunkyPNG::Point(*point_like) 98 point.x >= 0 && point.x < width && point.y >= 0 && point.y < height 99 end
Checks whether a point is within bounds of this dimension. @param [ChunkyPNG::Point, …] point_like A point-like to bounds-check. @return [true, false] True iff the x and y coordinate fall in this dimension. @see ChunkyPNG.Point
Source
# File lib/chunky_png/dimension.rb 127 def to_a 128 [width, height] 129 end
Casts this dimension into an array. @return [Array<Integer>] [width, height]
for this dimension.