mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-28 02:33:58 -04:00
AP_Math: use ARRAY_SIZE instead of defining another one
This commit is contained in:
parent
73ff01dc68
commit
fb2eb262e7
@ -108,15 +108,13 @@ static void test_euler(float roll, float pitch, float yaw)
|
|||||||
check_result("test_euler", roll, pitch, yaw, roll2, pitch2, yaw2);
|
check_result("test_euler", roll, pitch, yaw, roll2, pitch2, yaw2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ARRAY_LENGTH(x) (sizeof((x))/sizeof((x)[0]))
|
|
||||||
|
|
||||||
static const float angles[] = { 0, PI/8, PI/4, PI/2, PI,
|
static const float angles[] = { 0, PI/8, PI/4, PI/2, PI,
|
||||||
-PI/8, -PI/4, -PI/2, -PI};
|
-PI/8, -PI/4, -PI/2, -PI};
|
||||||
|
|
||||||
void test_matrix_eulers(void)
|
void test_matrix_eulers(void)
|
||||||
{
|
{
|
||||||
uint8_t i, j, k;
|
uint8_t i, j, k;
|
||||||
uint8_t N = ARRAY_LENGTH(angles);
|
uint8_t N = ARRAY_SIZE(angles);
|
||||||
|
|
||||||
hal.console->println("rotation matrix unit tests\n");
|
hal.console->println("rotation matrix unit tests\n");
|
||||||
|
|
||||||
@ -155,7 +153,7 @@ static void test_quaternion(float roll, float pitch, float yaw)
|
|||||||
void test_quaternion_eulers(void)
|
void test_quaternion_eulers(void)
|
||||||
{
|
{
|
||||||
uint8_t i, j, k;
|
uint8_t i, j, k;
|
||||||
uint8_t N = ARRAY_LENGTH(angles);
|
uint8_t N = ARRAY_SIZE(angles);
|
||||||
|
|
||||||
hal.console->println("quaternion unit tests\n");
|
hal.console->println("quaternion unit tests\n");
|
||||||
|
|
||||||
@ -215,7 +213,7 @@ static void test_conversion(float roll, float pitch, float yaw)
|
|||||||
void test_conversions(void)
|
void test_conversions(void)
|
||||||
{
|
{
|
||||||
uint8_t i, j, k;
|
uint8_t i, j, k;
|
||||||
uint8_t N = ARRAY_LENGTH(angles);
|
uint8_t N = ARRAY_SIZE(angles);
|
||||||
|
|
||||||
hal.console->println("matrix/quaternion tests\n");
|
hal.console->println("matrix/quaternion tests\n");
|
||||||
|
|
||||||
|
@ -66,8 +66,6 @@ static const struct {
|
|||||||
Vector2f(-2, 2), true },
|
Vector2f(-2, 2), true },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ARRAY_LENGTH(x) (sizeof((x))/sizeof((x)[0]))
|
|
||||||
|
|
||||||
static struct Location location_from_point(Vector2f pt)
|
static struct Location location_from_point(Vector2f pt)
|
||||||
{
|
{
|
||||||
struct Location loc = {0};
|
struct Location loc = {0};
|
||||||
@ -79,7 +77,7 @@ static struct Location location_from_point(Vector2f pt)
|
|||||||
static void test_passed_waypoint(void)
|
static void test_passed_waypoint(void)
|
||||||
{
|
{
|
||||||
hal.console->println("waypoint tests starting");
|
hal.console->println("waypoint tests starting");
|
||||||
for (uint8_t i=0; i<ARRAY_LENGTH(test_points); i++) {
|
for (uint8_t i=0; i<ARRAY_SIZE(test_points); i++) {
|
||||||
struct Location loc = location_from_point(test_points[i].location);
|
struct Location loc = location_from_point(test_points[i].location);
|
||||||
struct Location wp1 = location_from_point(test_points[i].wp1);
|
struct Location wp1 = location_from_point(test_points[i].wp1);
|
||||||
struct Location wp2 = location_from_point(test_points[i].wp2);
|
struct Location wp2 = location_from_point(test_points[i].wp2);
|
||||||
@ -135,7 +133,7 @@ static void test_offset(void)
|
|||||||
loc.lat = -35*1.0e7f;
|
loc.lat = -35*1.0e7f;
|
||||||
loc.lng = 149*1.0e7f;
|
loc.lng = 149*1.0e7f;
|
||||||
|
|
||||||
for (uint8_t i=0; i<ARRAY_LENGTH(test_offsets); i++) {
|
for (uint8_t i=0; i<ARRAY_SIZE(test_offsets); i++) {
|
||||||
test_one_offset(loc,
|
test_one_offset(loc,
|
||||||
test_offsets[i].ofs_north,
|
test_offsets[i].ofs_north,
|
||||||
test_offsets[i].ofs_east,
|
test_offsets[i].ofs_east,
|
||||||
|
@ -61,8 +61,6 @@ static const struct {
|
|||||||
{ Vector2l(-266092111, 1518747419), false },
|
{ Vector2l(-266092111, 1518747419), false },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ARRAY_LENGTH(x) (sizeof((x))/sizeof((x)[0]))
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* polygon tests
|
* polygon tests
|
||||||
*/
|
*/
|
||||||
@ -74,20 +72,20 @@ void setup(void)
|
|||||||
|
|
||||||
hal.console->println("polygon unit tests\n");
|
hal.console->println("polygon unit tests\n");
|
||||||
|
|
||||||
if (!Polygon_complete(OBC_boundary, ARRAY_LENGTH(OBC_boundary))) {
|
if (!Polygon_complete(OBC_boundary, ARRAY_SIZE(OBC_boundary))) {
|
||||||
hal.console->println("OBC boundary is not complete!");
|
hal.console->println("OBC boundary is not complete!");
|
||||||
all_passed = false;
|
all_passed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Polygon_complete(OBC_boundary, ARRAY_LENGTH(OBC_boundary)-1)) {
|
if (Polygon_complete(OBC_boundary, ARRAY_SIZE(OBC_boundary)-1)) {
|
||||||
hal.console->println("Polygon_complete test failed");
|
hal.console->println("Polygon_complete test failed");
|
||||||
all_passed = false;
|
all_passed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<ARRAY_LENGTH(test_points); i++) {
|
for (i=0; i<ARRAY_SIZE(test_points); i++) {
|
||||||
bool result;
|
bool result;
|
||||||
result = Polygon_outside(test_points[i].point,
|
result = Polygon_outside(test_points[i].point,
|
||||||
OBC_boundary, ARRAY_LENGTH(OBC_boundary));
|
OBC_boundary, ARRAY_SIZE(OBC_boundary));
|
||||||
hal.console->printf_P(PSTR("%10f,%10f %s %s\n"),
|
hal.console->printf_P(PSTR("%10f,%10f %s %s\n"),
|
||||||
1.0e-7f*test_points[i].point.x,
|
1.0e-7f*test_points[i].point.x,
|
||||||
1.0e-7f*test_points[i].point.y,
|
1.0e-7f*test_points[i].point.y,
|
||||||
@ -102,17 +100,17 @@ void setup(void)
|
|||||||
hal.console->println("Speed test:");
|
hal.console->println("Speed test:");
|
||||||
start_time = hal.scheduler->micros();
|
start_time = hal.scheduler->micros();
|
||||||
for (count=0; count<1000; count++) {
|
for (count=0; count<1000; count++) {
|
||||||
for (i=0; i<ARRAY_LENGTH(test_points); i++) {
|
for (i=0; i<ARRAY_SIZE(test_points); i++) {
|
||||||
bool result;
|
bool result;
|
||||||
result = Polygon_outside(test_points[i].point,
|
result = Polygon_outside(test_points[i].point,
|
||||||
OBC_boundary, ARRAY_LENGTH(OBC_boundary));
|
OBC_boundary, ARRAY_SIZE(OBC_boundary));
|
||||||
if (result != test_points[i].outside) {
|
if (result != test_points[i].outside) {
|
||||||
all_passed = false;
|
all_passed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hal.console->printf("%u usec/call\n", (unsigned)((hal.scheduler->micros()
|
hal.console->printf("%u usec/call\n", (unsigned)((hal.scheduler->micros()
|
||||||
- start_time)/(count*ARRAY_LENGTH(test_points))));
|
- start_time)/(count*ARRAY_SIZE(test_points))));
|
||||||
hal.console->println(all_passed ? "ALL TESTS PASSED" : "TEST FAILED");
|
hal.console->println(all_passed ? "ALL TESTS PASSED" : "TEST FAILED");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user