class ChunkyPNG::Dimension

This class contains some methods to simplify performing dimension related checks.
Class that represents the dimension of something, e.g. a {ChunkyPNG::Canvas}.

def <=>(other)

Returns:
  • (-1, 0, 1) - -1 if the other dimension has a larger area, 1 of this

Parameters:
  • The (ChunkyPNG::Dimension) -- dimension to compare with.
def <=>(other)
  other.area <=> area
end

def area

Returns:
  • (Integer) - The area in number of pixels.
def area
  width * height
end

def eql?(other)

Returns:
  • (true, false) - true iff width and height match.

Parameters:
  • The (ChunkyPNG::Dimension) -- dimension to compare with.
def eql?(other)
  return false unless other.respond_to?(:width) && other.respond_to?(:height)
  other.width == width && other.height == height
end

def include?(*point_like)

Other tags:
    See: ChunkyPNG.Point -

Returns:
  • (true, false) - True iff the x and y coordinate fall in this dimension.

Parameters:
  • A (ChunkyPNG::Point, ...) -- point-like to bounds-check.
def include?(*point_like)
  point = ChunkyPNG::Point(*point_like)
  point.x >= 0 && point.x < width && point.y >= 0 && point.y < height
end

def initialize(width, height)

Parameters:
  • height (Integer) -- The height-component of the new dimension.
  • width (Integer) -- The width-component of the new dimension.
def initialize(width, height)
  @width, @height = width.to_i, height.to_i
end

def to_a

Returns:
  • (Array) - [width, height] for this dimension.
def to_a
  [width, height]
end