Module: Heuristic

Defined in:
lib/pathfinding/core/heuristic.rb

Overview

A collection of heuristic functions.

Class Method Summary collapse

Class Method Details

.chebyshev(dx, dy) ⇒ Object

Chebyshev distance.



38
39
40
# File 'lib/pathfinding/core/heuristic.rb', line 38

def self.chebyshev(dx, dy)
  [dx, dy].max
end

.euclidean(dx, dy) ⇒ Object

Euclidean distance.



23
24
25
# File 'lib/pathfinding/core/heuristic.rb', line 23

def self.euclidean(dx, dy)
  Math.sqrt(dx * dx + dy * dy)
end

.manhattan(dx, dy) ⇒ Object

Manhattan distance.



16
17
18
# File 'lib/pathfinding/core/heuristic.rb', line 16

def self.manhattan(dx, dy)
  dx + dy
end

.octile(dx, dy) ⇒ Object

Octile distance.



30
31
32
33
# File 'lib/pathfinding/core/heuristic.rb', line 30

def self.octile(dx, dy)
  f = Math.sqrt(2) - 1
  dx < dy ? f * dx + dy : f * dy + dx
end