Sha256: a3d380f1265de0b1c6ad7539e6c064063268fcd817aab2d1aa66f5a95491b343

Contents?: true

Size: 641 Bytes

Versions: 32

Compression:

Stored size: 641 Bytes

Contents

# frozen_string_literal: true
# Axis aligned bounding box class (AABB would clash with Toxicgem)
class AaBb
  attr_reader :center, :extent

  def initialize(center:, extent:)
    @center = center
    @extent = extent
  end

  def self.from_min_max(min:, max:)
    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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
jruby_art-2.2.2 lib/jruby_art/helpers/aabb.rb
jruby_art-2.2.1 lib/jruby_art/helpers/aabb.rb
jruby_art-2.2.0 lib/jruby_art/helpers/aabb.rb
jruby_art-1.7.0 lib/jruby_art/helpers/aabb.rb
jruby_art-2.1.0.pre lib/jruby_art/helpers/aabb.rb
jruby_art-2.0.0.pre lib/jruby_art/helpers/aabb.rb
jruby_art-1.6.4 lib/jruby_art/helpers/aabb.rb
jruby_art-1.6.3 lib/jruby_art/helpers/aabb.rb
jruby_art-1.6.2 lib/jruby_art/helpers/aabb.rb
jruby_art-1.6.1 lib/jruby_art/helpers/aabb.rb
jruby_art-1.6.0 lib/jruby_art/helpers/aabb.rb
jruby_art-1.5.2 lib/jruby_art/helpers/aabb.rb
jruby_art-1.5.1 lib/jruby_art/helpers/aabb.rb
jruby_art-1.5.0 lib/jruby_art/helpers/aabb.rb
jruby_art-1.4.9 lib/jruby_art/helpers/aabb.rb
jruby_art-1.4.8 lib/jruby_art/helpers/aabb.rb
jruby_art-1.4.7 lib/jruby_art/helpers/aabb.rb
jruby_art-1.4.6 lib/jruby_art/helpers/aabb.rb
jruby_art-1.4.5 lib/jruby_art/helpers/aabb.rb
jruby_art-1.4.4 lib/jruby_art/helpers/aabb.rb