Commit b1e2b5cc8eec1ecd7ccd5cbbc2dc812144d617fa

Authored by Jojo-1000
Committed by Moritz Wirger
1 parent f58059d8

Move mired to kelvin conversion out of Light.

.travis.yml
... ... @@ -7,8 +7,8 @@ env:
7 7 - DEPS_DIR=${TRAVIS_BUILD_DIR}/deps
8 8 # compiler settings
9 9 - COMPILER_NAME=gcc
10   - - CXX=g++-5
11   - - CC=gcc-5
  10 + - CXX=g++-9
  11 + - CC=gcc-9
12 12 # Misc
13 13 - RUN_TESTS=true
14 14 - COVERAGE=false
... ... @@ -23,10 +23,10 @@ matrix:
23 23 addons:
24 24 apt:
25 25 packages:
26   - - gcc-5
27   - - g++-5
28 26 # Misc
29 27 - python-yaml
  28 + - gcc-5.5
  29 + - g++-5.5
30 30 - doxygen
31 31 - graphviz
32 32 sources: &sources
... ...
include/hueplusplus/ColorUnits.h
... ... @@ -141,6 +141,18 @@ struct RGB
141 141 //! This is because the color luminosity is not saved.
142 142 static RGB fromXY(const XYBrightness& xy, const ColorGamut& gamut);
143 143 };
  144 +
  145 +//! \brief Const function that converts Kelvin to Mired.
  146 + //!
  147 + //! \param kelvin Unsigned integer value in Kelvin
  148 + //! \return Unsigned integer value in Mired
  149 +unsigned int kelvinToMired(unsigned int kelvin);
  150 +
  151 +//! \brief Const function that converts Mired to Kelvin.
  152 +//!
  153 +//! \param mired Unsigned integer value in Mired
  154 +//! \return Unsigned integer value in Kelvin
  155 +unsigned int miredToKelvin(unsigned int mired);
144 156 } // namespace hueplusplus
145 157  
146 158 #endif
... ...
include/hueplusplus/Light.h
... ... @@ -143,18 +143,6 @@ public:
143 143 //! when not
144 144 virtual bool hasColorControl() const { return colorHueStrategy != nullptr; };
145 145  
146   - //! \brief Const function that converts Kelvin to Mired.
147   - //!
148   - //! \param kelvin Unsigned integer value in Kelvin
149   - //! \return Unsigned integer value in Mired
150   - unsigned int kelvinToMired(unsigned int kelvin) const;
151   -
152   - //! \brief Const function that converts Mired to Kelvin.
153   - //!
154   - //! \param mired Unsigned integer value in Mired
155   - //! \return Unsigned integer value in Kelvin
156   - unsigned int miredToKelvin(unsigned int mired) const;
157   -
158 146 //! \brief Function that sets the brightness of this light.
159 147 //!
160 148 //! \note The brightness will only be set if the light has a reference to a
... ...
src/ColorUnits.cpp
... ... @@ -197,4 +197,14 @@ RGB RGB::fromXY(const XYBrightness& xy, const ColorGamut& gamut)
197 197 }
198 198 }
199 199  
  200 +unsigned int kelvinToMired(unsigned int kelvin)
  201 +{
  202 + return int(std::round(1000000.f / kelvin));
  203 +}
  204 +
  205 +unsigned int miredToKelvin(unsigned int mired)
  206 +{
  207 + return int(std::round(1000000.f / mired));
  208 +}
  209 +
200 210 } // namespace hueplusplus
201 211 \ No newline at end of file
... ...
src/Light.cpp
... ... @@ -92,16 +92,6 @@ ColorGamut Light::getColorGamut() const
92 92 }
93 93 }
94 94  
95   -unsigned int Light::kelvinToMired(unsigned int kelvin) const
96   -{
97   - return int(0.5f + (1000000 / kelvin));
98   -}
99   -
100   -unsigned int Light::miredToKelvin(unsigned int mired) const
101   -{
102   - return int(0.5f + (1000000 / mired));
103   -}
104   -
105 95 bool Light::alert()
106 96 {
107 97 return transaction().alert().commit();
... ...
test/test_ColorUnits.cpp
... ... @@ -188,3 +188,23 @@ TEST(RGB, fromXY)
188 188 EXPECT_LE(maxDiffB, 64);
189 189  
190 190 }
  191 +
  192 +TEST(ColorUnits, kelvinToMired)
  193 +{
  194 + EXPECT_EQ(10000, kelvinToMired(100));
  195 + EXPECT_EQ(500, kelvinToMired(2000));
  196 + EXPECT_EQ(303, kelvinToMired(3300));
  197 + EXPECT_EQ(250, kelvinToMired(4000));
  198 + EXPECT_EQ(200, kelvinToMired(5000));
  199 + EXPECT_EQ(167, kelvinToMired(6000));
  200 +}
  201 +
  202 +TEST(ColorUnits, miredToKelvin)
  203 +{
  204 + EXPECT_EQ(100, miredToKelvin(10000));
  205 + EXPECT_EQ(2000, miredToKelvin(500));
  206 + EXPECT_EQ(3300, miredToKelvin(303));
  207 + EXPECT_EQ(4000, miredToKelvin(250));
  208 + EXPECT_EQ(5000, miredToKelvin(200));
  209 + EXPECT_EQ(6024, miredToKelvin(166)); // 6000 kelvin should be 166 mired, but is rounded
  210 +}
191 211 \ No newline at end of file
... ...
test/test_Light.cpp
... ... @@ -362,41 +362,6 @@ TEST_F(HueLightTest, getColorType)
362 362 EXPECT_EQ(ColorType::GAMUT_C_TEMPERATURE, test_light_3.getColorType());
363 363 }
364 364  
365   -TEST_F(HueLightTest, kelvinToMired)
366   -{
367   - const Light ctest_light_1 = test_bridge.lights().get(1);
368   - const Light ctest_light_2 = test_bridge.lights().get(2);
369   - const Light ctest_light_3 = test_bridge.lights().get(3);
370   - Light test_light_1 = test_bridge.lights().get(1);
371   - Light test_light_2 = test_bridge.lights().get(2);
372   - Light test_light_3 = test_bridge.lights().get(3);
373   -
374   - EXPECT_EQ(10000, ctest_light_1.kelvinToMired(100));
375   - EXPECT_EQ(500, ctest_light_2.kelvinToMired(2000));
376   - EXPECT_EQ(303, ctest_light_3.kelvinToMired(3300));
377   - EXPECT_EQ(250, test_light_1.kelvinToMired(4000));
378   - EXPECT_EQ(200, test_light_2.kelvinToMired(5000));
379   - EXPECT_EQ(166, test_light_3.kelvinToMired(6000));
380   -}
381   -
382   -TEST_F(HueLightTest, miredToKelvin)
383   -{
384   - const Light ctest_light_1 = test_bridge.lights().get(1);
385   - const Light ctest_light_2 = test_bridge.lights().get(2);
386   - const Light ctest_light_3 = test_bridge.lights().get(3);
387   - Light test_light_1 = test_bridge.lights().get(1);
388   - Light test_light_2 = test_bridge.lights().get(2);
389   - Light test_light_3 = test_bridge.lights().get(3);
390   -
391   - EXPECT_EQ(100, ctest_light_1.miredToKelvin(10000));
392   - EXPECT_EQ(2000, ctest_light_2.miredToKelvin(500));
393   - EXPECT_EQ(3300, ctest_light_3.miredToKelvin(303));
394   - EXPECT_EQ(4000, test_light_1.miredToKelvin(250));
395   - EXPECT_EQ(5000, test_light_2.miredToKelvin(200));
396   - EXPECT_EQ(6024, test_light_3.miredToKelvin(166)); // 6000 kelvin should be 166 mired, but keep in
397   - // mind flops are not exact
398   -}
399   -
400 365 TEST_F(HueLightTest, hasBrightnessControl)
401 366 {
402 367 const Light ctest_light_1 = test_bridge.lights().get(1);
... ...