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

          Line data    Source code
       1             : #ifndef CFE848F0_38AC_4182_9A69_D7C2AB0577CA_HPP
       2             : #define CFE848F0_38AC_4182_9A69_D7C2AB0577CA_HPP
       3             : 
       4             : #include "Hashing.hpp"
       5             : #include "Types.hpp"
       6             : 
       7             : #include <SFML/Graphics/Color.hpp>
       8             : 
       9             : #include <string>
      10             : 
      11             : namespace cell
      12             : {
      13             : 
      14             : /**
      15             :  * @brief Contains the physical and visual properties of a disc. Disc types used in the simulation need to be distinct
      16             :  * by name
      17             :  */
      18             : class DiscType
      19             : {
      20             : public:
      21             :     /**
      22             :      * @brief Creates a new disc type
      23             :      */
      24          49 :     DiscType(const std::string& name, Radius radius, Mass mass)
      25          49 :     {
      26          49 :         setName(name);
      27          49 :         setRadius(radius.value);
      28          49 :         setMass(mass.value);
      29          49 :     }
      30             : 
      31             :     /**
      32             :      * @brief Disc types should be shared across all discs and be unique
      33             :      */
      34             :     DiscType(const DiscType&) = delete;
      35             :     DiscType& operator=(const DiscType&) = delete;
      36          39 :     DiscType(DiscType&&) = default;
      37             :     DiscType& operator=(DiscType&&) = default;
      38             : 
      39             :     /**
      40             :      * @returns The name of this DiscType
      41             :      */
      42         431 :     const std::string& getName() const noexcept
      43             :     {
      44         431 :         return name_;
      45             :     }
      46             : 
      47             :     /**
      48             :      * @brief Sets the name for this DiscType (can't be empty)
      49             :      */
      50          49 :     void setName(const std::string& name)
      51             :     {
      52          49 :         if (name.empty())
      53           0 :             throw ExceptionWithLocation("Disc type name cannot be empty");
      54             : 
      55          49 :         name_ = name;
      56          49 :     }
      57             : 
      58             :     /**
      59             :      * @returns The radius of this DiscType in px
      60             :      */
      61         308 :     double getRadius() const noexcept
      62             :     {
      63         308 :         return radius_;
      64             :     }
      65             : 
      66             :     /**
      67             :      * @brief Sets the radius of this DiscType in px (must be > 0)
      68             :      */
      69          49 :     void setRadius(double radius)
      70             :     {
      71          49 :         if (radius <= 0)
      72           0 :             throw ExceptionWithLocation("Disc type radius must be positive");
      73             : 
      74          49 :         radius_ = radius;
      75          49 :     }
      76             : 
      77             :     /**
      78             :      * @returns The mass of this DiscType (arbitrary unit right now)
      79             :      */
      80         381 :     double getMass() const noexcept
      81             :     {
      82         381 :         return mass_;
      83             :     }
      84             : 
      85             :     /**
      86             :      * @brief Sets the mass of this DiscType (must be > 0, arbitrary unit)
      87             :      */
      88          49 :     void setMass(double mass)
      89             :     {
      90          49 :         if (mass <= 0)
      91           0 :             throw ExceptionWithLocation("Disc type mass must be positive");
      92             : 
      93          49 :         mass_ = mass;
      94          49 :     }
      95             : 
      96             :     /**
      97             :      * @brief Comparison by all members
      98             :      */
      99             :     bool operator==(const DiscType& other) const noexcept
     100             :     {
     101             :         return name_ == other.name_ && radius_ == other.radius_ && mass_ == other.mass_;
     102             :     }
     103             : 
     104             : private:
     105             :     /**
     106             :      * @brief The name is used to uniquely identify disc types within the disc type distribution
     107             :      */
     108             :     std::string name_;
     109             : 
     110             :     /**
     111             :      * @brief Radius in px
     112             :      */
     113             :     double radius_ = 0;
     114             : 
     115             :     /**
     116             :      * @brief Mass in arbitrary unit
     117             :      */
     118             :     double mass_ = 0;
     119             : };
     120             : 
     121             : } // namespace cell
     122             : 
     123             : #endif /* CFE848F0_38AC_4182_9A69_D7C2AB0577CA_HPP */

Generated by: LCOV version 1.14