Class: Geometry::Size

Inherits:
Vector
  • Object
show all
Defined in:
lib/geometry/size.rb

Overview

An object representing the size of something.

Supports all of the familiar Vector methods as well as a few convenience methods (width, height and depth).

Usage

Constructor

size = Geometry::Size[x,y,z]

Constant Summary

Constants inherited from Vector

Vector::X, Vector::Y, Vector::Z

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Vector

#+@, #-@, #cross

Instance Attribute Details

#xNumber (readonly)

Returns X-component (width).

Returns:

  • (Number)

    X-component (width)



61
62
63
# File 'lib/geometry/size.rb', line 61

def x
  @x
end

#yNumber (readonly)

Returns Y-component (height).

Returns:

  • (Number)

    Y-component (height)



66
67
68
# File 'lib/geometry/size.rb', line 66

def y
  @y
end

#zNumber (readonly)

Returns Z-component (depth).

Returns:

  • (Number)

    Z-component (depth)



71
72
73
# File 'lib/geometry/size.rb', line 71

def z
  @z
end

Class Method Details

.[](x, y, z, ...) ⇒ Size .[](Point) ⇒ Size .[](Size) ⇒ Size .[](Vector) ⇒ Size

Allow vector-style initialization, but override to support copy-init from Vector, Point or another Size

Returns:



27
28
29
30
# File 'lib/geometry/size.rb', line 27

def self.[](*array)
    array = array[0].to_a unless array[0].is_a?(Numeric)
    super *array
end

Instance Method Details

#==(other) ⇒ Object

Allow comparison with an Array, otherwise do the normal thing



33
34
35
36
# File 'lib/geometry/size.rb', line 33

def ==(other)
    return @elements == other if other.is_a?(Array)
    super other
end

#depthNumber

Returns The size along the Z axis.

Returns:

  • (Number)

    The size along the Z axis



46
47
48
# File 'lib/geometry/size.rb', line 46

def depth
    z
end

#heightNumber

Returns The size along the Y axis.

Returns:

  • (Number)

    The size along the Y axis



51
52
53
# File 'lib/geometry/size.rb', line 51

def height
    y
end

#inspectObject



38
39
40
# File 'lib/geometry/size.rb', line 38

def inspect
    'Size' + @elements.inspect
end

#to_sObject



41
42
43
# File 'lib/geometry/size.rb', line 41

def to_s
    'Size' + @elements.to_s
end

#widthNumber

Returns The size along the X axis.

Returns:

  • (Number)

    The size along the X axis



56
57
58
# File 'lib/geometry/size.rb', line 56

def width
    x
end