Skip to content

Commit

Permalink
[core] Allow instantiation of TColorNumber from RGB arrays
Browse files Browse the repository at this point in the history
This allows pass Python tuples to any of the `Set*Color` methods.
  • Loading branch information
guitargeek committed Nov 27, 2024
1 parent c3174e5 commit aa0fbda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/base/inc/TColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "TNamed.h"

#include <array>
#include <vector>

class TArrayI;
Expand Down Expand Up @@ -140,6 +141,7 @@ class TColorNumber {
public:
TColorNumber(Int_t color) : fNumber{color} {}
TColorNumber(std::string const &color);
TColorNumber(std::array<Float_t, 3> rgb);
Int_t number() const { return fNumber; }

private:
Expand Down
5 changes: 5 additions & 0 deletions core/base/src/TColor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3646,6 +3646,7 @@ void TColor::InvertPalette()
std::reverse(fgPalette.fArray, fgPalette.fArray + fgPalette.GetSize());
}

////////////////////////////////////////////////////////////////////////////////
/// The `color` string argument argument will be evaluated
/// to get the actual ROOT color number, like `kRed`.
/// Here is how the string is parsed:
Expand Down Expand Up @@ -3681,3 +3682,7 @@ TColorNumber::TColorNumber(std::string const &color)
throw std::invalid_argument(msg.str());
}
}

////////////////////////////////////////////////////////////////////////////////
/// Instantiate a color from a tuple of RGB values between 0.0 and 1.0.
TColorNumber::TColorNumber(std::array<Float_t, 3> rgb) : fNumber{TColor::GetColor(rgb[0], rgb[1], rgb[2])} {}

0 comments on commit aa0fbda

Please sign in to comment.