From f4bd3cb5a20a168e1fcbdf9e595196803280e870 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 15 Dec 2011 14:42:34 +1100 Subject: [PATCH] AP_Math: added Polygon_complete() function used to veryify user supplied boundaries --- libraries/AP_Math/examples/polygon/polygon.pde | 12 +++++++++++- libraries/AP_Math/polygon.cpp | 12 ++++++++++++ libraries/AP_Math/polygon.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Math/examples/polygon/polygon.pde b/libraries/AP_Math/examples/polygon/polygon.pde index ff3c6432e8..339ec996ea 100644 --- a/libraries/AP_Math/examples/polygon/polygon.pde +++ b/libraries/AP_Math/examples/polygon/polygon.pde @@ -55,6 +55,16 @@ void setup(void) Serial.begin(115200); Serial.println("polygon unit tests\n"); + if (!Polygon_complete(OBC_boundary, ARRAY_LENGTH(OBC_boundary))) { + Serial.println("OBC boundary is not complete!"); + all_passed = false; + } + + if (Polygon_complete(OBC_boundary, ARRAY_LENGTH(OBC_boundary)-1)) { + Serial.println("Polygon_complete test failed"); + all_passed = false; + } + for (i=0; i= 4 && V[n-1].x == V[0].x && V[n-1].y == V[0].y); +} diff --git a/libraries/AP_Math/polygon.h b/libraries/AP_Math/polygon.h index 1ae785db09..f536ebdfe8 100644 --- a/libraries/AP_Math/polygon.h +++ b/libraries/AP_Math/polygon.h @@ -18,4 +18,5 @@ */ bool Polygon_outside(const Vector2f *P, const Vector2f *V, unsigned n); +bool Polygon_complete(const Vector2f *V, unsigned n);