32 #define MAP_X(map, index) (map.landmarks[(index * 2)]);
33 #define MAP_Y(map, index) (map.landmarks[(index * 2) + 1]);
49 ArrayBuild(map.landmarks, landmarks);
57 ArrayBuild(map.landmarks, x, y);
65 return ArrayLen(map.landmarks)/2;
75 x = MAP_X(map, index);
76 y = MAP_Y(map, index);
94 int maxAngle,
Vector &retLandmark)
96 long minDistance = 20000000;
99 int flipCheck =
false;
100 int angleDiff = maxAngle;
102 if (minAngle > maxAngle) flipCheck =
true;
105 for (
int i = 0; i < size; i++)
112 if (flipCheck ==
false && (angle >= minAngle && angle <= maxAngle) &&
113 distance < minDistance)
116 minDistance = distance;
118 else if (flipCheck ==
true && (angle >= minAngle || angle <= maxAngle) &&
119 distance < minDistance)
122 minDistance = distance;
142 int minAngle,
int maxAngle,
155 int angleDiff = maxAngle;
169 if (found1 ==
false && found2 ==
false)
171 if (found1 ==
true && found2 ==
true)
201 long minDistance = 2000000000;
205 if (size <= 0)
return false;
207 for (
int i = 0; i < size; i++)
213 if (distance > minDistance)
215 minDistance = distance;
224 long testLandmarks[4] = {250, 250, 250, -250, -250, 250, -250, -250};
229 Vector reference, detectedObject, landmark1, landmark2;
236 TEST((found ==
true),
"No landmark at 45");
237 TEST((detectedObject.
x == 250 && detectedObject.
y == 250),
242 TEST((found ==
true),
"No landmark at 135");
243 TEST((detectedObject.
x == -250 && detectedObject.
y == 250),
248 TEST((found ==
true),
"No landmark at 225");
249 TEST((detectedObject.
x == -250 && detectedObject.
y == -250),
254 TEST((found ==
true),
"No landmark at 315");
255 TEST((detectedObject.
x == 250 && detectedObject.
y == -250),
259 landmark1, landmark2);
260 TEST((found ==
true),
"landmark tri at 0");
261 TEST((landmark1.
x == 250 && landmark1.
y == -250),
263 TEST((landmark2.
x == 250 && landmark2.
y == 250),
267 landmark1, landmark2);
268 TEST((found ==
true),
"landmark tri at 90");
269 TEST((landmark1.
x == 250 && landmark1.
y == 250),
271 TEST((landmark2.
x == -250 && landmark2.
y == 250),
275 landmark1, landmark2);
276 TEST((found ==
true),
"landmark tri at 90");
277 TEST((landmark1.
x == -250 && landmark1.
y == 250),
279 TEST((landmark2.
x == -250 && landmark2.
y == -250),
283 landmark1, landmark2);
284 TEST((found ==
true),
"landmark tri at 90");
285 TEST((landmark1.
x == -250 && landmark1.
y == -250),
287 TEST((landmark2.
x == 250 && landmark2.
y == -250),
void MapArrayLandmarks(Map &map, long &landmarks[])
Initializes the Map with an array of landmarks. The array has alternate x and y positions of the land...
A vector that represents a 2D point by x-y coordinates and a direction angle.
void MapGetLandmark(Map &map, int index, Vector &vec)
Gets a landmark at the given index and returns it in the provide vector.
void MapAddLandMark(Map &map, int x, int y)
Adds a landmark (x,y) to the map.
long VectorGetDistanceVec(Vector &a, Vector &b)
Gets the distance between given two vectors.
long VectorGetDistance(Vector &a)
Gets the polar distance of the given vector. It's the distance of its x-y coordicate from origin...
int AngleAbsAdd(int absAngleA, int angle)
Adds angle to an absolute angle (0 .. 360) absAngleA. Returns an absolute angle properly truncated to...
A simple 3-components vector implementation (2D point + direction)
Map class to hold a collection of landmarks.
void VectorSubtract(Vector &a, Vector &b)
Subtracts vector b from a. i.e. a -= b.
int MapGetNumLandmarks(Map &map)
Returns the number of landmarks currently present in the map.
bool MapFindNearestLandmark(Map &map, Vector &reference, Vector &retLandmark)
Finds the nearest landmard around the reference vector.
bool MapFindTriangulationLandmarks(Map &map, Vector &reference, int minAngle, int maxAngle, Vector &landmark1, Vector &landmark2)
Finds two nearest landmarks around the reference vector within the bounds of given minAngle and maxAn...
Provides simple arithmetic for absolute and relative angles.
bool MapFindNearestLandmarkAtAngle(Map &map, Vector &reference, int minAngle, int maxAngle, Vector &retLandmark)
Finds the nearest landmark around the reference vector within the bounds of given minAngle and maxAng...
int AngleAbsSub(int absAngleA, int angle)
Subtracts angle from an absolute angle (0 .. 360) absAngleA. Returns an absolute angle properly trunc...
Display functions for text and graphs.
long VectorGetAngleVec(Vector &a, Vector &b)
Gets the angle of the line formed by the given two vectors.
void VectorInit(Vector &a, long x, long y, long theta)
Initializes the vector with given x, y and theta components.