From 76cb8bb0ca2c0bc5299fb3b45b6f1c7f8668fe26 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Sun, 6 Nov 2022 17:42:03 +0100 Subject: Use enum as axis --- include/polygon/Point.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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 // 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(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(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(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(axis)); + } + [[nodiscard]] constexpr reference front() noexcept { return data_.front(); -- cgit v1.2.3