Class: PointsToLine

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-doom.rb

Instance Method Summary collapse

Constructor Details

#initialize(points, debug = false) ⇒ PointsToLine

Returns a new instance of PointsToLine.



76
77
78
79
# File 'lib/ruby-doom.rb', line 76

def initialize(points, debug=false)
  @points = points
  @debug = debug
end

Instance Method Details

#lineObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ruby-doom.rb', line 83

def line
  @f = Finder.new(@points, 5, @debug)
  found_so_far = [lower_left]
  current = @f.next(found_so_far[0], found_so_far)
  while found_so_far.size != @points.size - 1 
    found_so_far << current
    puts "Current = " + current.to_s + "; points so far: " + found_so_far.size.to_s unless !@debug
    begin
      current = @f.next(current, found_so_far)
    rescue
      puts "Couldn't find next point, so skipping back to the origin" unless !@debug
      break
    end
  end
  found_so_far << current
end

#lower_leftObject



80
81
82
# File 'lib/ruby-doom.rb', line 80

def lower_left
  @points.min {|a,b| a.distance_to(Point.new(0,0)) <=> b.distance_to(Point.new(0,0)) }
end