Class: Moon::AABB

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

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cpos, rad) ⇒ AABB

Returns a new instance of AABB.

Parameters:


14
15
16
17
# File 'lib/moon/packages/std/aabb.rb', line 14

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

Instance Attribute Details

#cposMoon::Vector2 (readonly)

Returns:


6
7
8
# File 'lib/moon/packages/std/aabb.rb', line 6

def cpos
  @cpos
end

#cpos center position(centerposition) ⇒ Moon::Vector2 (readonly)

Returns:


6
# File 'lib/moon/packages/std/aabb.rb', line 6

attr_reader :cpos

#radMoon::Vector2 (readonly)

Returns:


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

def rad
  @rad
end

#rad radii(radii) ⇒ Moon::Vector2 (readonly)

Returns:


10
# File 'lib/moon/packages/std/aabb.rb', line 10

attr_reader :rad

Class Method Details

.create_encompassing(aabbs) ⇒ Object

TODO:

37
38
39
40
41
42
43
44
# File 'lib/moon/packages/std/aabb.rb', line 37

def self.create_encompassing(aabbs)
  cpos = Vector2.zero
  rad = Vector2.zero
  aabbs.each do |aabb|
    #
  end
  new cpos, rad
end

Instance Method Details

#&(other) ⇒ Moon::AABB

Parameters:

Returns:


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

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

#intersect?(other) ⇒ Boolean

Parameters:

Returns:


21
22
23
24
25
# File 'lib/moon/packages/std/aabb.rb', line 21

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)
  true
end