I have an iterator p and a vertex curvePoints:
for (p = curvePoints.begin(); p != curvePoints.end(); p++) {
p->x = (1 - u) * p->x + u * (p+1)->x;
p->y = (1 - u) * p->y + u * (p+1)->y;
}
Right now the loops use the value of the next indexed object; how can I guarantee that that next value exists. In other words, how can I make the loop condition something like (p+1) != curvePoints.end() or p != curvePoints.end() - 1.
You can use std::distance(p, curvePoints.end()) > 1 as you condition.
http://www.cplusplus.com/reference/std/iterator/distance/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With