Comments (7)
What is the possible range (set of valid types) of T
? I think I have written similar code in the past, where my assumption was that the divisor must be a wide floating point value for the operation to make sense, which would explain the second double
argument. And then it would make sense to use simple type promotion to compute the return type, which may just be double
, too, in this case.
(I'm just thinking aloud, trying to mentally reproduce why the code was written the way it is.)
from gil.
@mloskot Is there not a better point class in boost? Wouldn't that be better than using gil::point2?
from gil.
It's such a trivial class...
I'm not sure it would be worthwhile dragging in another dependency just for that. Besides, there are rather specific requirements for it (See http://boostorg.github.io/gil/html/design_guide.html#point) that I'm not sure any pre-existing class would meet without additional adapter code.
(And speaking of requirements: the /=
signature using double
actually comes from the concept itself.)
from gil.
I agree with @stefanseefeld that pulling Boost.Geometry or whatever as a dependency would not buy as anything really, but potential maintenance hassle.
I will look at implementing the idea of promoting the return type to best float-point type matching the operands.
from gil.
@stefanseefeld & @chhenning
How about replacing the current double
-hardwired point<T>::operator/
with template function auto-promoting the base T
of its point<T>
result using std::common_type which I had no idea about until today :-)
template <typename T, typename D>
auto operator/(point<T> const& p, D d)
{
static_assert(std::is_arithmetic<D>::value, "denominator is not arithmetic type");
using numeric_type = typename std::common_type<T, D>::type;
return point<numeric_type>(p.x / t, p.y / t);
}
Test:
point<int> p1;
static_assert(std::is_same<decltype((p1 / short{}).x), int>::value, "!int");
static_assert(std::is_same<decltype((p1 / int{}).x), int>::value, "!int");
static_assert(std::is_same<decltype((p1 / float{}).x), float>::value, "!float");
static_assert(std::is_same<decltype((p1 / double{}).x), double>::value, "!double");
point<float> p2;
static_assert(std::is_same<decltype((p2 / int{}).x), float>::value, "!float");
static_assert(std::is_same<decltype((p2 / float{}).x), float>::value, "!float");
static_assert(std::is_same<decltype((p2 / double{}).x), double>::value, "!double");
from gil.
Yeah, perfect !
from gil.
Fixed by #157
from gil.
Related Issues (20)
- Add tests for PR #505 with RGB to HSL fix
- Refactor any_image tests after deprecating apply_operation in #656
- Remove C++11 build jobs from CI HOT 2
- Fix wrong pixel channel truncation in binary threshold and truncate threshold HOT 2
- Consider moving channel_convert_to_unsigned out of detail namespace
- color_convert_hsl / gcc-5~c++14: converting to std::tuple from initializer list would use explicit constructor constexpr std::tuple
- color_convert_rgb / gcc-5~c++14: converting to std::tuple from initializer list would use explicit constructor constexpr std::tuple
- color_convert_hsl.cpp and color_convert_rgb.cpp error: no matching constructor for initialization of std::vector<color_t>
- Allow implicit conversion from gray8_ptr_t to gray8_step_ptr_t HOT 3
- g++ 12.1.1 fails to compile Boost.GIL with -std=c++20 HOT 3
- unsued variable warning
- Convolution2d seems to be not correct. HOT 1
- stream device "tell" method absent! HOT 2
- Support for reading/writing 1 bit (black/white) BMP images? HOT 2
- Alpha-blending HOT 4
- Overflow in channel convertion HOT 2
- heap-buffer-overflow when using io-related functions HOT 1
- Running the convolve_2d.cpp test causes an alignment error on ARM
- About Enterprise Managed Users - GitHub Enterprise Cloud Docs
- https://docs.github.com/es/[email protected]/admin/monitoring-managing-and-updating-your-instance/updating-the-virtual-machine-and-physical-resources/upgrading-github-enterprise-server HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gil.