Question
This is what has been listening to me for some time, but I could not find a definitive answer to it:
- Does anyone know of a proposal for embedding a standard 2D and / or 3D vector (structures with elements x, y, and z) in the STL?
- If not, is there a realistic way to get such a class in the next version of the standard — unless you write a complete and perfectly written sentence?
- And are there good reasons (except for those who do not have time) why this has not yet been done?
I am definitely ready to contribute, but I believe that I do not have enough experience to produce something of high enough quality for adoption (I am not a professional programmer).
Reasoning / Background
To date, I have seen dozens of libraries and frameworks (be it graphics, physics, mathematics, navigation, sensor fusion ...), which basically implement their own version
struct Vector2d { double x,y;
and / or its three-dimensional equivalent - not to mention all the cases when I myself implemented it before I took the time to make the correct, reusable version.
Obviously, this is not something difficult, and I'm not worried about suboptimal implementations, but every time I want to combine two libraries or reuse code from another project, I have to take care of converting one version to another (either casting or - if perhaps a text replacement).
Now that the committee seeks to significantly expand the standard library for C ++ 17 (especially with 2D graphics), I would like from the very beginning I would like to have a common 2D vector baked in all interfaces, so I can just write, eg:
drawLine(transformCoordinates(trackedObject1.estimatePos(),params), transformCoordinates(trackedObject2.estimatePos(),params));
but not
MyOwnVec2D t1{trackedObject1.estimatePosX(), trackedObject1.estPosY()}; MyOwnVec2D t2{trackedObject2.estimatePosX(), trackedObject2.estPosY()}; t1 = transformCoordinates(t1,params); t2 = transformCoordinates(t2,params); drawLine(t1.x,t1.y,t2.x,t2.y);
The example may be a little exaggerated, but I think it shows my point.
I know std::valarray , which is already going in the right direction, since it allows you to perform standard operations such as addition and multiplication, but it carries too much weight if you need only two or three coordinates. I think a valarray with a fixed size and no dynamic memory allocation (e.g. based on std::array ) would be an acceptable solution, especially since it would have a trivial iterator implementation, but I personally would prefer a class with x, y (and z).
Note: I'm sorry if this topic has already been discussed (and I would be surprised if it weren’t for it), but every time I look for 2d vectors, I get results that say something like std::vector<std::vector<T>> or how to implement a certain transformation, but not on the topic of standardization.