Sha256: 8399380530ab84c5856648e77d6b16638716ee1cae95832479a9d43825e6b3d2

Contents?: true

Size: 661 Bytes

Versions: 14

Compression:

Stored size: 661 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: false

# 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

14 entries across 14 versions & 1 rubygems

Version Path
jruby_art-1.2.5 lib/jruby_art/helpers/aabb.rb
jruby_art-1.2.4 lib/jruby_art/helpers/aabb.rb
jruby_art-1.2.3 lib/jruby_art/helpers/aabb.rb
jruby_art-1.2.2 lib/jruby_art/helpers/aabb.rb
jruby_art-1.2.1 lib/jruby_art/helpers/aabb.rb
jruby_art-1.2.0.pre lib/jruby_art/helpers/aabb.rb
jruby_art-1.1.3 lib/jruby_art/helpers/aabb.rb
jruby_art-1.1.2 lib/jruby_art/helpers/aabb.rb
jruby_art-1.1.1 lib/jruby_art/helpers/aabb.rb
jruby_art-1.1.0 lib/jruby_art/helpers/aabb.rb
jruby_art-1.0.8 lib/jruby_art/helpers/aabb.rb
jruby_art-1.0.7 lib/jruby_art/helpers/aabb.rb
jruby_art-1.0.6 lib/jruby_art/helpers/aabb.rb
jruby_art-1.0.5 lib/jruby_art/helpers/aabb.rb