Class ChunkyPNG::Dimension
In: lib/chunky_png/dimension.rb
Parent: Object

Class that represents the dimension of something, e.g. a {ChunkyPNG::Canvas}.

This class contains some methods to simplify performing dimension related checks.

Methods

<=>   ==   area   eql?   include?   new   to_a   to_ary  

Constants

DIMENSION_REGEXP = /^[\(\[\{]?(\d+)\s*[x,]?\s*(\d+)[\)\]\}]?$/   @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

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.

[Source]

    # File lib/chunky_png/dimension.rb, line 69
69:     def initialize(width, height)
70:       @width, @height = width.to_i, height.to_i
71:     end

Public Instance methods

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.

[Source]

     # File lib/chunky_png/dimension.rb, line 101
101:     def <=>(other)
102:       other.area <=> area
103:     end
==(other)

Alias for eql?

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

[Source]

    # File lib/chunky_png/dimension.rb, line 75
75:     def area
76:       width * height
77:     end

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

[Source]

    # File lib/chunky_png/dimension.rb, line 91
91:     def eql?(other)
92:       other.width == width && other.height == height
93:     end

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

[Source]

    # File lib/chunky_png/dimension.rb, line 83
83:     def include?(*point_like)
84:       point = ChunkyPNG::Point(*point_like)
85:       point.x >= 0 && point.x < width && point.y >= 0 && point.y < height
86:     end

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

[Source]

     # File lib/chunky_png/dimension.rb, line 107
107:     def to_a
108:       [width, height]
109:     end
to_ary()

Alias for to_a

[Validate]