AP_Math: correct Polygon_outside floating point instatiation

This routine was entemplatificated from the integer version, which was
designed to be perfect across representable ranges of points.  The
floating point version suffered from a rounding problem.
This commit is contained in:
Peter Barker 2019-05-27 10:24:24 +10:00 committed by Andrew Tridgell
parent b35b65eed1
commit 51a0401383

View File

@ -59,16 +59,32 @@ bool Polygon_outside(const Vector2<T> &P, const Vector2<T> *V, unsigned n)
outside = !outside;
} else if (m1 < m2) {
continue;
} else if ( dx1 * (int64_t)dy2 > dx2 * (int64_t)dy1 ) {
outside = !outside;
} else {
if (std::is_floating_point<T>::value) {
if ( dx1 * dy2 > dx2 * dy1 ) {
outside = !outside;
}
} else {
if ( dx1 * (int64_t)dy2 > dx2 * (int64_t)dy1 ) {
outside = !outside;
}
}
}
} else {
if (m1 < m2) {
outside = !outside;
} else if (m1 > m2) {
continue;
} else if ( dx1 * (int64_t)dy2 < dx2 * (int64_t)dy1 ) {
outside = !outside;
} else {
if (std::is_floating_point<T>::value) {
if ( dx1 * dy2 < dx2 * dy1 ) {
outside = !outside;
}
} else {
if ( dx1 * (int64_t)dy2 < dx2 * (int64_t)dy1 ) {
outside = !outside;
}
}
}
}
}