2011-12-14 23:34:58 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
//
|
2011-12-19 05:52:59 -04:00
|
|
|
// Unit tests for the AP_Math polygon code
|
2011-12-14 23:34:58 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#include <AP_Common.h>
|
2012-10-27 00:55:17 -03:00
|
|
|
#include <AP_Progmem.h>
|
2012-08-20 20:22:44 -03:00
|
|
|
#include <AP_Param.h>
|
2014-08-13 09:12:04 -03:00
|
|
|
#include <StorageManager.h>
|
2011-12-14 23:34:58 -04:00
|
|
|
#include <AP_Math.h>
|
2012-09-18 15:08:18 -03:00
|
|
|
#include <AP_HAL.h>
|
|
|
|
#include <AP_HAL_AVR.h>
|
2014-07-29 02:49:38 -03:00
|
|
|
#include <AP_HAL_Linux.h>
|
2011-12-14 23:34:58 -04:00
|
|
|
|
2012-12-18 21:26:58 -04:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;
|
2011-12-14 23:34:58 -04:00
|
|
|
|
|
|
|
/*
|
2012-08-17 03:20:14 -03:00
|
|
|
* this is the boundary of the 2010 outback challenge
|
|
|
|
* Note that the last point must be the same as the first for the
|
|
|
|
* Polygon_outside() algorithm
|
2011-12-14 23:34:58 -04:00
|
|
|
*/
|
2011-12-15 22:48:15 -04:00
|
|
|
static const Vector2l OBC_boundary[] = {
|
|
|
|
Vector2l(-265695640, 1518373730),
|
|
|
|
Vector2l(-265699560, 1518394050),
|
|
|
|
Vector2l(-265768230, 1518411420),
|
|
|
|
Vector2l(-265773080, 1518403440),
|
|
|
|
Vector2l(-265815110, 1518419500),
|
|
|
|
Vector2l(-265784860, 1518474690),
|
|
|
|
Vector2l(-265994890, 1518528860),
|
|
|
|
Vector2l(-266092110, 1518747420),
|
|
|
|
Vector2l(-266454780, 1518820530),
|
|
|
|
Vector2l(-266435720, 1518303500),
|
|
|
|
Vector2l(-265875990, 1518344050),
|
|
|
|
Vector2l(-265695640, 1518373730)
|
2011-12-14 23:34:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
2011-12-15 22:48:15 -04:00
|
|
|
Vector2l point;
|
|
|
|
bool outside;
|
2011-12-14 23:34:58 -04:00
|
|
|
} test_points[] = {
|
2011-12-15 22:48:15 -04:00
|
|
|
{ Vector2l(-266398870, 1518220000), true },
|
|
|
|
{ Vector2l(-266418700, 1518709260), false },
|
|
|
|
{ Vector2l(-350000000, 1490000000), true },
|
|
|
|
{ Vector2l(0, 0), true },
|
|
|
|
{ Vector2l(-265768150, 1518408250), false },
|
|
|
|
{ Vector2l(-265774060, 1518405860), true },
|
|
|
|
{ Vector2l(-266435630, 1518303440), true },
|
|
|
|
{ Vector2l(-266435650, 1518313540), false },
|
|
|
|
{ Vector2l(-266435690, 1518303530), false },
|
|
|
|
{ Vector2l(-266435690, 1518303490), true },
|
2011-12-19 03:51:13 -04:00
|
|
|
{ Vector2l(-265875990, 1518344049), true },
|
|
|
|
{ Vector2l(-265875990, 1518344051), false },
|
|
|
|
{ Vector2l(-266454781, 1518820530), true },
|
|
|
|
{ Vector2l(-266454779, 1518820530), true },
|
|
|
|
{ Vector2l(-266092109, 1518747420), true },
|
|
|
|
{ Vector2l(-266092111, 1518747420), false },
|
|
|
|
{ Vector2l(-266092110, 1518747421), true },
|
|
|
|
{ Vector2l(-266092110, 1518747419), false },
|
|
|
|
{ Vector2l(-266092111, 1518747421), true },
|
|
|
|
{ Vector2l(-266092109, 1518747421), true },
|
|
|
|
{ Vector2l(-266092111, 1518747419), false },
|
2011-12-14 23:34:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ARRAY_LENGTH(x) (sizeof((x))/sizeof((x)[0]))
|
|
|
|
|
|
|
|
/*
|
2012-08-17 03:20:14 -03:00
|
|
|
* polygon tests
|
2011-12-14 23:34:58 -04:00
|
|
|
*/
|
|
|
|
void setup(void)
|
|
|
|
{
|
2011-12-15 22:48:15 -04:00
|
|
|
unsigned i, count;
|
2011-12-14 23:34:58 -04:00
|
|
|
bool all_passed = true;
|
|
|
|
uint32_t start_time;
|
|
|
|
|
2012-09-18 15:08:18 -03:00
|
|
|
hal.console->println("polygon unit tests\n");
|
2011-12-14 23:34:58 -04:00
|
|
|
|
2011-12-14 23:42:34 -04:00
|
|
|
if (!Polygon_complete(OBC_boundary, ARRAY_LENGTH(OBC_boundary))) {
|
2012-09-18 15:08:18 -03:00
|
|
|
hal.console->println("OBC boundary is not complete!");
|
2011-12-14 23:42:34 -04:00
|
|
|
all_passed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Polygon_complete(OBC_boundary, ARRAY_LENGTH(OBC_boundary)-1)) {
|
2012-09-18 15:08:18 -03:00
|
|
|
hal.console->println("Polygon_complete test failed");
|
2011-12-14 23:42:34 -04:00
|
|
|
all_passed = false;
|
|
|
|
}
|
|
|
|
|
2011-12-14 23:34:58 -04:00
|
|
|
for (i=0; i<ARRAY_LENGTH(test_points); i++) {
|
|
|
|
bool result;
|
2012-09-18 15:08:18 -03:00
|
|
|
result = Polygon_outside(test_points[i].point,
|
|
|
|
OBC_boundary, ARRAY_LENGTH(OBC_boundary));
|
|
|
|
hal.console->printf_P(PSTR("%10f,%10f %s %s\n"),
|
2011-12-15 22:48:15 -04:00
|
|
|
1.0e-7*test_points[i].point.x,
|
|
|
|
1.0e-7*test_points[i].point.y,
|
2012-08-17 03:20:14 -03:00
|
|
|
result ? "OUTSIDE" : "INSIDE ",
|
|
|
|
result == test_points[i].outside ? "PASS" : "FAIL");
|
2011-12-14 23:34:58 -04:00
|
|
|
if (result != test_points[i].outside) {
|
|
|
|
all_passed = false;
|
|
|
|
}
|
|
|
|
}
|
2012-09-18 15:08:18 -03:00
|
|
|
hal.console->println(all_passed ? "TEST PASSED" : "TEST FAILED");
|
2011-12-14 23:34:58 -04:00
|
|
|
|
2012-09-18 15:08:18 -03:00
|
|
|
hal.console->println("Speed test:");
|
|
|
|
start_time = hal.scheduler->micros();
|
2011-12-14 23:34:58 -04:00
|
|
|
for (count=0; count<1000; count++) {
|
|
|
|
for (i=0; i<ARRAY_LENGTH(test_points); i++) {
|
|
|
|
bool result;
|
2012-09-18 15:08:18 -03:00
|
|
|
result = Polygon_outside(test_points[i].point,
|
|
|
|
OBC_boundary, ARRAY_LENGTH(OBC_boundary));
|
2011-12-14 23:34:58 -04:00
|
|
|
if (result != test_points[i].outside) {
|
|
|
|
all_passed = false;
|
|
|
|
}
|
|
|
|
}
|
2012-08-17 03:20:14 -03:00
|
|
|
}
|
2012-09-18 15:08:18 -03:00
|
|
|
hal.console->printf("%u usec/call\n", (unsigned)((hal.scheduler->micros()
|
|
|
|
- start_time)/(count*ARRAY_LENGTH(test_points))));
|
|
|
|
hal.console->println(all_passed ? "ALL TESTS PASSED" : "TEST FAILED");
|
2011-12-14 23:34:58 -04:00
|
|
|
}
|
|
|
|
|
2012-09-18 15:08:18 -03:00
|
|
|
void loop(void){}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|