Fawkes API  Fawkes Development Version
map.c
1 
2 /***************************************************************************
3  * map.h: Global map (grid-based)
4  *
5  * Created: Thu May 24 18:44:56 2012
6  * Copyright 2000 Brian Gerkey
7  * 2000 Kasper Stoy
8  * 2012 Tim Niemueller [www.niemueller.de]
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL file in the doc directory.
22  */
23 
24 /* From:
25  * Player - One Hell of a Robot Server (LGPL)
26  * Copyright (C) 2000 Brian Gerkey & Kasper Stoy
27  * gerkey@usc.edu kaspers@robotics.usc.edu
28  */
29 /**************************************************************************
30  * Desc: Global map (grid-based)
31  * Author: Andrew Howard
32  * Date: 6 Feb 2003
33  **************************************************************************/
34 
35 #include <math.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <stdio.h>
39 
40 #include "map.h"
41 
42 /// @cond EXTERNAL
43 
44 // Create a new map
45 map_t *map_alloc(void)
46 {
47  map_t *map;
48 
49  map = (map_t*) malloc(sizeof(map_t));
50 
51  // Assume we start at (0, 0)
52  map->origin_x = 0;
53  map->origin_y = 0;
54 
55  // Make the size odd
56  map->size_x = 0;
57  map->size_y = 0;
58  map->scale = 0;
59 
60  // Allocate storage for main map
61  map->cells = (map_cell_t*) NULL;
62 
63  return map;
64 }
65 
66 
67 // Destroy a map
68 void map_free(map_t *map)
69 {
70  free(map->cells);
71  free(map);
72  return;
73 }
74 
75 
76 // Get the cell at the given point
77 map_cell_t *map_get_cell(map_t *map, double ox, double oy, double oa)
78 {
79  int i, j;
80  map_cell_t *cell;
81 
82  i = MAP_GXWX(map, ox);
83  j = MAP_GYWY(map, oy);
84 
85  if (!MAP_VALID(map, i, j))
86  return NULL;
87 
88  cell = map->cells + MAP_INDEX(map, i, j);
89  return cell;
90 }
91 
92 /// @endcond