summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorOlivier Lanneluc2013-04-17 01:26:18 +0200
committerNicolas Schodet2013-04-27 00:23:04 +0200
commitf2067b32e290f27fd891bb69e02f71d7226062e0 (patch)
tree383a8e4937a8d0b92f8856035e1ece4e1c66e273 /digital
parent1a30f24ef4b749f5209637487ef88a808d94a7d3 (diff)
Add type weight_t
Diffstat (limited to 'digital')
-rw-r--r--digital/io-hub/src/common-cc/path.cc12
-rw-r--r--digital/io-hub/src/common-cc/path.hh12
2 files changed, 13 insertions, 11 deletions
diff --git a/digital/io-hub/src/common-cc/path.cc b/digital/io-hub/src/common-cc/path.cc
index c8ae6d77..6febd082 100644
--- a/digital/io-hub/src/common-cc/path.cc
+++ b/digital/io-hub/src/common-cc/path.cc
@@ -129,7 +129,7 @@ void Path::add_obstacle(const vect_t &c, uint16_t r, const int nodes)
&& navpoints[navpoints_nb].y <= border_ymax)
{
/* Accept point */
- navweights[navpoints_nb] = (1<<PATH_WEIGHT_PRECISION) + layer * PATH_WEIGHT_STEP;
+ navweights[navpoints_nb] = (1 << PATH_WEIGHT_PRECISION) + (layer * PATH_WEIGHT_STEP);
DPRINTF("Add point %u (%u;%u) w=%u\n",
navpoints_nb, navpoints[navpoints_nb].x, navpoints[navpoints_nb].y, navweights[navpoints_nb]);
navpoints_nb++;
@@ -167,7 +167,7 @@ int Path::find_neighbors(int cur_point, struct astar_neighbor_t *neighbors)
if (i!=cur_point)
{
/* Get segment length */
- uint32_t weight = navweights[i] * (uint32_t)distance_point_point(&navpoints[cur_point], &navpoints[i]);
+ weight_t weight = navweights[i] * (weight_t)distance_point_point(&navpoints[cur_point], &navpoints[i]);
weight >>= PATH_WEIGHT_PRECISION;
DPRINTF("- Node %u (%u;%u) w=%u (%u) ", i, navpoints[i].x, navpoints[i].y, weight, navweights[i]);
@@ -220,7 +220,7 @@ int Path::find_neighbors(int cur_point, struct astar_neighbor_t *neighbors)
return neighbors_nb;
}
-void Path::compute(uint16_t escape)
+void Path::compute(weight_t escape)
{
DPRINTF("** Path compute(start) escape=%u\n", escape);
@@ -266,8 +266,8 @@ void Path::endpoints(const vect_t &src, const vect_t &dst)
DPRINTF("Set path endpoints src=(%u;%u) dst=(%u;%u)\n",
src.x, src.y, dst.x, dst.y);
navpoints[PATH_NAVPOINT_SRC_IDX] = src;
- navweights[PATH_NAVPOINT_SRC_IDX] = (1<<PATH_WEIGHT_PRECISION);
navpoints[PATH_NAVPOINT_DST_IDX] = dst;
+ navweights[PATH_NAVPOINT_SRC_IDX] = (1<<PATH_WEIGHT_PRECISION);
navweights[PATH_NAVPOINT_DST_IDX] = (1<<PATH_WEIGHT_PRECISION);
}
@@ -297,14 +297,14 @@ int Path::get_point_index(const vect_t& point)
return -1;
}
-void Path::prepare_score(const vect_t &src, uint16_t escape)
+void Path::prepare_score(const vect_t &src, weight_t escape)
{
DPRINTF("Path prepare score from src=(%u;%u) escape=%u\n", src.x, src.y, escape);
escape_factor = escape;
astar_dijkstra_prepare(astar_nodes, PATH_NAVPOINTS_NB, get_point_index(src), PATH_NAVPOINT_DST_IDX);
}
-uint16_t Path::get_score(const vect_t &dst)
+weight_t Path::get_score(const vect_t &dst)
{
uint16_t score = astar_dijkstra_finish(astar_nodes, PATH_NAVPOINTS_NB, get_point_index(dst));
DPRINTF("Path get score=%u for dst=(%u;%u)\n", score, dst.x, dst.y);
diff --git a/digital/io-hub/src/common-cc/path.hh b/digital/io-hub/src/common-cc/path.hh
index 58db4623..4a3cb072 100644
--- a/digital/io-hub/src/common-cc/path.hh
+++ b/digital/io-hub/src/common-cc/path.hh
@@ -39,6 +39,8 @@ typedef struct path_obstacle_t
uint16_t r;
} path_obstacle_t;
+typedef uint16_t weight_t;
+
/** Path finding class */
class Path
{
@@ -52,7 +54,7 @@ class Path
/** Set path source and destination */
void endpoints(const vect_t &src, const vect_t &dst);
/** Compute path with the given escape factor */
- void compute(uint16_t escape = 0);
+ void compute(weight_t escape = 0);
/** Return a point vector by index */
vect_t& get_point_vect(const int index);
/** Return a point index */
@@ -63,10 +65,10 @@ class Path
/** Find all neighbors of a given node, fill the astar_neighbor structure */
int find_neighbors(int node, struct astar_neighbor_t *neighbors);
/** Prepare score computation for the given source, with given escape factor */
- void prepare_score(const vect_t &src, uint16_t escape = 0);
+ void prepare_score(const vect_t &src, weight_t escape = 0);
/** Return score for a given destination, using a previous preparation
(also reuse previously given escape factor) */
- uint16_t get_score(const vect_t &dst);
+ weight_t get_score(const vect_t &dst);
private:
/** Add an obstacle on the field */
@@ -94,7 +96,7 @@ class Path
/** Borders, any point outside borders is eliminated. */
const uint16_t border_xmin, border_ymin, border_xmax, border_ymax;
/** Escape factor, 0 if none. */
- uint16_t escape_factor;
+ weight_t escape_factor;
/** List of obstacles. */
path_obstacle_t obstacles[PATH_OBSTACLES_NB];
/** Number of obstacles */
@@ -102,7 +104,7 @@ class Path
/** List of navigation points coordonates */
vect_t navpoints[PATH_NAVPOINTS_NB];
/** List of navigation points weights */
- uint32_t navweights[PATH_NAVPOINTS_NB];
+ weight_t navweights[PATH_NAVPOINTS_NB];
/** Number of navigation points */
int navpoints_nb;
/** List of nodes used for A*. */