#pragma once #include "EmberDefines.h" #include "Affine2D.h" #include "Timing.h" /// /// Basic point and color structures used in iteration. /// namespace EmberNs { /// /// The point used to store the result of each iteration, which is /// a spatial coordinate, a color index/coordinate and a visibility value. /// Note that a Y color coordinate is not used at the moment because /// only 1D palettes are supported like the original. However, in the future /// 2D palettes may be supported like Fractron does. /// Template argument expected to be float or double. /// template class EMBER_API Point { public: /// /// Constructor to initialize spatial and color coordinates to zero, with full visibility. /// Point() = default; ~Point() = default; /// /// Default copy constructor. /// /// The Point object to copy Point(const Point& point) { Point::operator=(point); } /// /// Copy constructor to copy a Point object of type U. /// /// The Point object to copy template Point(const Point& point) { Point::operator=(point); } /// /// Default assignment operator. /// /// The Point object to copy Point& operator = (const Point& point) { if (this != &point) Point::operator=(point); return *this; } /// /// Assignment operator to assign a Point object of type U. /// /// The Point object to copy. /// Reference to updated self template Point& operator = (const Point& point) { m_X = point.m_X; m_Y = point.m_Y; m_Z = point.m_Z; m_ColorX = point.m_ColorX; //m_ColorY = point.m_ColorY; m_Opacity = point.m_Opacity; return *this; } //Set spatial and color coordinates to zero, with full visibility. T m_X = 0; T m_Y = 0; T m_Z = 0; T m_ColorX = 0; //T m_ColorY; T m_Opacity = 1; }; /// /// Comparer used for sorting the results of iteration by their spatial x coordinates. /// /// The first point to compare /// The second point to compare /// 1 if the first point had an x coordinate less than the second point, else 0 template static int SortPointByX(const Point& a, const Point& b) { return a.m_X < b.m_X; } /// /// Comparer used for sorting the results of iteration by their spatial y coordinates. /// /// The first point to compare /// The second point to compare /// 1 if the first point had an y coordinate less than the second point, else 0 template static int SortPointByY(const Point& a, const Point& b) { return a.m_Y < b.m_Y; } /// /// Thin override of a glm::vec4 which adds a couple of functions /// specific to color handling. /// template struct EMBER_API Color : public v4T { using v4T::r; using v4T::g; using v4T::b; using v4T::a; public: /// /// Constructor to set color values to zero, with full visibility. /// Color() { Reset(); } /// /// Default copy constructor. /// /// The Color object to copy Color(const Color& color) : v4T() { Color::operator=(color); } /// /// Copy constructor to copy a Color object of type U. /// /// The Color object to copy template Color(const Color& color) { Color::operator=(color); } /// /// Default assignment operator. /// /// The Color object to copy Color& operator = (const Color& color) { if (this != &color) Color::operator=(color); return *this; } /// /// Assignment operator to assign a Color object of type U. /// /// The Color object to copy. /// Reference to updated self template Color& operator = (const Color& color) { v4T::template operator=(color); return *this; } /// /// Member-wise constructor. /// /// The red value, either 0-1 or 0-255. /// The green value, either 0-1 or 0-255. /// The blue value, either 0-1 or 0-255. /// The alpha value, either 0-1 or 0-255. Color(T rr, T gg, T bb, T aa) : v4T(rr, gg, bb, aa) { } /// /// Set color values and visibility to zero. /// inline void Clear() { r = 0; g = 0; b = 0; a = 0; } /// /// Set color values to zero, with full visibility. /// /// If norm is true, the color fields are expected to have a range of 0-1, else 0-255 inline void Reset(bool norm = true) { r = 0; g = 0; b = 0; a = norm ? T{ 1 } : T{ 255 }; } }; }