Class: Sangaku::AABB
- Inherits:
-
Object
- Object
- Sangaku::AABB
- Defined in:
- lib/sangaku/aabb.rb
Instance Method Summary collapse
- #*(scale) ⇒ Object
- #centre!(point = [0, 0]) ⇒ Object
- #h ⇒ Object
-
#initialize(*points) ⇒ AABB
constructor
A new instance of AABB.
- #max ⇒ Object
- #mid ⇒ Object
- #min ⇒ Object
- #square! ⇒ Object
- #to_a ⇒ Object
- #to_grid(count = 5) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #w ⇒ Object
Constructor Details
Instance Method Details
#*(scale) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sangaku/aabb.rb', line 33 def *(scale) mid = @line.mid dx = 0.5 * w * scale dy = 0.5 * h * scale AABB.new([mid.x - dx, mid.y - dy], [mid.x + dx, mid.y + dy]) end |
#centre!(point = [0, 0]) ⇒ Object
19 20 21 22 |
# File 'lib/sangaku/aabb.rb', line 19 def centre!(point = [0, 0]) point = Point.new(*point) if point.is_a?(Array) @line -= (@line.mid - point) end |
#h ⇒ Object
17 |
# File 'lib/sangaku/aabb.rb', line 17 def h; @line.h; end |
#max ⇒ Object
13 |
# File 'lib/sangaku/aabb.rb', line 13 def max; @line.p2; end |
#mid ⇒ Object
14 |
# File 'lib/sangaku/aabb.rb', line 14 def mid; @line.mid; end |
#min ⇒ Object
12 |
# File 'lib/sangaku/aabb.rb', line 12 def min; @line.p1; end |
#square! ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/sangaku/aabb.rb', line 24 def square! mid = @line.mid ds = 0.5 * [w, h].max @line.p1.x = mid.x - ds @line.p1.y = mid.y - ds @line.p2.x = mid.x + ds @line.p2.y = mid.y + ds end |
#to_a ⇒ Object
47 |
# File 'lib/sangaku/aabb.rb', line 47 def to_a; @line.to_a; end |
#to_grid(count = 5) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/sangaku/aabb.rb', line 40 def to_grid(count = 5) raise if count < 2 xs = (min.x..max.x).step(w/(count-1).to_f) ys = (min.y..max.y).step(h/(count-1).to_f) Grid.new(xs.to_a, ys.to_a) end |
#to_s ⇒ Object Also known as: inspect
48 |
# File 'lib/sangaku/aabb.rb', line 48 def to_s; @line.to_s; end |
#w ⇒ Object
16 |
# File 'lib/sangaku/aabb.rb', line 16 def w; @line.w; end |