DynMatrix.h 872 B

123456789101112131415161718192021222324252627282930
  1. // SPDX-FileCopyrightText: 2022 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. JPH_NAMESPACE_BEGIN
  5. /// Dynamic resizable matrix class
  6. class [[nodiscard]] DynMatrix
  7. {
  8. public:
  9. /// Constructor
  10. DynMatrix(const DynMatrix &) = default;
  11. DynMatrix(uint inRows, uint inCols) : mRows(inRows), mCols(inCols) { mElements.resize(inRows * inCols); }
  12. /// Access an element
  13. float operator () (uint inRow, uint inCol) const { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; }
  14. float & operator () (uint inRow, uint inCol) { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; }
  15. /// Get dimensions
  16. uint GetCols() const { return mCols; }
  17. uint GetRows() const { return mRows; }
  18. private:
  19. uint mRows;
  20. uint mCols;
  21. Array<float> mElements;
  22. };
  23. JPH_NAMESPACE_END