summaryrefslogtreecommitdiff
path: root/hw2/include/color.h
diff options
context:
space:
mode:
author53hornet <53hornet@gmail.com>2019-02-02 23:33:15 -0500
committer53hornet <53hornet@gmail.com>2019-02-02 23:33:15 -0500
commitdb072ad4dc181eca5a1458656b130beb43f475bf (patch)
treea3c03c7f5497cb70503e2486662fa85cfb53415a /hw2/include/color.h
downloadcsci427-db072ad4dc181eca5a1458656b130beb43f475bf.tar.xz
csci427-db072ad4dc181eca5a1458656b130beb43f475bf.zip
Diffstat (limited to 'hw2/include/color.h')
-rw-r--r--hw2/include/color.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/hw2/include/color.h b/hw2/include/color.h
new file mode 100644
index 0000000..b2ca490
--- /dev/null
+++ b/hw2/include/color.h
@@ -0,0 +1,105 @@
+/******************************************************************/
+/* This file is part of the homework assignments for CSCI-427/527 */
+/* at The College of William & Mary and authored by Pieter Peers. */
+/* No part of this file, whether altered or in original form, can */
+/* be distributed or used outside the context of CSCI-427/527 */
+/* without consent of either the College of William & Mary or */
+/* Pieter Peers. */
+/******************************************************************/
+#ifndef _COLOR_H_
+#define _COLOR_H_
+
+#include <ostream>
+
+class color {
+ public:
+ /////////////
+ // Typedef //
+ /////////////
+ typedef float value_type;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef value_type* iterator;
+ typedef const value_type* const_iterator;
+
+ //////////////////
+ // Data Members //
+ //////////////////
+ union {
+ struct { value_type r, g, b; };
+ struct { value_type red, green, blue; };
+ value_type data[3];
+ };
+
+ public:
+ /////////////////
+ // Constructor //
+ /////////////////
+ explicit color(const_reference value=0.0f);
+ color(const_reference r, const_reference g, const_reference b);
+ color(const color& col);
+
+ ////////////////
+ // Inspectors //
+ ////////////////
+ const_reference operator[](size_t index) const;
+ reference operator[](size_t index);
+
+ size_t size(void) const { return 3; }
+
+ iterator begin(void);
+ const_iterator begin(void) const;
+ iterator end(void);
+ const_iterator end(void) const;
+
+ ///////////////
+ // Operators //
+ ///////////////
+ color& operator=(const color& col);
+
+ bool operator==(const color& col) const;
+ bool operator!=(const color& col) const;
+
+ color operator+(const color& col) const;
+ color operator-(const color& col) const;
+ color operator*(const color& col) const;
+ color operator*(const_reference scale) const;
+ color operator/(const color& col) const;
+ color operator/(const_reference scale) const;
+
+ color& operator+=(const color& col);
+ color& operator-=(const color& col);
+ color& operator*=(const color& col);
+ color& operator*=(const_reference scale);
+ color& operator/=(const color& col);
+ color& operator/=(const_reference scale);
+
+ ///////////////
+ // Modifiers //
+ ///////////////
+ color& abs(void);
+ color& clamp(const_reference lowerBound=0.0f, const_reference upperBounds=1.0f);
+
+ /////////////
+ // Friends //
+ /////////////
+ friend void swap(color& a, color& b) { return a._swap(b); }
+ friend color abs(const color& c) { return color(c).abs(); }
+ friend color clamp(const color& c, const_reference lowerBound=0.0f, const_reference upperBound=1.0f) { return color(c).clamp(lowerBound, upperBound); }
+ friend color operator*(const_reference scale, const color& col) { return (col*scale); }
+
+ friend std::ostream& operator<<(std::ostream& s, const color& col)
+ {
+ s << "(" << col.r << "," << col.g << "," << col.b << ")";
+ return s;
+ }
+
+ private:
+ /////////////////////
+ // Private Methods //
+ /////////////////////
+ void _assign(const color& col);
+ void _swap(color& col);
+};
+
+#endif /* _COLOR_H_ */