Class: ChunkyPNG::Dimension

### Home Classes Methods

### In Files

- lib/chunky_png/dimension.rb

### Parent

Object

### Methods

- ::new
- #<=>
- #==
- #area
- #eql?
- #include?
- #to_a
- #to_ary

### Files

- BENCHMARKING.rdoc
- CHANGELOG.rdoc
- CONTRIBUTING.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ChunkyPNG
- ChunkyPNG::CRCMismatch
- ChunkyPNG::Canvas
- ChunkyPNG::Canvas::Adam7Interlacing
- ChunkyPNG::Canvas::DataUrlExporting
- ChunkyPNG::Canvas::DataUrlImporting
- ChunkyPNG::Canvas::Drawing
- ChunkyPNG::Canvas::Masking
- ChunkyPNG::Canvas::Operations
- ChunkyPNG::Canvas::PNGDecoding
- ChunkyPNG::Canvas::PNGEncoding
- ChunkyPNG::Canvas::Resampling
- ChunkyPNG::Canvas::StreamExporting
- ChunkyPNG::Canvas::StreamImporting
- ChunkyPNG::Chunk
- ChunkyPNG::Chunk::Base
- ChunkyPNG::Chunk::CompressedText
- ChunkyPNG::Chunk::End
- ChunkyPNG::Chunk::Generic
- ChunkyPNG::Chunk::Header
- ChunkyPNG::Chunk::ImageData
- ChunkyPNG::Chunk::InternationalText
- ChunkyPNG::Chunk::Palette
- ChunkyPNG::Chunk::Text
- ChunkyPNG::Chunk::Transparency
- ChunkyPNG::Color
- ChunkyPNG::Datastream
- ChunkyPNG::Dimension
- ChunkyPNG::Exception
- ChunkyPNG::ExpectationFailed
- ChunkyPNG::Image
- ChunkyPNG::NotSupported
- ChunkyPNG::OutOfBounds
- ChunkyPNG::Palette
- ChunkyPNG::Point
- ChunkyPNG::RMagick
- ChunkyPNG::SignatureMismatch
- ChunkyPNG::Vector
- Enumerable
- String

No matching classes.

# 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, line 81
    def initialize(width, height)
      @width, @height = width.to_i, height.to_i
    end

### Public Instance Methods

<=>(other) click to toggle source

Compares the size of 2 dimensions. @param [ChunkyPNG::Dimension] 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, line 114
    def <=>(other)
      other.area <=> area
    end

==(other) click to toggle source
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, line 87
    def area
      width * height
    end

eql?(other) click to toggle source

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

    # File lib/chunky_png/dimension.rb, line 103
    def eql?(other)
      return false unless other.respond_to?(:width) && other.respond_to?(:height)
      other.width == width && other.height == height
    end

Also aliased as: ==
include?(*point_like) click to toggle source

Checks whether a point is within bounds of this dimension. @param [ChunkyPNG::Point, ...] 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, line 95
    def include?(*point_like)
      point = ChunkyPNG::Point(*point_like)
      point.x >= 0 && point.x < width && point.y >= 0 && point.y < height
    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, line 120
    def to_a
      [width, height]
    end

Also aliased as: to_ary
to_ary() click to toggle source
Alias for: to_a

[Validate]

Generated with the Darkfish Rdoc Generator 2.