AP_Math: AP_GeodesicGrid: fix algorithm for null vector

If v is the null vector, then alpha * v is still the null vector for any alpha
as a real number. That means that the null vector doesn't cross any section.
This commit is contained in:
Gustavo Jose de Sousa 2016-04-18 13:56:16 -03:00 committed by Lucas De Marchi
parent c28c3265c8
commit eb90ef23a1
2 changed files with 7 additions and 7 deletions

View File

@ -347,8 +347,7 @@ int AP_GeodesicGrid::_triangle_index(const Vector3f& v,
case 0: case 0:
/* There are two possible cases when balance is 1: /* There are two possible cases when balance is 1:
* *
* 1) The vector v is the null vector. Arbitrarily return first * 1) The vector v is the null vector, which doesn't cross any section.
* triangle.
* *
* 2) One coefficient is zero, another is positive and yet another is * 2) One coefficient is zero, another is positive and yet another is
* negative. Let a, b and c be the respective vertices for those * negative. Let a, b and c be the respective vertices for those
@ -356,7 +355,7 @@ int AP_GeodesicGrid::_triangle_index(const Vector3f& v,
* are also valid here. * are also valid here.
*/ */
if (zero_count == 3) { if (zero_count == 3) {
return inclusive ? 0 : -1; return -1;
} }
if (!is_zero(w.x) && w.x < 0) { if (!is_zero(w.x) && w.x < 0) {

View File

@ -121,8 +121,9 @@ public:
* are checked is unspecified. The default value for \p inclusive is * are checked is unspecified. The default value for \p inclusive is
* false. * false.
* *
* @return The index of the section. The value -1 is returned if the * @return The index of the section. The value -1 is returned if \p v is
* section isn't found, which might happen when \p inclusive is false. * the null vector or the section isn't found, which might happen when \p
* inclusive is false.
*/ */
int section(const Vector3f& v, const bool inclusive = false) const; int section(const Vector3f& v, const bool inclusive = false) const;
@ -266,8 +267,8 @@ private:
* #section() const. * #section() const.
* *
* @return The index of the icosahedron triangle. The value -1 is returned * @return The index of the icosahedron triangle. The value -1 is returned
* if the triangle isn't found, which might happen when \p inclusive is * if \p v is the null vector or the triangle isn't found, which might
* false. * happen when \p inclusive is false.
*/ */
int _from_neighbor_umbrella(int umbrella_index, int _from_neighbor_umbrella(int umbrella_index,
const Vector3f& v, const Vector3f& v,