Sha256: 10026f77283856c8de7a6992b302e323297a36e134e0eec4a81eb383e725ce62

Contents?: true

Size: 954 Bytes

Versions: 7

Compression:

Stored size: 954 Bytes

Contents

class TuioPoint
  attr_accessor :x_pos, :y_pos, :updated_at
  
  def initialize( x_pos, y_pos )
    @x_pos, @y_pos = x_pos, y_pos
  end
  
  def update( x_pos, y_pos )
    @x_pos, @y_pos = x_pos, y_pos
  
    clear_update_time
  end
  
  def distance_to( another_point )
    dx = @x_pos - another_point.x_pos
    dy = @y_pos - another_point.y_pos
    
    Math.sqrt( dx*dx + dy*dy )
  end
  
  def radians_to( another_point )
    side =   another_point.x_pos - @x_pos
    height = another_point.y_pos - @y_pos
    distance = distance_to( another_point )
    
    angle = Math.asin( side / distance ) + Math::PI / 2 
    angle = 2.0 * Math.PI - angle if height < 0 
    angle
  end
  
  def degrees_to( another_point )
    ( radians_to( another_point ) / Math::PI ) * 180.0
  end
  
  def eql?( another_point )
    @x_pos == another_point.x_pos &&
    @y_pos == another_point.y_pos
  end
  
private

  def clear_update_time
    @updated_at = nil
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
aberant-tuio-ruby-0.1.0 lib/tuio_point.rb
aberant-tuio-ruby-0.2.0 lib/tuio_point.rb
aberant-tuio-ruby-0.2.1 lib/tuio-ruby/tuio_point.rb
tuio-ruby-0.2.5 lib/tuio-ruby/tuio_point.rb
tuio-ruby-0.2.4 lib/tuio-ruby/tuio_point.rb
tuio-ruby-0.2.3 lib/tuio-ruby/tuio_point.rb
tuio-ruby-0.2.2 lib/tuio-ruby/tuio_point.rb