diff options
author | Jelle Spijker <j.spijker@ultimaker.com> | 2022-11-06 19:42:03 +0300 |
---|---|---|
committer | Jelle Spijker <spijker.jelle@gmail.com> | 2022-11-06 19:42:03 +0300 |
commit | 76cb8bb0ca2c0bc5299fb3b45b6f1c7f8668fe26 (patch) | |
tree | 7b816214b00b55b8a5d2db41600538bb93bfbfa6 | |
parent | 40bfbe52a6cb975c8a62e2224911c9d7881c4895 (diff) |
Use enum as axispolygonamory
-rw-r--r-- | include/polygon/Point.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/include/polygon/Point.h b/include/polygon/Point.h index 9a237d8af..119b2ce77 100644 --- a/include/polygon/Point.h +++ b/include/polygon/Point.h @@ -19,6 +19,13 @@ namespace cura::poly { +enum struct Axis +{ + X = 0, + Y = 1, + Z = 2 +}; + template<class Tp, std::size_t Nm = 2> // TODO: figure out how to set a max size (of 3 x,y,z) class Point { @@ -140,28 +147,48 @@ public: // Element access. [[nodiscard]] constexpr reference operator[](size_type idx) noexcept { - gsl_Expects(idx < Nm); + gsl_Expects(idx < size()); return data_[idx]; } + [[nodiscard]] constexpr reference operator[](const Axis& axis) noexcept + { + return data_[static_cast<size_type>(axis)]; + } + [[nodiscard]] constexpr const_reference operator[](size_type idx) const noexcept { gsl_Expects(idx < Nm); return data_[idx]; } + [[nodiscard]] constexpr const_reference operator[](const Axis& axis) const noexcept + { + return data_[static_cast<size_type>(axis)]; + } + [[nodiscard]] constexpr reference at(size_type idx) { gsl_Expects(idx < Nm); return data_.at(idx); } + [[nodiscard]] constexpr reference at(const Axis& axis) + { + return data_.at(static_cast<size_type>(axis)); + } + [[nodiscard]] constexpr const_reference at(size_type idx) const { gsl_Expects(idx < Nm); return data_.at(idx); } + [[nodiscard]] constexpr const_reference at(const Axis& axis) const + { + return data_.at(static_cast<size_type>(axis)); + } + [[nodiscard]] constexpr reference front() noexcept { return data_.front(); |