-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parsing color_t #2015
base: master
Are you sure you want to change the base?
Add parsing color_t #2015
Conversation
86a9843
to
29a20f3
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2015 +/- ##
==========================================
+ Coverage 95.79% 95.82% +0.02%
==========================================
Files 128 128
Lines 10396 10560 +164
==========================================
+ Hits 9959 10119 +160
- Misses 437 441 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f75e84a
to
4ae7f9b
Compare
4ae7f9b
to
eaf2963
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nitpicks as per tradition but look good :)
@VittorioSanchez Is this ready for review ? :) |
Yes it is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work, a few questions though
Please resolve discussions you have adressed and ping me and @snoyer for a review when ready @VittorioSanchez :) |
the |
|
||
See [W3C](https://www.w3.org/TR/css-color-3/#rgb-color) doc for more details on these formats. | ||
|
||
When formatting a color into a string, it is formatted as `#RRGGBB` if values are multiple of 255. Otherwise, it is formatted as `R,G,B` where R, G, B are doubles between 0 and 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When formatting a color into a string, it is formatted as `#RRGGBB` if values are multiple of 255. Otherwise, it is formatted as `R,G,B` where R, G, B are doubles between 0 and 1. | |
When formatting a color into a string, it is formatted as `#RRGGBB` if values are multiple of 255. Otherwise, it is formatted as vector of doubles. |
Color are parsed and formatted as a vector of double. | ||
The following formats are supported when parsing a color, case insensitive: | ||
|
||
- R,G,B where R, G, B are doubles [0, 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- R,G,B where R, G, B are doubles [0, 1] | |
- R,G,B where R, G, B are doubles >= 0 |
} | ||
|
||
/* Named colors search */ | ||
vtkSmartPointer<vtkNamedColors> color = vtkSmartPointer<vtkNamedColors>::New(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vtkSmartPointer<vtkNamedColors> color = vtkSmartPointer<vtkNamedColors>::New(); | |
vtkNew<vtkNamedColors> color; |
|
||
/* Vector double format */ | ||
std::vector<double> vecColor = options_tools::parse<std::vector<double>>(str); | ||
if (std::any_of(vecColor.begin(), vecColor.end(), [](double value) { return !(value >= 0.0); })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should remove this check. Anyone using the struct API can directly put negative values in anyway so its not like we can then skip checks later on, and it restrict a bit what the user can do.
If it makes sense to someone to input negative values, it may be simpler to let them (and catch the error later when we use the value, which we already do)
} | ||
/* We do not catch std::invalid_argument exception from stod as it is covered by the regex */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nor std::out_of_range
return options_tools::format(static_cast<std::vector<double>>(var)); | ||
const std::vector<double> colors = { var.r(), var.g(), var.b() }; | ||
if (std::all_of(colors.begin(), colors.end(), | ||
[](double val) { return (val >= 0 && val <= 1 && std::fmod(val * 255., 1) < 1e-9); })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does using std::epsilon makes sense here ?
@@ -110,8 +110,39 @@ int TestSDKOptionsIO(int argc, char* argv[]) | |||
|
|||
test.parse<f3d::color_t>("color_t", "0.1,0.2,0.3", { 0.1, 0.2, 0.3 }); | |||
test.parse<f3d::color_t>("color_t", " 0.1, 0.2 , 0.3 ", { 0.1, 0.2, 0.3 }); | |||
test.parse<f3d::color_t>("color_t", "#FFFFFF", { 1.0, 1.0, 1.0 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at w3c, it looks like they also list #FFF as supported format. Does that work ? If not is it easy to add ?
test.parse_expect<f3d::color_t, parsing_exception>("incorrect size color_t", "0.1,0.2,0.3,0.4"); | ||
test.parse_expect<f3d::color_t, parsing_exception>("invalid color_t", "-0.1,-0.2,-0.3"); | ||
test.parse_expect<f3d::color_t, parsing_exception>( | ||
"out of range color_t", std::string(outOfRangeDoubleStr + ",0.2,0.3")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not following this test ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some questions and remarks
Added parsing for:
These are case insensitive and whitespace insensitive. % symbol is also optional.
Limits are checked and throws error if out of range.
Updated doc and added tests
Fix: #2003