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)
-
(-1, 0, 1)
- -1 if the other dimension has a larger area, 1 of this
Parameters:
-
other
(ChunkyPNG::Dimension
) -- The dimension to compare with.
def <=>(other) other.area <=> area end
def area
-
(Integer)
- The area in number of pixels.
def area width * height end
def eql?(other)
-
(true, false)
- true iff width and height match.
Parameters:
-
other
(ChunkyPNG::Dimension
) -- The 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 hash
-
(Integer)
- A hashed value of the dimensions
def hash [width, height].hash end
def include?(*point_like)
- See: ChunkyPNG.Point -
Returns:
-
(true, false)
- True iff the x and y coordinate fall in this dimension.
Parameters:
-
point_like
(ChunkyPNG::Point, ...
) -- A 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)
-
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
-
(Array
- [width, height] for this dimension.)
def to_a [width, height] end