Class: ChunkyPNG::Dimension

Inherits:
Object
  • Object
show all
Defined in:
lib/chunky_png/dimension.rb

Overview

Class that represents the dimension of something, e.g. a Canvas.

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

Constant Summary

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Dimension) initialize(width, height)

Initializes a new dimension instance.



69
70
71
# File 'lib/chunky_png/dimension.rb', line 69

def initialize(width, height)
  @width, @height = width.to_i, height.to_i
end

Instance Attribute Details

- (Integer) height



64
65
66
# File 'lib/chunky_png/dimension.rb', line 64

def height
  @height
end

- (Integer) width



61
62
63
# File 'lib/chunky_png/dimension.rb', line 61

def width
  @width
end

Instance Method Details

- (-1, ...) <=>(other)

Compares the size of 2 dimensions.



101
102
103
# File 'lib/chunky_png/dimension.rb', line 101

def <=>(other)
  other.area <=> area
end

- (Integer) area

Returns the area of this dimension.



75
76
77
# File 'lib/chunky_png/dimension.rb', line 75

def area
  width * height
end

- (true, false) eql?(other) Also known as: ==

Checks whether 2 dimensions are identical.



91
92
93
# File 'lib/chunky_png/dimension.rb', line 91

def eql?(other)
  other.width == width && other.height == height
end

- (true, false) include?(*point_like)

Checks whether a point is within bounds of this dimension.

See Also:



83
84
85
86
# File 'lib/chunky_png/dimension.rb', line 83

def include?(*point_like)
  point = ChunkyPNG::Point(*point_like)
  point.x >= 0 && point.x < width && point.y >= 0 && point.y < height
end

- (Array<Integer>) to_a Also known as: to_ary

Casts this dimension into an array.



107
108
109
# File 'lib/chunky_png/dimension.rb', line 107

def to_a
  [width, height]
end