lib/jruby_art/helpers/aabb.rb in jruby_art-2.2.2 vs lib/jruby_art/helpers/aabb.rb in jruby_art-2.3.0
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
# Axis aligned bounding box class (AABB would clash with Toxicgem)
class AaBb
attr_reader :center, :extent
def initialize(center:, extent:)
@@ -12,18 +13,20 @@
new(center: (min + max) * 0.5, extent: max - min)
end
def position(vec)
return @center = vec unless block_given?
+
@center = vec if yield
end
def scale(d)
@extent *= d
end
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
end