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

Generated by: LCOV version 1.14