From 2147d8a62defc17a877049a45f804e1254ae8a66 Mon Sep 17 00:00:00 2001 From: svchb Date: Fri, 12 Aug 2022 17:00:13 +0200 Subject: [PATCH] fix #1 --- src/cartesiangrid_base.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cartesiangrid_base.h b/src/cartesiangrid_base.h index 59a4215..a485fb6 100644 --- a/src/cartesiangrid_base.h +++ b/src/cartesiangrid_base.h @@ -55,22 +55,30 @@ class CartesianGridData { m_partitionLvl(initGrid.ref_partitionLvl()), m_currentHighestLvl(initGrid.ref_currentHighestLvl()) {} - // todo: add asserts - [[nodiscard]] inline auto noCells() const -> GInt { return m_noCells; } + [[nodiscard]] inline auto noCells() const -> GInt { + ASSERT(m_noCells >= 0, "Invalid object!"); + return m_noCells; + } - // todo: add asserts - inline auto center(const GInt cellId) const -> const Point& { return m_center[cellId]; } + inline auto center(const GInt cellId) const -> const Point& { + ASSERT(cellId >= 0 and cellId < m_noCells, "Invalid cellId"); + return m_center[cellId]; + } - // todo: add asserts [[nodiscard]] inline auto isLeaf(const GInt cellId) const -> GBool { + ASSERT(cellId >= 0 and cellId < m_noCells, "Invalid cellId"); return m_properties[cellId][static_cast(CellProperties::leaf)]; } - // todo: add asserts - [[nodiscard]] inline auto level(const GInt cellId) const -> std::byte { return m_level[cellId]; } + [[nodiscard]] inline auto level(const GInt cellId) const -> std::byte { + ASSERT(cellId >= 0 and cellId < m_noCells, "Invalid cellId"); + return m_level[cellId]; + } - // todo: add asserts - [[nodiscard]] inline auto cellLength(const GInt cellId) const -> GDouble { return m_lengthOnLevel[static_cast(level(cellId))]; } + [[nodiscard]] inline auto cellLength(const GInt cellId) const -> GDouble { + ASSERT(cellId >= 0 and cellId < m_noCells, "Invalid cellId"); + return m_lengthOnLevel[static_cast(level(cellId))]; + } [[nodiscard]] inline auto boundingBox() const -> const BoundingBoxInterface& { return m_boundingBox; } @@ -86,7 +94,7 @@ class CartesianGridData { private: - const GInt m_noCells; + const GInt m_noCells = -1; const BoundingBoxInterface& m_boundingBox; const std::vector>& m_center;