Ids stored in the id attribute cannot be assumed to be unique. While they might be unique in many cases, this is not something that can be guaranteed in general. For some use cases (e.g. generating "stable randomness" on points) uniqueness is not important. To support features like motion blur, unique ids are important though.
This patch implements a simple algorithm that turns non-unique ids into unique ids. Obviously, there are limits to how successful this can be. Here are some requirements I set:
- Ids that are unique already, must not be changed/
- If there are id collisions, only ids that collide should be changed.
- The same input should generate the same output.
- Handle the cases when all ids are different and when all ids are the same equally well (in expected linear time).
- Small changes in the input id array should ideally only have a small impact on the output id array.