class AaBb

Axis aligned bounding box class (AABB would clash with Toxicgem)

Attributes

center[R]
extent[R]

Public Class Methods

from_min_max(min:, max:) click to toggle source
# 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
new(center:, extent:) click to toggle source
# File lib/jruby_art/helpers/aabb.rb, line 7
def initialize(center:, extent:)
  @center = center
  @extent = extent
end

Public Instance Methods

contains?(vec) click to toggle source
# 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) { || ... } click to toggle source
# 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) click to toggle source
# File lib/jruby_art/helpers/aabb.rb, line 22
def scale(d)
  @extent *= d
end