diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..4039befa --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..06036ff9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "ostream": "cpp", + "stdexcept": "cpp", + "cmath": "cpp" + } +} \ No newline at end of file diff --git a/include/gz/math/Color.hh b/include/gz/math/Color.hh index 595d48b6..6412aa60 100644 --- a/include/gz/math/Color.hh +++ b/include/gz/math/Color.hh @@ -159,14 +159,14 @@ namespace gz /// 3=alpha) /// \return r, g, b, or a when _index is 0, 1, 2 or 3. A NAN_F value is /// returned if the _index is invalid - public: float &operator[](const unsigned int _index); + public: float& operator[](const unsigned int _index); /// \brief Array index operator, const version /// \param[in] _index Color component index(0=red, 1=green, 2=blue, /// 3=alpha) /// \return r, g, b, or a when _index is 0, 1, 2 or 3. A NAN_F value is /// returned if the _index is invalid - public: float operator[](const unsigned int _index) const; + public: const float& operator[](const unsigned int _index) const; /// \brief Get as uint32 RGBA packed value /// \return the color diff --git a/src/Color.cc b/src/Color.cc index aa1ebca2..e4f6271c 100644 --- a/src/Color.cc +++ b/src/Color.cc @@ -16,6 +16,7 @@ */ #include #include +#include #include "gz/math/Color.hh" @@ -187,13 +188,28 @@ void Color::SetFromYUV(const float _y, const float _u, const float _v) } ////////////////////////////////////////////////// -const float &Color::operator[](const unsigned int _index) +float& Color::operator[](const unsigned int _index) { - return (*static_cast(this))[_index]; + switch (_index) + { + case 0: + return this->r; + case 1: + return this->g; + case 2: + return this->b; + case 3: + return this->a; + default: + break; + } + + std::cerr << "Trying to read index " << _index << " of Color"<