Class: Euclidean::Size

Inherits:
Vector
  • Object
show all
Defined in:
lib/euclidean/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)



62
63
64
# File 'lib/euclidean/size.rb', line 62

def x
  @x
end

#yNumber (readonly)

Returns Y-component (height).

Returns:

  • (Number)

    Y-component (height)



67
68
69
# File 'lib/euclidean/size.rb', line 67

def y
  @y
end

#zNumber (readonly)

Returns Z-component (depth).

Returns:

  • (Number)

    Z-component (depth)



72
73
74
# File 'lib/euclidean/size.rb', line 72

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/euclidean/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/euclidean/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



39
40
41
# File 'lib/euclidean/size.rb', line 39

def depth
  z
end

#heightNumber

Returns The size along the Y axis.

Returns:

  • (Number)

    The size along the Y axis



44
45
46
# File 'lib/euclidean/size.rb', line 44

def height
  y
end

#inspectObject



48
49
50
# File 'lib/euclidean/size.rb', line 48

def inspect
  'Size' + @elements.inspect
end

#to_sObject



52
53
54
# File 'lib/euclidean/size.rb', line 52

def to_s
  'Size' + @elements.to_s
end

#widthNumber

Returns The size along the X axis.

Returns:

  • (Number)

    The size along the X axis



57
58
59
# File 'lib/euclidean/size.rb', line 57

def width
  x
end