LCOV - code coverage report
Current view: top level - cell - PhysicalObject.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 13 100.0 %
Date: 2025-12-26 22:55:38 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #ifndef EABADE67_50B6_4B9A_933E_C1059A828B32_HPP
       2             : #define EABADE67_50B6_4B9A_933E_C1059A828B32_HPP
       3             : 
       4             : #include "Vector2d.hpp"
       5             : 
       6             : namespace cell
       7             : {
       8             : 
       9             : class PhysicalObject
      10             : {
      11             : public:
      12             :     /**
      13             :      * @brief Sets the velocity of the disc in px/s
      14             :      */
      15             :     void setVelocity(const Vector2d& velocity);
      16             : 
      17             :     /**
      18             :      * @brief Multiplies both velocity components with `factor`
      19             :      */
      20           2 :     void scaleVelocity(double factor) noexcept
      21             :     {
      22           2 :         velocity_ *= factor;
      23           2 :     }
      24             : 
      25             :     /**
      26             :      * @brief Adds `acceleration` to the velocity of the disc
      27             :      */
      28          14 :     void accelerate(const Vector2d& acceleration) noexcept
      29             :     {
      30          14 :         velocity_ += acceleration;
      31          14 :     }
      32             : 
      33             :     /**
      34             :      * @brief Sets the position with no checks.
      35             :      * @note In debug mode, checks for invalid values (nan, inf)
      36             :      */
      37             :     void setPosition(const Vector2d& position);
      38             : 
      39             :     /**
      40             :      * @brief Changes the disc's position by the given `distance`
      41             :      */
      42          27 :     void move(const Vector2d& distance) noexcept
      43             :     {
      44          27 :         position_ += distance;
      45          27 :     }
      46             : 
      47             :     /**
      48             :      * @returns Velocity of the disc (px/s)
      49             :      */
      50          51 :     const Vector2d& getVelocity() const noexcept
      51             :     {
      52          51 :         return velocity_;
      53             :     }
      54             : 
      55             :     /**
      56             :      * @returns Position of the disc (px)
      57             :      */
      58      362954 :     const Vector2d& getPosition() const noexcept
      59             :     {
      60      362954 :         return position_;
      61             :     }
      62             : 
      63             :     /**
      64             :      * @returns |mv|
      65             :      */
      66             :     double getAbsoluteMomentum(double mass) const;
      67             : 
      68             :     /**
      69             :      * @returns 1/2*m*v^2
      70             :      */
      71             :     double getKineticEnergy(double mass) const noexcept
      72             :     {
      73             :         return 0.5 * mass * (velocity_.x * velocity_.x + velocity_.y * velocity_.y);
      74             :     }
      75             : 
      76             : private:
      77             :     bool isNanOrInf(const Vector2d& vec) const;
      78             : 
      79             : private:
      80             :     /**
      81             :      * @brief Velocity in px/s
      82             :      */
      83             :     Vector2d velocity_;
      84             : 
      85             :     /**
      86             :      * @brief Position in px
      87             :      */
      88             :     Vector2d position_;
      89             : };
      90             : 
      91             : } // namespace cell
      92             : 
      93             : #endif /* EABADE67_50B6_4B9A_933E_C1059A828B32_HPP */

Generated by: LCOV version 1.14