Class: AaBb
- Inherits:
-
Object
- Object
- AaBb
- Defined in:
- lib/jruby_art/helpers/aabb.rb
Overview
Axis aligned bounding box class (AABB would clash with Toxicgem)
Instance Attribute Summary collapse
-
#center ⇒ Object
readonly
Returns the value of attribute center.
-
#extent ⇒ Object
readonly
Returns the value of attribute extent.
Class Method Summary collapse
Instance Method Summary collapse
- #contains?(vec) ⇒ Boolean
-
#initialize(center:, extent:) ⇒ AaBb
constructor
A new instance of AaBb.
- #position(vec) ⇒ Object
- #scale(d) ⇒ Object
Constructor Details
#initialize(center:, extent:) ⇒ AaBb
Returns a new instance of AaBb.
7 8 9 10 |
# File 'lib/jruby_art/helpers/aabb.rb', line 7 def initialize(center:, extent:) @center = center @extent = extent end |
Instance Attribute Details
#center ⇒ Object (readonly)
Returns the value of attribute center.
5 6 7 |
# File 'lib/jruby_art/helpers/aabb.rb', line 5 def center @center end |
#extent ⇒ Object (readonly)
Returns the value of attribute extent.
5 6 7 |
# File 'lib/jruby_art/helpers/aabb.rb', line 5 def extent @extent end |
Class Method Details
.from_min_max(min:, max:) ⇒ Object
12 13 14 |
# File 'lib/jruby_art/helpers/aabb.rb', line 12 def self.from_min_max(min:, max:) new(center: (min + max) * 0.5, extent: max - min) end |
Instance Method Details
#contains?(vec) ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/jruby_art/helpers/aabb.rb', line 26 def contains?(vec) rad = extent * 0.5 return false unless (center.x - rad.x..center.x + rad.x).cover? vec.x (center.y - rad.y..center.y + rad.y).cover? vec.y end |
#position(vec) ⇒ Object
16 17 18 19 20 |
# File 'lib/jruby_art/helpers/aabb.rb', line 16 def position(vec) return @center = vec unless block_given? @center = vec if yield end |
#scale(d) ⇒ Object
22 23 24 |
# File 'lib/jruby_art/helpers/aabb.rb', line 22 def scale(d) @extent *= d end |