Class: Moon::Cuboid

Inherits:
Object show all
Includes:
Serializable, Serializable::Properties
Defined in:
lib/moon/packages/std/cuboid.rb

Defined Under Namespace

Modules: Cast

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cuboid) ⇒ Cuboid #initialize(num) ⇒ Cuboid #initialize(options) ⇒ Cuboid #initialize(position, size) ⇒ Cuboid #initialize(x, y, z, w, h, d) ⇒ Cuboid

Returns a new instance of Cuboid.

Overloads:


75
76
77
78
# File 'lib/moon/packages/std/cuboid.rb', line 75

def initialize(*args)
  clear
  set(*args) unless args.empty?
end

Class Method Details

.[](*objs) ⇒ Object


199
200
201
202
# File 'lib/moon/packages/std/cuboid.rb', line 199

def self.[](*objs)
  obj = objs.size == 1 ? objs.first : objs
  new(*extract(obj))
end

.extract(obj) ⇒ Array<Numeric>

Converts a given Object to Cuboid array

Parameters:

Returns:


195
196
197
# File 'lib/moon/packages/std/cuboid.rb', line 195

def self.extract(obj)
  Cast.extract(obj)
end

Instance Method Details

#==(other) ⇒ Object


80
81
82
83
84
85
86
87
88
# File 'lib/moon/packages/std/cuboid.rb', line 80

def ==(other)
  if other.is_a?(Cuboid)
    return true if equal?(other)
    x == other.x && y == other.y && z == other.z &&
    w == other.w && h == other.h && d == other.d
  else
    false
  end
end

#clearself

Returns:

  • (self)

131
132
133
134
# File 'lib/moon/packages/std/cuboid.rb', line 131

def clear
  @x, @y, @z, @w, @h, @d = 0, 0, 0, 0, 0, 0
  self
end

#contains?(vec3) ⇒ Boolean #contains?(x, y, z) ⇒ Boolean

Overloads:

Returns:


180
181
182
183
184
185
# File 'lib/moon/packages/std/cuboid.rb', line 180

def contains?(*args)
  x, y, z = *Vector3.extract(args.singularize)
  x.between?(self.x, self.x2 - 1) &&
  y.between?(self.y, self.y2 - 1) &&
  z.between?(self.z, self.z2 - 1)
end

#dInteger

Returns:


57
# File 'lib/moon/packages/std/cuboid.rb', line 57

property_accessor :d

#empty?Boolean

Returns:


188
189
190
# File 'lib/moon/packages/std/cuboid.rb', line 188

def empty?
  return w == 0 && h == 0 && d == 0
end

#hInteger

Returns:


55
# File 'lib/moon/packages/std/cuboid.rb', line 55

property_accessor :h

#positionVector3

Returns:


142
143
144
# File 'lib/moon/packages/std/cuboid.rb', line 142

def position
  Vector3.new @x, @y, @z
end

#position=(x, y, z) ⇒ Object #position=(position) ⇒ Object

Moves the Cuboid to the given position

Overloads:


154
155
156
157
# File 'lib/moon/packages/std/cuboid.rb', line 154

def position=(other)
  @x, @y, @z = *Vector3.extract(other)
  self
end

#resize(vec3) ⇒ self #resize(w, h, d) ⇒ self #resize(hash) ⇒ self

Overloads:

Returns:

  • (self)

168
169
170
171
# File 'lib/moon/packages/std/cuboid.rb', line 168

def resize(*args)
  @w, @h, @d = *Vector3.extract(args.singularize)
  self
end

#set(*args) ⇒ Object


136
137
138
139
# File 'lib/moon/packages/std/cuboid.rb', line 136

def set(*args)
  @x, @y, @z, @w, @h, @d = *self.class.extract(args.singularize)
  self
end

#to_aArray<Integer>[6]

Returns:


106
107
108
# File 'lib/moon/packages/std/cuboid.rb', line 106

def to_a
  return @x, @y, @z, @w, @h, @d
end

#to_hHash<Symbol, Integer>

Returns:


111
112
113
# File 'lib/moon/packages/std/cuboid.rb', line 111

def to_h
  properties_to_h
end

#to_rect_xyRect

Returns:


116
117
118
# File 'lib/moon/packages/std/cuboid.rb', line 116

def to_rect_xy
  Moon::Rect.new(@x, @y, @w, @h)
end

#to_rect_xzRect

Returns:


121
122
123
# File 'lib/moon/packages/std/cuboid.rb', line 121

def to_rect_xz
  Moon::Rect.new(@x, @z, @w, @d)
end

#to_rect_yzRect

Returns:


126
127
128
# File 'lib/moon/packages/std/cuboid.rb', line 126

def to_rect_yz
  Moon::Rect.new(@y, @z, @h, @d)
end

#wInteger

Returns:


53
# File 'lib/moon/packages/std/cuboid.rb', line 53

property_accessor :w

#xInteger

Returns:


47
# File 'lib/moon/packages/std/cuboid.rb', line 47

property_accessor :x

#x2Integer

Returns:


91
92
93
# File 'lib/moon/packages/std/cuboid.rb', line 91

def x2
  @x + @w
end

#yInteger

Returns:


49
# File 'lib/moon/packages/std/cuboid.rb', line 49

property_accessor :y

#y2Integer

Returns:


96
97
98
# File 'lib/moon/packages/std/cuboid.rb', line 96

def y2
  @y + @h
end

#zInteger

Returns:


51
# File 'lib/moon/packages/std/cuboid.rb', line 51

property_accessor :z

#z2Integer

Returns:


101
102
103
# File 'lib/moon/packages/std/cuboid.rb', line 101

def z2
  @z + @d
end