chingu-pathfinding 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e40cf76e8b0907e849089d8e76da75a54e25843
4
- data.tar.gz: 616929d9dcf559c235cc0b7c9f7efa57a3dcf015
3
+ metadata.gz: 8858650c171257bdd67fb05a33dd949d39571085
4
+ data.tar.gz: d4752cef76413e77f5eed22aa64826688c90b222
5
5
  SHA512:
6
- metadata.gz: a2d9d6bb0c64c695809d717ecdb7b7a525a88da92506650379dd6102058ae39b2723beaf9d31d8c13034a8316d1bde981253e2db997bf65492a39e7a67d701e4
7
- data.tar.gz: 96c63f137ddfb6327da4dee754dd7b04a59f1aa79e55373f2b27303cbebb70f0d7f713c48a72a7a526294a97b07cba05751bfe59d80e6c7e7d98706df6bdb20c
6
+ metadata.gz: ec0100d0ac4eb14e8e76121b3c2949310971a6bf9ce825580c0e6d12300c667a29f3c20750436d97212b71342b918db2f22e5689283c2e8da061320cabbb2856
7
+ data.tar.gz: 16617428a3c769015618d6b89579a525f15dc65db5ad0a73a10b64257489807ed0e6b80a3aa896058ca4539fd96b32856244775a694d2cbe356993c0a337be8b
@@ -9,6 +9,7 @@
9
9
  #include <functional>
10
10
  #include <stdexcept>
11
11
  #include <sstream>
12
+ #include <limits>
12
13
 
13
14
  static void Init_pathfinding();
14
15
 
@@ -37,16 +38,16 @@ struct point_t {
37
38
  };
38
39
  typedef std::pair<long int, long int> location_t;
39
40
 
40
- long int dist(const location_t& a, const location_t& b) {
41
- long int dx = a.first-b.first;
42
- long int dy = a.second-b.second;
43
- return std::abs(dx) + std::abs(dy);
41
+ float dist(const location_t& a, const location_t& b) {
42
+ float dx = a.first-b.first;
43
+ float dy = a.second-b.second;
44
+ return std::sqrt(dx*dx + dy*dy);
44
45
  }
45
46
 
46
47
  class path_t {
47
48
  std::map< location_t, point_t >* map_p;
48
49
  std::multimap< location_t, location_t >* connectivity_p;
49
- long int cost_paid;
50
+ float cost_paid;
50
51
 
51
52
  public:
52
53
  std::vector<location_t> path;
@@ -55,7 +56,7 @@ class path_t {
55
56
  path_t(std::map< location_t, point_t >* mm,
56
57
  std::multimap< location_t, location_t >* cc)
57
58
  : map_p(mm), connectivity_p(cc), cost_paid(0), path() { }
58
- long int get_cost_paid() const { return cost_paid; }
59
+ float get_cost_paid() const { return cost_paid; }
59
60
  void add_loc(location_t l, const location_t& goal) {
60
61
  if (!path.empty()) {
61
62
  location_t last = *path.crbegin();
@@ -63,7 +64,7 @@ class path_t {
63
64
  }
64
65
  path.push_back(l);
65
66
  }
66
- long int dist_to(const location_t& goal) const {
67
+ float dist_to(const location_t& goal) const {
67
68
  return dist(*path.crbegin(), goal);
68
69
  }
69
70
 
@@ -98,6 +99,7 @@ class pathfinder_t {
98
99
  }
99
100
 
100
101
  bool line_blocked(const long int x1, const long int y1, const long int x2, const long int y2) {
102
+ if (block_size == 1) return false;
101
103
  long int dx = dir(x1, x2);
102
104
  long int dy = dir(y1, y2);
103
105
  long int runner_x = x1;
@@ -169,14 +171,20 @@ class pathfinder_t {
169
171
  init_path.add_loc(start, goal);
170
172
  // Cut out the part of the path already visited
171
173
  bool drop = true;
174
+ float last_dist = std::numeric_limits<float>::max();
172
175
  for (location_t l : current) {
173
- if (dist(l, start) < block_size) {
176
+ float d = dist(l, start);
177
+ if (d > last_dist) {
174
178
  drop = false;
175
179
  }
176
180
  if (!drop && start != l) {
177
181
  init_path.add_loc(l, goal);
178
182
  queue.push(init_path);
179
183
  }
184
+ last_dist = d;
185
+ }
186
+ if (queue.empty()) {
187
+ queue.push(init_path);
180
188
  }
181
189
  // Add every prefix of current to initial guess and converge to new location.
182
190
  return find_path_internal(queue, goal);
@@ -1,5 +1,5 @@
1
1
  class Pathfinding
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  def find_path(x1, y1, x2, y2)
4
4
  throw "Require points to be numeric, got #{[x1, y1, x2, y2]}." unless [x1,y1,x2,y2].all? {|x| x.kind_of?(Numeric)}
5
5
  _find_path(x1, y1, x2, y2)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu-pathfinding
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zombiecalypse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-08 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Find paths C supported on a static map with the A* algorithm.
14
14
  email: maergil@gmail.com