Skip to content

Commit db1578d

Browse files
committed
Minor code cleanup, changed applicable CityGraph methods "inherit" their Graph equivalent, updated benchmark to run the 500x500 test
1 parent b177a7f commit db1578d

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

astar.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ var astar = {
158158
function Graph(gridIn, options) {
159159
options = options || {};
160160
this.nodes = [];
161-
this.dirtyNodes=[];
162161
this.diagonal = !!options.diagonal;
163162
this.grid = [];
164163
for (var x = 0; x < gridIn.length; x++) {
@@ -170,23 +169,24 @@ function Graph(gridIn, options) {
170169
this.nodes.push(node);
171170
}
172171
}
173-
this.init(this);
172+
this.init();
174173
}
175174

176-
Graph.prototype.init= function() {
177-
for (var i = 0, len = this.nodes.length; i < len; ++i) {
175+
Graph.prototype.init = function() {
176+
this.dirtyNodes = [];
177+
for (var i = 0; i < this.nodes.length; i++) {
178178
astar.cleanNode(this.nodes[i]);
179179
}
180180
};
181181

182-
Graph.prototype.cleanDirty=function(){
182+
Graph.prototype.cleanDirty = function() {
183183
for (var i = 0; i < this.dirtyNodes.length; i++) {
184184
astar.cleanNode(this.dirtyNodes[i]);
185185
}
186-
this.dirtyNodes.length=0;
186+
this.dirtyNodes = [];
187187
};
188188

189-
Graph.prototype.markDirty=function(node){
189+
Graph.prototype.markDirty = function(node) {
190190
this.dirtyNodes.push(node);
191191
};
192192

benchmark/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="stylesheet" type="text/css" href="../demo/demo.css" />
88
<script type='text/javascript' src='../demo/jquery-1.7.1.min.js'></script>
99
<script type='text/javascript' src='../astar.js'></script>
10-
<script type='text/javascript' src='grid_150x150.js'></script>
10+
<script type='text/javascript' src='grid_500x500.js'></script>
1111
<script type='text/javascript' src='benchmark.js'></script>
1212
</head>
1313
<body>

test/tests.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ test( "GPS Pathfinding", function() {
135135

136136
function CityGraph(data, links) {
137137
this.nodes = [];
138-
this.dirtyNodes = [];
139138
this.links = links;
140139
this.cities = {};
141140

@@ -153,22 +152,11 @@ test( "GPS Pathfinding", function() {
153152
this.init();
154153
}
155154

156-
CityGraph.prototype.init= function() {
157-
for (var i = 0, len = this.nodes.length; i < len; ++i) {
158-
astar.cleanNode(this.nodes[i]);
159-
}
160-
};
161-
CityGraph.prototype.cleanDirty=function(){
162-
for (var i = 0; i < this.dirtyNodes.length; i++) {
163-
astar.cleanNode(this.dirtyNodes[i]);
164-
}
165-
this.dirtyNodes.length=0;
166-
};
155+
CityGraph.prototype.init= Graph.prototype.init;
167156

168-
CityGraph.prototype.markDirty=function(node){
169-
this.dirtyNodes.push(node);
170-
};
157+
CityGraph.prototype.cleanDirty = Graph.prototype.cleanDirty;
171158

159+
CityGraph.prototype.markDirty = Graph.prototype.markDirty;
172160

173161
CityGraph.prototype.neighbors = function (node) {
174162
var neighbors = [],

0 commit comments

Comments
 (0)