Line data Source code
1 : #include "PhysicalObject.hpp" 2 : #include "ExceptionWithLocation.hpp" 3 : #include "MathUtils.hpp" 4 : 5 : #include <cmath> 6 : 7 : namespace cell 8 : { 9 : 10 330 : void PhysicalObject::setVelocity(const Vector2d& velocity) 11 : { 12 : #ifdef DEBUG 13 330 : if (isNanOrInf(velocity)) 14 0 : throw ExceptionWithLocation("Trying to assign an invalid value to velocity"); 15 : #endif 16 330 : velocity_ = velocity; 17 330 : } 18 : 19 350 : void PhysicalObject::setPosition(const Vector2d& position) 20 : { 21 : #ifdef DEBUG 22 350 : if (isNanOrInf(position)) 23 0 : throw ExceptionWithLocation("Trying to assign an invalid value to position"); 24 : #endif 25 350 : position_ = position; 26 350 : } 27 : 28 0 : double PhysicalObject::getAbsoluteMomentum(double mass) const 29 : { 30 0 : return mass * std::hypot(velocity_.x, velocity_.y); 31 : } 32 : 33 680 : bool PhysicalObject::isNanOrInf(const Vector2d& vec) const 34 : { 35 680 : return std::isnan(vec.x) || std::isnan(vec.y) || std::isinf(vec.x) || std::isinf(vec.y); 36 : } 37 : 38 : } // namespace cell