// // dyn_limit.h // pokemon // // Created by Sam Jaffe on 12/1/23. // Copyright © 2023 Sam Jaffe. All rights reserved. // #pragma once #include namespace math { template class Bound; template class DynBound final { public: using value_type = T; using underlying_type = value_type; private: value_type lower_bound_{}; value_type upper_bound_{}; value_type value_{}; public: DynBound() = default; DynBound(value_type value, value_type lower_bound, value_type upper_bound) : lower_bound_(lower_bound), upper_bound_(upper_bound), value_(clamp(value, lower_bound_, upper_bound_)) {} template DynBound(Bound const & other) : lower_bound_(MINIMUM_VALUE), upper_bound_(MAXIMUM_VALUE), value_(other) {} operator value_type() const { return value_; } bool is_min() const { return value_ == lower_bound_; } bool is_max() const { return value_ == upper_bound_; } DynBound & operator+=(value_type by) { value_ = std::min(upper_bound_, value_ + by); return *this; } DynBound & operator-=(value_type by) { value_ = std::max(lower_bound_, value_ - by); return *this; } DynBound & operator++() { return operator+=(1); } DynBound & operator--() { return operator-=(1); } DynBound operator+(value_type by) const { return DynBound{*this} += by; } DynBound operator-(value_type by) const { return DynBound{*this} -= by; } DynBound operator++(int) { DynBound tmp{*this}; operator++(); return tmp; } DynBound operator--(int) { DynBound tmp{*this}; operator--(); return tmp; } }; }