libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
xyzcolor.h
Go to the documentation of this file.
1
8#pragma once
9
11#include <promeki/core/array.h>
12#include <promeki/core/string.h>
13
15
25class XYZColor {
26 public:
29
31 XYZColor() : d{-1.0, -1.0, -1.0} {}
32
37 XYZColor(const DataType &val) : d(val) {}
38
45 XYZColor(double x, double y, double z) : d(x, y, z) {}
46
48 bool isValid() const {
49 for(size_t i = 0; i < d.size(); ++i) if(d[i] < 0.0 || d[i] > 1.0) return false;
50 return true;
51 }
52
54 const DataType &data() const { return d; }
56 DataType &data() { return d; }
58 double x() { return d[0]; }
60 double y() { return d[1]; }
62 double z() { return d[2]; }
64 void set(double x, double y, double z) { d = { x, y, z }; }
66 void setX(double val) { d[0] = val; }
68 void setY(double val) { d[1] = val; }
70 void setZ(double val) { d[2] = val; }
71
78 XYZColor lerp(const XYZColor &val, double t) const { return d.lerp(val.d, t); }
79
81 operator String() { return toString(); }
82
84 String toString() const {
85 return String::sprintf("XYZ(%g, %g, %g)", d[0], d[1], d[2]);
86 }
87
88 private:
89 DataType d;
90};
91
93
size_t size() const
Returns the number of elements in the array.
Definition array.h:76
Array< T, NumValues > lerp(const Array< T, NumValues > &other, double v) const
Returns a linearly interpolated array between this one and another.
Definition array.h:310
Dynamic array container wrapping std::vector.
Definition list.h:40
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
static String sprintf(const char *fmt,...)
Creates a formatted string using printf-style syntax.
CIE XYZ color value.
Definition xyzcolor.h:25
String toString() const
Returns a string representation of the XYZ color.
Definition xyzcolor.h:84
XYZColor lerp(const XYZColor &val, double t) const
Returns a linearly interpolated XYZColor between this and val.
Definition xyzcolor.h:78
double z()
Returns the Z component.
Definition xyzcolor.h:62
void setZ(double val)
Sets the Z component.
Definition xyzcolor.h:70
void set(double x, double y, double z)
Sets all three XYZ components.
Definition xyzcolor.h:64
XYZColor(const DataType &val)
Constructs an XYZColor from a DataType array.
Definition xyzcolor.h:37
Array< double, 3 > DataType
Underlying storage type for the three XYZ components.
Definition xyzcolor.h:28
void setX(double val)
Sets the X component.
Definition xyzcolor.h:66
double y()
Returns the Y component.
Definition xyzcolor.h:60
void setY(double val)
Sets the Y component.
Definition xyzcolor.h:68
const DataType & data() const
Returns a const reference to the underlying data array.
Definition xyzcolor.h:54
XYZColor()
Constructs an invalid XYZColor with all components set to -1.0.
Definition xyzcolor.h:31
bool isValid() const
Returns true if all components are in the valid [0.0, 1.0] range.
Definition xyzcolor.h:48
XYZColor(double x, double y, double z)
Constructs an XYZColor from individual component values.
Definition xyzcolor.h:45
double x()
Returns the X component.
Definition xyzcolor.h:58
DataType & data()
Returns a mutable reference to the underlying data array.
Definition xyzcolor.h:56
#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