41template <
typename T,
size_t NumValues>
class Point {
54 d[
i] =
static_cast<T>(
parts[
i].trim().toDouble(&
err));
70 return e.isOk() ? d :
Point();
133 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 1,
int> = 0>
const T &x()
const {
138 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 1,
int> = 0>
T &x() {
143 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 1,
int> = 0>
void setX(
const T &
val) {
149 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 2,
int> = 0>
const T &y()
const {
154 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 2,
int> = 0>
T &y() {
159 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 2,
int> = 0>
void setY(
const T &
val) {
165 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 3,
int> = 0>
const T &z()
const {
170 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 3,
int> = 0>
T &z() {
175 template<
size_t N = NumValues,
typename std::enable_if_t<N >= 3,
int> = 0>
void setZ(
const T &
val) {
184 if(
i > 0) result +=
", ";
185 if constexpr (std::is_floating_point_v<T>) {
202 double diff =
static_cast<double>(d[
i]) -
static_cast<double>(
other.d[
i]);
205 return std::sqrt(sum);
243 if (d[
i] < min.d[
i] || d[
i] >
max.d[
i]) {
Lightweight error code wrapper for the promeki library.
Definition error.h:39
@ Ok
No error.
Definition error.h:51
@ Invalid
Invalid value or argument (EINVAL).
Definition error.h:66
Dynamic array container wrapping std::vector.
Definition list.h:40
size_t size() const noexcept
Returns the number of elements in the list.
Definition list.h:301
N-dimensional point with arithmetic, interpolation, and serialization.
Definition point.h:41
friend Point operator-(const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
Returns the component-wise difference of two Arrays as a Point.
Definition point.h:256
static Point fromString(const String &str, Error *err=nullptr)
Parses a comma-separated string into a Point.
Definition point.h:66
static Error fromString(const String &val, Point &d)
Parses a comma-separated string into a Point.
Definition point.h:49
friend Point operator/(const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
Returns the component-wise quotient of two Arrays as a Point.
Definition point.h:266
bool operator!=(const Array< T, NumValues > &val) const
Returns true if this Point does not equal the given Array.
Definition point.h:104
Point & operator-=(const Array< T, NumValues > &val)
Subtracts the given Array component-wise from this Point.
Definition point.h:115
Point & operator/=(const Array< T, NumValues > &val)
Divides this Point component-wise by the given Array.
Definition point.h:127
Point(const String &str)
Constructs a Point by parsing a comma-separated string.
Definition point.h:83
virtual ~Point()
Destructor.
Definition point.h:86
Point()
Default constructor. Initializes all values to zero.
Definition point.h:74
Point< T, NumValues > clamp(const Point< U, NumValues > &minVal, const Point< U, NumValues > &maxVal) const
Clamps each component of the Point to the given min and max bounds.
Definition point.h:222
Point(const Array< T, NumValues > &val)
Constructs a Point from an Array.
Definition point.h:77
friend Point operator*(const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
Returns the component-wise product of two Arrays as a Point.
Definition point.h:261
Point(Args... args)
Constructs a Point from individual component values.
Definition point.h:80
Point & operator+=(const Array< T, NumValues > &val)
Adds the given Array component-wise to this Point.
Definition point.h:109
bool operator==(const Array< T, NumValues > &val) const
Returns true if this Point equals the given Array.
Definition point.h:99
Point & operator*=(const Array< T, NumValues > &val)
Multiplies this Point component-wise by the given Array.
Definition point.h:121
bool isWithinBounds(const Point< T, NumValues > &min, const Point< T, NumValues > &max) const
Returns true if all components are within the given min and max bounds (inclusive).
Definition point.h:241
friend Point operator+(const Array< T, NumValues > &lh, const Array< T, NumValues > &rh)
Returns the component-wise sum of two Arrays as a Point.
Definition point.h:251
Manages a list of strings.
Definition stringlist.h:21
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
static String number(int8_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
Converts a numeric value to its String representation.
static String dec(const T &val, int padding=0, char padchar=' ')
Formats a value as a decimal string with optional padding.
Definition string.h:167
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19