Consider a Euclidean space $\mathbb{R}^d$. Consider $ X \subset \mathbb{R}^d$ where $X$ is a finite set with $|X|=n$. Consider the set of line segments $\{xy | x,y \in X\}$ . I have a process $Z$ that I want to apply to each line segment, from smallest to largest but I will stop examining line segments when a line segment satisfies some condition $C$.
One thing I could do is find all line segments and then order them from smallest to largest and simply apply $Z$ to each line segment until $C$ is satisfied but organising the line segments will have $O(n^2\log (n))$ complexity.
Is there an efficient way I can find each line segment in order of increasing length, one at a time.
That is, find a line segment $l$, apply $Z$ to $l$ and if $C$ is not satisfied find the next largest line segment, apply $Z$,...
Thank you in advance