• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ParadoxGameConverters / commonItems / 12477838745

24 Dec 2024 06:12AM UTC coverage: 77.556% (+16.9%) from 60.619%
12477838745

push

github

web-flow
Create a cmake target for the commons library (#272)

* Create a cmake target for the commons.

* Fix a broken test.

* Update workflows

* More workflow updates

* Add a windows cmake workflow

* More workflow updates.

* Double-dash

* Check folder

* Fix presets

* No /w

* Disable clang-tidy

* Update name.

* Try correcting directory.

* Build both targets.

* More path fixes.

* Even more path fixes.

* In both builds

* Add gcov and lcov targets

* Maybe don't change folders?

* Don't initially build gcov and lcov

* Use correct profile

* Just get the commands from vic3tohoi4

* Fix syntax error

* In both parts

* Borrow more from converter

* More tweaks

* Peek at directories.

* More folders

* Add some echos

* Moar folders

* Focus more

* Maybe these are the right dirs?

* Woah, we're halfway there!

* Maybe not the preceding folders?

* Correct path to coverage report

* Update exclusions.

* Don't get coverage of tests.

* Exclude nlohmann

* Fix path

* No need for gcov

* Remove another few gcov references

* One more workflow

1 of 1 new or added line in 1 file covered. (100.0%)

34 existing lines in 7 files now uncovered.

1745 of 2250 relevant lines covered (77.56%)

238.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Color.h
1
#ifndef COLOR_H
2
#define COLOR_H
3

4

5

6
// Represents a Paradox - defined color.
7
//
8
// Can be directly created in either the RGB or HSV color spaces.
9
// If alpha is persent we're assuming it's RGBA or HSVA.
10
//
11
// Can be imported in :
12
// * Unspecified with ints(becomes RGB) - "= { 64 128 128 }"
13
// * Unspecified with three floats(becomes RGB) - "= { 0.5 0.9 0.1 }"
14
// * Unspecified with four floats(becomes RGBA) - "= { 0.5 0.9 0.1 0.1 }"
15
// * RGB - "= rgb { 64 128 128 }"
16
// * Hex - "= hex { 408080 }"
17
// * HSV - "= hsv { 0.5 0.5 0.5 }"
18
// * HSVA - "= hsv { 0.5 0.5 0.5 0.1 }"
19
// * HSV360 - "= hsv360 { 180 50 50 }"
20
// * Name(requires caching definitions for the named colors in advance) - "= dark_moderate_cyan"
21
//
22
// Can be output in :
23
// * unspecified(rgb) - "= { 64 128 128 }"
24
// * RGB - "= rgb { 64 128 128 }"
25
// * RGBA - we don't export RGBA. yet.
26
// * hex - "= hex { 408080 }"
27
// * HSV - "= hsv { 0.5 0.5 0.5 }"
28
// * HSVA - "= hsv { 0.5 0.5 0.5 0.1 }"
29
// * HSV360 - "= hsv360 { 180 50 50 }"
30
//
31
// The individual components can be accessed in both RGB and HSV color spaces, equality and inequality can be checked, the color cache can be reviewed and
32
// modified, and colors can have a random fluctuation be applied automatically.
33

34

35

36
#include "Parser.h"
37
#include <array>
38
#include <iostream>
39

40

41

42
namespace commonItems
43
{
44

45
class Color
46
{
47
  public:
48
        class Factory;
UNCOV
49
        Color() = default;
×
50
        explicit Color(std::array<int, 3> rgbComponents);
UNCOV
51
        explicit Color(std::array<int, 3> rgbComponents, float alpha): rgbComponents(rgbComponents), alpha(alpha) { deriveHsvFromRgb(); }
×
UNCOV
52
        explicit Color(std::array<float, 3> hsvComponents): hsvComponents(hsvComponents) { deriveRgbFromHsv(); }
×
UNCOV
53
        explicit Color(std::array<float, 3> hsvComponents, float alpha): hsvComponents(hsvComponents), alpha(alpha) { deriveRgbFromHsv(); }
×
54

55
        std::partial_ordering operator<=>(const Color&) const = default;
56

57
        [[nodiscard]] const auto& getRgbComponents() const { return rgbComponents; }
58
        [[nodiscard]] const auto& getHsvComponents() const { return hsvComponents; }
59
        [[nodiscard]] const auto& r() const { return rgbComponents[0]; }
60
        [[nodiscard]] const auto& g() const { return rgbComponents[1]; }
61
        [[nodiscard]] const auto& b() const { return rgbComponents[2]; }
62
        [[nodiscard]] const auto& h() const { return hsvComponents[0]; }
63
        [[nodiscard]] const auto& s() const { return hsvComponents[1]; }
64
        [[nodiscard]] const auto& v() const { return hsvComponents[2]; }
65
        [[nodiscard]] const auto& a() const { return alpha; }
66

67
        [[nodiscard]] std::string outputRgb() const;
68
        [[nodiscard]] std::string outputHex() const;
69
        [[nodiscard]] std::string outputHsv() const;
70
        [[nodiscard]] std::string outputHsv360() const;
71

72
        // All three color components will go up or down by the some amount (according to stdDev), and then each is tweaked a
73
        // bit more (with a much smaller standard deviation).
74
        void RandomlyFluctuate(int stdDev);
75

76
        friend std::ostream& operator<<(std::ostream& out, const Color& color);
77

78
  private:
79
        void deriveHsvFromRgb();
80
        void deriveRgbFromHsv();
81

82
        std::array<int, 3> rgbComponents{0, 0, 0};
83
        std::array<float, 3> hsvComponents{0.0F, 0.0F, 0.0F};
84
        std::optional<float> alpha;
85
};
86

87

88
std::ostream& operator<<(std::ostream& out, const Color& color);
89

90

91
class Color::Factory: parser
92
{
93
  public:
94
        [[nodiscard]] Color getColor(std::istream& theStream) const;
95
        [[nodiscard]] Color getColor(const std::string& colorName) const;
96
        [[nodiscard]] const auto& getRegisteredColors() const { return namedColors; }
97

98
        void addNamedColor(const std::string& name, const Color& color);
99
        void addNamedColor(const std::string& name, std::istream& theStream);
100
        void addNamedColorMap(const std::map<std::string, Color>& colorMap);
101

102
        void clear() { namedColors.clear(); }
103

104
  private:
105
        std::unordered_map<std::string, Color> namedColors;
106
};
107

108
} // namespace commonItems
109

110

111

112
#endif // COLOR_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc