Sha256: f0b09ecd77865723b1888c4b25136c25d5fb41089999c0611fb843c9313f44d2

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

Context::define :CalculateShortestDistance do

  role :tentative_distance_values do end
  role :path do end

  role :current do  end
  role :destination do end


  role :map do
    distance_between do |a, b|
      map.distances[Edge.new(a, b)]
    end

    # These two functions presume always travelling
    # in a southern or easterly direction
    next_down_the_street_from do |x|
      map.east_neighbor_of x
    end

    next_along_the_avenue_from do |x|
      map.south_neighbor_of x
    end
  end

  role :current do
    tentative_distance do
      tentative_distance_values[current]
    end
    set_tentative_distance_to do |x|
      tentative_distance_values[current] = x
    end
  end


  rebind do |origin_node, geometries|
    @current = origin_node
    @destination = geometries.destination
    @map = geometries
  end

  distance do
    current.set_tentative_distance_to 0
    @path = CalculateShortestPath.new(current, destination, map).path
    retval = 0
    previous_node = nil
      path.reverse_each {|node|
        if previous_node.nil?
          retval = 0
        else
          retval += map.distance_between previous_node, node
        end
        previous_node = node
      }
    retval
  end

end

class CalculateShortestDistance
  def initialize(origin_node, geometries)
    rebind(origin_node, geometries)
    @tentative_distance_values = Hash.new
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
maroon-0.6.1 Examples/Dijkstra/CalculateShortestDistance.rb
maroon-0.6.0 Examples/Dijkstra/CalculateShortestDistance.rb
maroon-0.5.3 Examples/Dijkstra/CalculateShortestDistance.rb
maroon-0.5.2 Examples/Dijkstra/CalculateShortestDistance.rb
Moby-0.5.1 Examples/Dijkstra/CalculateShortestDistance.rb
Moby-0.5.0 Examples/Dijkstra/CalculateShortestDistance.rb