Iterator for juce::Path

currently trying to find a point in a path where x == someValue
in order to do that it would be useful to have something like this:

for(const auto& p: path) if(p.x == someValue) doSomething();

Have you had a look at juce::Path::Iterator?

https://docs.juce.com/master/classPath_1_1Iterator.html

well no… not yet. but if there already is an iterator, why did no one implement the nice for loop yet? or is it just a bad idea to loop through a path for some reason?

Paths aren’t just a collection of points, and what points they do have aren’t necessarily points the stroked version of the path will pass through.

Take a bezier curve for example, it has a start and end point and then 1 or 2 control points. If you iterated those points it’d only give those 3/4 points, not a point for every x coordinate along the resultant curve.

That being said, there is also juce:PathFlatteningIterator which does convert a path containing curves into a series of straight lines and so each point given by that iterator will be a point along the curve.

Since there’s no way to know which set of points is desired by for (auto& p : path), such a feature isn’t provided so a specific iterator must be chosen.

1 Like

that makes sense. well… but then it would still be nice to have some additional methods for the path-object at least. i already solved my problem in a different way now, but if i still used the path i’d kinda like a method that works a bit like getPointAlongLine, but instead of getting a distance as argument, it would just get an x-value. that wouldn’t make sense for paths that can have multiple x values per y value, but for stuff like drawing an envelope, or an oscilloscope, or a spectrum analyzer, where you know, that the path can only go into one direction on the x-achsis, it makes a lot of sense to have a function where you get a y value for only an x value as argument and nothing else.

edit: and yes, i tried making a vertical line from my x value to the height of the component and then using getClippedLine but that didn’t do anything. i suppose it was because my path was not closed or something, but you know, sometimes one doesn’t want to close a path because it just doesn’t look good, sooo, having a getClippedLine-function that works with open paths would also solve the problem somehow

edit: or… you know what would also be cool? to have a seperate object, which is not a path, but acts very similiar to a path, with the only difference being that it’s restricted to graph-type data, where there can’t be 2 x-values for one y-value. i know something like that could already be done with a simple vector of y values. but i imagine something that also has these path-type functions, like making it curved, smoothing the edges, drawing to juce::Graphics and so on

The issue is still even if the line is straight across the X-Axis, there can still be multiple points at an x position due to a “step”

It’s a very special use case and I have the same issue – PathFlatteningIterator is the closest functionality.