mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-27 10:13:57 -04:00
AP_Math: use ARRAY_SIZE instead of defining another one
This commit is contained in:
parent
73ff01dc68
commit
fb2eb262e7
libraries/AP_Math/examples
@ -108,15 +108,13 @@ static void test_euler(float roll, float pitch, float yaw)
|
||||
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,
|
||||
-PI/8, -PI/4, -PI/2, -PI};
|
||||
|
||||
void test_matrix_eulers(void)
|
||||
{
|
||||
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");
|
||||
|
||||
@ -155,7 +153,7 @@ static void test_quaternion(float roll, float pitch, float yaw)
|
||||
void test_quaternion_eulers(void)
|
||||
{
|
||||
uint8_t i, j, k;
|
||||
uint8_t N = ARRAY_LENGTH(angles);
|
||||
uint8_t N = ARRAY_SIZE(angles);
|
||||
|
||||
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)
|
||||
{
|
||||
uint8_t i, j, k;
|
||||
uint8_t N = ARRAY_LENGTH(angles);
|
||||
uint8_t N = ARRAY_SIZE(angles);
|
||||
|
||||
hal.console->println("matrix/quaternion tests\n");
|
||||
|
||||
|
@ -66,8 +66,6 @@ static const struct {
|
||||
Vector2f(-2, 2), true },
|
||||
};
|
||||
|
||||
#define ARRAY_LENGTH(x) (sizeof((x))/sizeof((x)[0]))
|
||||
|
||||
static struct Location location_from_point(Vector2f pt)
|
||||
{
|
||||
struct Location loc = {0};
|
||||
@ -79,7 +77,7 @@ static struct Location location_from_point(Vector2f pt)
|
||||
static void test_passed_waypoint(void)
|
||||
{
|
||||
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 wp1 = location_from_point(test_points[i].wp1);
|
||||
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.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_offsets[i].ofs_north,
|
||||
test_offsets[i].ofs_east,
|
||||
|
@ -61,8 +61,6 @@ static const struct {
|
||||
{ Vector2l(-266092111, 1518747419), false },
|
||||
};
|
||||
|
||||
#define ARRAY_LENGTH(x) (sizeof((x))/sizeof((x)[0]))
|
||||
|
||||
/*
|
||||
* polygon tests
|
||||
*/
|
||||
@ -74,20 +72,20 @@ void setup(void)
|
||||
|
||||
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!");
|
||||
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");
|
||||
all_passed = false;
|
||||
}
|
||||
|
||||
for (i=0; i<ARRAY_LENGTH(test_points); i++) {
|
||||
for (i=0; i<ARRAY_SIZE(test_points); i++) {
|
||||
bool result;
|
||||
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"),
|
||||
1.0e-7f*test_points[i].point.x,
|
||||
1.0e-7f*test_points[i].point.y,
|
||||
@ -102,17 +100,17 @@ void setup(void)
|
||||
hal.console->println("Speed test:");
|
||||
start_time = hal.scheduler->micros();
|
||||
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;
|
||||
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) {
|
||||
all_passed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user