MakeUnitVector have an assert if the length is really small or 0
This commit is contained in:
parent
8f7cecc6ca
commit
df48b68391
|
@ -104,9 +104,7 @@ namespace geom {
|
|||
|
||||
Vector3D MakeUnitVector() const {
|
||||
const double len = Length();
|
||||
if (len < std::numeric_limits<double>::epsilon()) {
|
||||
return Vector3D(1.0, 0.0, 0.0);
|
||||
}
|
||||
DEBUG_ASSERT(len > std::numeric_limits<double>::epsilon());
|
||||
double k = 1.0 / len;
|
||||
return Vector3D(x * k, y * k, z * k);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "test.h"
|
||||
#include "gtest/gtest-death-test.h"
|
||||
|
||||
#include <carla/geom/Vector3D.h>
|
||||
#include <carla/geom/Math.h>
|
||||
|
||||
using namespace carla::geom;
|
||||
|
||||
TEST(vector3D, make_unit_vec) {
|
||||
ASSERT_EQ(Vector3D(10,0,0).MakeUnitVector(), Vector3D(1,0,0));
|
||||
ASSERT_NE(Vector3D(10,0,0).MakeUnitVector(), Vector3D(0,1,0));
|
||||
ASSERT_EQ(Vector3D(0,10,0).MakeUnitVector(), Vector3D(0,1,0));
|
||||
ASSERT_EQ(Vector3D(0,0,512).MakeUnitVector(), Vector3D(0,0,1));
|
||||
ASSERT_NE(Vector3D(0,1,512).MakeUnitVector(), Vector3D(0,0,1));
|
||||
ASSERT_DEATH_IF_SUPPORTED(
|
||||
Vector3D().MakeUnitVector(), "len > std::numeric_limits<double>::epsilon()");
|
||||
}
|
Loading…
Reference in New Issue