Class: Moon::AABBCC

Inherits:
Object show all
Defined in:
lib/moon/packages/std/aabbcc.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cpos, rad) ⇒ AABBCC

Returns a new instance of AABBCC.

Parameters:


10
11
12
13
# File 'lib/moon/packages/std/aabbcc.rb', line 10

def initialize(cpos, rad)
  @cpos = Vector3[cpos]
  @rad = Vector3[rad]
end

Instance Attribute Details

#cposObject (readonly)

Vector3 center position


4
5
6
# File 'lib/moon/packages/std/aabbcc.rb', line 4

def cpos
  @cpos
end

#radObject (readonly)

Vector3 radii


5
6
7
# File 'lib/moon/packages/std/aabbcc.rb', line 5

def rad
  @rad
end

Instance Method Details

#&(other) ⇒ Moon::AABBCC

Parameters:

Returns:


28
29
30
31
32
33
34
# File 'lib/moon/packages/std/aabbcc.rb', line 28

def &(other)
  rx = (@cpos.x - other.cpos.x)
  ry = (@cpos.y - other.cpos.y)
  rz = (@cpos.z - other.cpos.z)
  self.class.new(Vector3.new(@cpos.x + rx/2, @cpos.y + ry/2, @cpos.z + rz/2),
                 Vector3.new(rx, ry, rz))
end

#intersect?(other) ⇒ Boolean

Parameters:

Returns:


18
19
20
21
22
23
# File 'lib/moon/packages/std/aabbcc.rb', line 18

def intersect?(other)
  return false if (@cpos.x - other.cpos.x).abs > (@rad.x + other.rad.x) ||
                  (@cpos.y - other.cpos.y).abs > (@rad.y + other.rad.y) ||
                  (@cpos.z - other.cpos.z).abs > (@rad.z + other.rad.z)
  true
end