class Sangaku::AABB

Public Class Methods

new(*points) click to toggle source
# File lib/sangaku/aabb.rb, line 5
def initialize(*points)
  points = Point::convert(points)
  xs = points.map { |p| p.x }
  ys = points.map { |p| p.y }
  @line = Line.new([xs.min || 0, ys.min || 0], [xs.max || 0, ys.max || 0])
end

Public Instance Methods

*(scale) click to toggle source
# 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]) click to toggle source
# 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() click to toggle source
# File lib/sangaku/aabb.rb, line 17
def h; @line.h; end
inspect()
Alias for: to_s
max() click to toggle source
# File lib/sangaku/aabb.rb, line 13
def max; @line.p2; end
mid() click to toggle source
# File lib/sangaku/aabb.rb, line 14
def mid; @line.mid; end
min() click to toggle source
# File lib/sangaku/aabb.rb, line 12
def min; @line.p1; end
square!() click to toggle source
# 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() click to toggle source
# File lib/sangaku/aabb.rb, line 47
def to_a; @line.to_a; end
to_grid(count = 5) click to toggle source
# 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() click to toggle source
# File lib/sangaku/aabb.rb, line 48
def to_s; @line.to_s; end
Also aliased as: inspect
w() click to toggle source
# File lib/sangaku/aabb.rb, line 16
def w; @line.w; end