LCOV - code coverage report
Current view: top level - math/linalg - point3d.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 20 20
Test Date: 2026-04-26 21:52:20 Functions: 100.0 % 1 1
Legend: Lines: hit not hit

            Line data    Source code
       1              : #ifndef D190DD96_01E1_4A50_8090_B1337EB3B42E
       2              : #define D190DD96_01E1_4A50_8090_B1337EB3B42E
       3              : 
       4              : /// \file point3d.h
       5              : /// \brief 3D point class with named coordinate access
       6              : ///
       7              : /// This file defines Point3d, a 3D point class that inherits from Vector<ValueType_, 3>
       8              : /// and provides convenient named access to x, y, and z coordinates.
       9              : ///
      10              : /// \note Point3d is a thin wrapper around Vector that adds semantic meaning
      11              : ///       and named accessors for 3D geometric operations.
      12              : 
      13              : #include "base/first_include.h"   // IWYU pragma: keep
      14              : #include "math/linalg/vector.hpp" // IWYU pragma: keep
      15              : 
      16              : namespace tracking
      17              : {
      18              : namespace math
      19              : {
      20              : 
      21              : // TODO(matthias): add upcast from Point2d
      22              : // TODO(matthias): add interface contract
      23              : 
      24              : /// \brief 3D point with named coordinate access
      25              : ///
      26              : /// Point3d represents a point in 3D space with x, y, and z coordinates.
      27              : /// It inherits from Vector<ValueType_, 3> and provides convenient named
      28              : /// accessors for the coordinates, making geometric code more readable.
      29              : ///
      30              : /// All Vector operations are available, plus coordinate-specific accessors.
      31              : ///
      32              : /// \tparam ValueType_ The atomic data type of internal elements
      33              : ///
      34              : /// Example usage:
      35              : /// \code{.cpp}
      36              : /// Point3d<double> p = Point3d<double>::FromValues(1.0, 2.0, 3.0);
      37              : /// double x = p.x(); // 1.0
      38              : /// double y = p.y(); // 2.0
      39              : /// double z = p.z(); // 3.0
      40              : /// p.z() = 4.0;     // modify z coordinate
      41              : /// \endcode
      42              : ///
      43              : /// \see Point2d for 2D points
      44              : /// \see Vector for underlying vector operations
      45              : template <typename ValueType_>
      46            4 : class Point3d: public Vector<ValueType_, 3>
      47              : {
      48              : public:
      49              :   /// \brief Type of the parent Vector class
      50              :   using BaseVector = Vector<ValueType_, 3>;
      51              : 
      52              :   // unhide ctor of base class to allow implicit call in derived default ctors
      53            1 :   using BaseVector::BaseVector;
      54              : 
      55              :   /// \brief Construct a new Point 3d<ValueType_> object
      56              :   /// \param[in] other A base class object
      57              :   explicit Point3d(const BaseVector& other)
      58              :       : BaseVector{other}
      59              :   {
      60              :   }
      61              : 
      62              :   /// \brief Move construct a new Point 3d<ValueType_> object
      63              :   /// \param[in] other A base class object
      64              :   explicit Point3d(BaseVector&& other) noexcept
      65              :       : BaseVector{std::move(other)}
      66              :   {
      67              :   }
      68              : 
      69              :   /// \brief Create a 3D point from coordinate values
      70              :   ///
      71              :   /// Static factory method to create a Point3d from individual x, y, and z values.
      72              :   /// This is the preferred way to construct points with explicit coordinates.
      73              :   ///
      74              :   /// \param[in] x The x-coordinate value
      75              :   /// \param[in] y The y-coordinate value
      76              :   /// \param[in] z The z-coordinate value
      77              :   /// \return Point3d with the specified coordinates
      78              :   ///
      79              :   /// Example:
      80              :   /// \code{.cpp}
      81              :   /// auto point = Point3d<double>::FromValues(1.5, -2.3, 4.7);
      82              :   /// \endcode
      83              :   static auto FromValues(const ValueType_ x, const ValueType_ y, const ValueType_ z) -> Point3d;
      84              : 
      85              :   /// \brief Read access to x-coordinate
      86              :   ///
      87              :   /// Provides read-only access to the x-coordinate (first component).
      88              :   ///
      89              :   /// \return The x-coordinate value
      90              :   [[nodiscard]] auto x() const -> ValueType_;
      91              : 
      92              :   /// \brief Read access to y-coordinate
      93              :   ///
      94              :   /// Provides read-only access to the y-coordinate (second component).
      95              :   ///
      96              :   /// \return The y-coordinate value
      97              :   [[nodiscard]] auto y() const -> ValueType_;
      98              : 
      99              :   /// \brief Read access to z-coordinate
     100              :   ///
     101              :   /// Provides read-only access to the z-coordinate (third component).
     102              :   ///
     103              :   /// \return The z-coordinate value
     104              :   [[nodiscard]] auto z() const -> ValueType_;
     105              : 
     106              :   /// \brief Write access to x-coordinate
     107              :   ///
     108              :   /// Provides read-write access to the x-coordinate (first component).
     109              :   ///
     110              :   /// \return Reference to the x-coordinate for modification
     111              :   [[nodiscard]] auto x() -> ValueType_&;
     112              : 
     113              :   /// \brief Write access to y-coordinate
     114              :   ///
     115              :   /// Provides read-write access to the y-coordinate (second component).
     116              :   ///
     117              :   /// \return Reference to the y-coordinate for modification
     118              :   [[nodiscard]] auto y() -> ValueType_&;
     119              : 
     120              :   /// \brief Write access to z-coordinate
     121              :   ///
     122              :   /// Provides read-write access to the z-coordinate (third component).
     123              :   ///
     124              :   /// \return Reference to the z-coordinate for modification
     125              :   [[nodiscard]] auto z() -> ValueType_&;
     126              : 
     127              :   // clang-format off
     128              : TEST_REMOVE_PRIVATE:
     129              :   ; // workaround for correct indentation
     130              :   // clang-format on
     131              : 
     132              :   /// \brief hide inherited at_unsafe to prevent wrong access
     133              :   using BaseVector::at_unsafe;
     134              : };
     135              : 
     136              : template <typename ValueType_>
     137            3 : inline auto Point3d<ValueType_>::FromValues(const ValueType_ x, const ValueType_ y, const ValueType_ z) -> Point3d
     138              : {
     139            3 :   Point3d tmp{};
     140            6 :   tmp.x() = x;
     141            6 :   tmp.y() = y;
     142            6 :   tmp.z() = z;
     143            3 :   return tmp;
     144              : }
     145              : 
     146              : template <typename ValueType_>
     147            2 : inline auto Point3d<ValueType_>::x() const -> ValueType_
     148              : {
     149            2 :   return this->at_unsafe(0);
     150              : }
     151              : 
     152              : template <typename ValueType_>
     153            2 : inline auto Point3d<ValueType_>::y() const -> ValueType_
     154              : {
     155            2 :   return this->at_unsafe(1);
     156              : }
     157              : 
     158              : template <typename ValueType_>
     159            2 : inline auto Point3d<ValueType_>::z() const -> ValueType_
     160              : {
     161            2 :   return this->at_unsafe(2);
     162              : }
     163              : 
     164              : template <typename ValueType_>
     165            5 : inline auto Point3d<ValueType_>::x() -> ValueType_&
     166              : {
     167            5 :   return this->at_unsafe(0);
     168              : }
     169              : 
     170              : template <typename ValueType_>
     171            5 : inline auto Point3d<ValueType_>::y() -> ValueType_&
     172              : {
     173            5 :   return this->at_unsafe(1);
     174              : }
     175              : 
     176              : template <typename ValueType_>
     177            5 : inline auto Point3d<ValueType_>::z() -> ValueType_&
     178              : {
     179            5 :   return this->at_unsafe(2);
     180              : }
     181              : 
     182              : } // namespace math
     183              : } // namespace tracking
     184              : 
     185              : #endif // D190DD96_01E1_4A50_8090_B1337EB3B42E
        

Generated by: LCOV version 2.0-1