Commit 885a6cc5 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Starting work on radixcolor package.

parent 190e9909
......@@ -2,6 +2,7 @@ TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
SUBPACKAGES_DIRS_CLASSIFICATIONS_OPTREQS
bug radixbug SS OPTIONAL
math radixmath SS OPTIONAL
color radixcolor SS OPTIONAL
io radixio SS OPTIONAL
geometry radixgeometry SS OPTIONAL
plot radixplot SS OPTIONAL
......
TRIBITS_SUBPACKAGE(color)
SET(SOURCE
color.cc
colorset.cc
)
SET(HEADERS
color.hh
colorset.hh
)
#
# Add library
TRIBITS_ADD_LIBRARY(radixcolor
SOURCES ${SOURCE}
)
#
# Add testing directory
TRIBITS_ADD_TEST_DIRECTORIES(tests)
INSTALL(FILES ${HEADERS} DESTINATION "include/radixcolor/")
TRIBITS_SUBPACKAGE_POSTPROCESS()
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_PACKAGES radixmath radixbug
LIB_OPTIONAL_PACKAGES
TEST_REQUIRED_PACKAGES testframework
TEST_OPTIONAL_PACKAGES
LIB_REQUIRED_TPLS
LIB_OPTIONAL_TPLS
TEST_REQUIRED_TPLS
TEST_OPTIONAL_TPLS
)
#include "radixcolor/color.hh"
namespace radix
{
Color::Color()
: mR(255)
, mG(255)
, mB(255)
{
}
radix::Color::Color(int r, int g, int b)
: mR(r)
, mG(g)
, mB(b)
{
}
int Color::r() const
{
return mR;
}
void Color::setR(int r)
{
mR = r;
}
int Color::g() const
{
return mG;
}
void Color::setG(int g)
{
mG = g;
}
int Color::b() const
{
return mB;
}
void Color::setB(int b)
{
mB = b;
}
} // namespace radix
#ifndef RADIX_RADIXCOLOR_COLOR_HH_
#define RADIX_RADIXCOLOR_COLOR_HH_
namespace radix
{
class Color
{
int mR, mG, mB;
public:
/**
* @brief Color default constructor (white)
*/
Color();
/**
* @brief Color
* @param r red [0, 255)
* @param g green [0, 255)
* @param b blue [0, 255)
*/
Color(int r, int g, int b);
int r() const;
void setR(int r);
int g() const;
void setG(int g);
int b() const;
void setB(int b);
}; // class Color
} // namespace radix
#endif /** RADIX_RADIXCOLOR_COLOR_HH_ */
#include "radixbug/bug.hh"
#include "radixcolor/colorset.hh"
#include "radixcolor/color.hh"
namespace radix
{
int ColorSet::size() const
{
return mSize;
}
void ColorSet::setSize(int size)
{
radix_check(size > 0);
mSize = size;
}
const std::vector<Color>& ColorSet::colors() const
{
if(mColors.size() != (size_t)mSize)
{
//lazy initialization of color set
evaluate();
}
return mColors;
}
Color ColorSet::next() const
{
if(mColors.size() != (size_t)mSize)
{
// lazy initialization of color set
evaluate();
}
if(mIndex == mColors.size())
{
mIndex = 0;
}
return mColors[mIndex++];
}
void ColorSet::evaluate() const
{
}
ColorSet::ColorSet()
: mSize(10)
{
}
ColorSet::ColorSet(int n)
: mSize(n)
{
radix_check(mSize != 0);
}
} //namespace radix
#ifndef RADIX_RADIXCOLOR_COLORSET_HH_
#define RADIX_RADIXCOLOR_COLORSET_HH_
#include <vector>
namespace radix
{
class Color;
class ColorSet
{
private:
/**
* @brief mIndex index for next() request
*/
mutable size_t mIndex;
/**
* @brief mSize The number of requested unique colors
*/
int mSize;
/**
* @brief mColors The computed unique colors
*/
mutable std::vector<Color> mColors;
void evaluate() const;
public:
/**
* @brief ColorSet Defaults to 10 unique colors
*/
ColorSet();
/**
* @brief ColorSet
* @param n Number of unique colors
*/
ColorSet(int n);
int size() const;
void setSize(int size);
const std::vector<Color>& colors() const;
Color next() const;
}; // class Color
} // namespace radix
#endif /** RADIX_RADIXCOLOR_COLORSET_HH_ */
INCLUDE(GoogleTest)
ADD_GOOGLE_TEST(tstColor.cc NP 1)
#include "gtest/gtest.h"
TEST(Radix, Color)
{
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment