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

height[RW]

@return [Integer] The height-component of this dimension.

width[RW]

@return [Integer] The width-component of this dimension.

Public Class Methods

new(width, height) click to toggle source

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.

   # File lib/chunky_png/dimension.rb
82 def initialize(width, height)
83   @width, @height = width.to_i, height.to_i
84 end

Public Instance Methods

<=>(other) click to toggle source

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.
    # File lib/chunky_png/dimension.rb
121 def <=>(other)
122   other.area <=> area
123 end
==(other)
Alias for: eql?
area() click to toggle source

Returns the area of this dimension. @return [Integer] The area in number of pixels.

   # File lib/chunky_png/dimension.rb
88 def area
89   width * height
90 end
eql?(other) click to toggle source

Checks whether 2 dimensions are identical. @param [ChunkyPNG::Dimension] other The dimension to compare with. @return [true, false] true iff width and height match.

    # 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
Also aliased as: ==
hash() click to toggle source

Calculates a hash for the dimension object, based on width and height @return [Integer] A hashed value of the dimensions

    # File lib/chunky_png/dimension.rb
113 def hash
114   [width, height].hash
115 end
include?(*point_like) click to toggle source

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

   # 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
to_a() click to toggle source

Casts this dimension into an array. @return [Array<Integer>] [width, height] for this dimension.

    # File lib/chunky_png/dimension.rb
127 def to_a
128   [width, height]
129 end
Also aliased as: to_ary
to_ary()
Alias for: to_a