Class: Pulo::Cuboid

Inherits:
Object
  • Object
show all
Includes:
Figure3D
Defined in:
lib/pulo/figure/figure3d.rb

Instance Attribute Summary collapse

Attributes included from Figure3D

#surfacearea, #volume

Instance Method Summary collapse

Methods included from Quantity_Checker

#quantity_check

Constructor Details

#initialize(width: nil, height: nil, length: nil, volume: nil, face: nil) ⇒ Cuboid



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/pulo/figure/figure3d.rb', line 61

def initialize(width: nil, height: nil, length: nil, volume: nil, face: nil)
  raise 'Cuboid needs width, length and height or volume and face or length and face.' unless ((width && length && height) || (volume && face) || (length && face))

  @faces=[]
  if width and length and height
    @width=width; @length=length; @height=height
    @faces[0]=Rectangle.new(width: width, height: height)
    @faces[1]=Rectangle.new(width: width, height: length)
    @faces[2]=Rectangle.new(width: length, height: height)
    @volume=@faces[0].area*@length
  end
  if volume and face
    @volume=volume
    @faces[0]=face
    @width=@faces[0].width
    @height=@faces[0].height
    @length=@volume/@faces[0].area
    @faces[1]=Rectangle.new(width: @width, height: @length)
    @faces[2]=Rectangle.new(width: @length, height: @height)
  end
  if face and length
    @faces[0]=face
    @length=length
    @volume=face.area * length
    @width=@faces[0].width
    @height=@faces[0].height
    @faces[1]=Rectangle.new(width: @width, height: @length)
    @faces[2]=Rectangle.new(width: @length, height: @height)
  end
  @surfacearea=(@faces[0].area+@faces[1].area+@faces[2].area)*2
end

Instance Attribute Details

#facesObject (readonly)

Returns the value of attribute faces.



60
61
62
# File 'lib/pulo/figure/figure3d.rb', line 60

def faces
  @faces
end

#heightObject (readonly)

Returns the value of attribute height.



60
61
62
# File 'lib/pulo/figure/figure3d.rb', line 60

def height
  @height
end

#lengthObject (readonly)

Returns the value of attribute length.



60
61
62
# File 'lib/pulo/figure/figure3d.rb', line 60

def length
  @length
end

#widthObject (readonly)

Returns the value of attribute width.



60
61
62
# File 'lib/pulo/figure/figure3d.rb', line 60

def width
  @width
end