/********************************************************************
 * File: Color.cpp
 * Author: Keith Schwarz (htiek@cs.stanford.edu)
 *
 * Implementation of the Color class.
 */
#include "Color.h"
#include <stdexcept>
using namespace std;

/* Confirms that a color is within the valid range [0, 1]. */
static void VerifyColorValue(float color) {
	if (color < 0.0f || color > 1.0f)
		throw invalid_argument("Color value is out of range [0, 1]");
}

/* Default constructor sets everything to zero (except alpha, which is one) */
Copper3D::Color::Color() : rValue(0.0f), gValue(0.0f), bValue(0.0f), aValue(1.0f) {
}

/* Parameterized constructor just calls all the setters. */
Copper3D::Color::Color(float r, float g, float b, float a) {
	setR(r);
	setG(g);
	setB(b);
	setA(a);
}

/* Setters check their respective values, then store them. */
void Copper3D::Color::setR(float r) {
	VerifyColorValue(r);
	rValue = r;
}
void Copper3D::Color::setG(float g) {
	VerifyColorValue(g);
	gValue = g;
}
void Copper3D::Color::setB(float b) {
	VerifyColorValue(b);
	bValue = b;
}
void Copper3D::Color::setA(float a) {
	VerifyColorValue(a);
	aValue = a;
}

/* Getters just return the appropriate values. */
float Copper3D::Color::r() const {
	return rValue;
}
float Copper3D::Color::g() const {
	return gValue;
}
float Copper3D::Color::b() const {
	return bValue;
}
float Copper3D::Color::a() const {
	return aValue;
}