Skip to content
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

ofVec, double precision? #1847

Closed
armadillu opened this issue Jan 31, 2013 · 11 comments
Closed

ofVec, double precision? #1847

armadillu opened this issue Jan 31, 2013 · 11 comments

Comments

@armadillu
Copy link
Contributor

I'm working on a project where I need double precision.

I've had a look at ofVec2f, ofVec3f and ofVec4f, and I see they are independent classes. Obviously the easy route would be to make more custom classes (ofVec2d, ofVec3d and ofVec4d); but it feels kinda wrong.

Maybe it would make sense to template ofVec "à la" ofImage? (although that would be much more work, and most likely slower execution).

@elliotwoods
Copy link
Contributor

elliotwoods commented Feb 1, 2013

+1
this sounds very practical and inevitable
template ofVec?T classes on T

@kylemcdonald
Copy link
Contributor

i don't think templating ofVec would cause slower execution. templates are evaluated at compile time, so it would be exactly the same as using custom code. i think it's also "the right way" to solve the problem.

that said, templating the math classes is kind of a big job and could lead to a lot of new bugs. if someone wants to volunteer to tackle this, i'm guessing everyone else would be open to it -- but it'd be really important to write a few examples that show the behavior hasn't changed (and isn't different in the case of vec2f vs vec2d).

@bilderbuchi
Copy link
Member

I think templating the math classes would be a prime opportunity to start with some kind of automated testing for OF. We could ascertain that the results don't change with double precision in an automated way, and while examples are really practical for some tests, I'm not sure they're the best way to approach math tests. We even already got volunteers recently for this: in #1068, @diasbruno showed interest in starting a testing effort for OF.

@diasbruno
Copy link

hi, i'm trying to get the openFrameworks' core running with automated tests. so, i'm using this # to figure out the best way to make it.

hope this can help.

https://github.com/diasbruno/ofCoreTest/tree/feature-ofVec-templates/src/template-ofVec (i'm still working on it)

@bakercp
Copy link
Member

bakercp commented May 31, 2013

Just cross listing a related issue #1821

@memo
Copy link
Member

memo commented May 31, 2013

Definitely +1000 for templated ofVec and in fact all math functions.

Cinder has been doing this from the start and it's ace. Not only for being able to have float vs double vectors, but int vectors are quite useful, and even being able to ofMap, ofLerp, ofClamp vectors etc. as well.

It can get tricky if you start doing ofMap(f, 0, 1, 0, 100); // where f is a float, the rest are ints.
So this will give a compilation error because of ambiguity. I think you'll have to write ofMap(f, 0.0f, 0.0f, 0.0f, 100.0f); which could be a nuisance.

@elliotwoods
Copy link
Contributor

i think any invisible change of internal mechanism (i.e. templating against function arguments) has the chance to cause a lot frustration for new users, and more advanced users would perhaps be happy with explicit template argument syntax:

ofMap<int>(value, minIn, maxIn, minOut, maxOut);

The template argument would default to float.

btw, is there a reason we don't use default template arguments across oF, (e.g. ofPixels_<T>, i.e. do default template arguments not work with classes?)

@memo
Copy link
Member

memo commented Jun 1, 2013

Yea that solution didn't occur to me, it's a great idea. +1. Maybe one for
the devconf? :)

@underdoeg
Copy link
Contributor

That is a good idea. But I think default template parameters for functions are only allowed in C++11? With the old standard you can only add them to templated classes. Is C++11 widespread enough to use?

@elliotwoods
Copy link
Contributor

elliotwoods commented Jun 2, 2013

for addons, i've started using C++11 in examples, but not within the addons themselves

we eventually have to consider how to drop support for old compilers (as we have for Visual Studio 2010), and i presume at that time we'll start building up a table somewhere in the wiki that looks like (i didn't fill out the crosses correctly at all):

005
006
0061
007
0071
0072
0073
0074
XCode 3
x
x
x
x
x
x
x
x
XCode 4 (osx 10.6)

x
x
x
x
x
XCode 4 (osx 10.7)

x
x
x
x
x
XCode 4 (osx 10.8)

x
x
x
x
x
Visual Studio 2010
x
x
x
x
x
x
x

Visual Studio 2012

x
Eclipse (Linux)

Makefile (linux)

Makefile (osx)

Makefile (windows)

@armadillu
Copy link
Contributor Author

This seems to be covered by the recent move to GLM... Closing if that's cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants