Index range selection that wraps around

This forum structure is very confusing, so I hope this question ends up in the correct place. Anyways:

I’m trying to select a range of points in a curve and I want to be able to select points “wrapping around”, for example from the last index in a curve to the second index. I’ve made a setup with floored modulo selection and compare nodes, but it fails when the index is 0. I’ve managed to deduce that the problem is my boolean logic, but I can’t really figure out what I need to do to fix it. Any ideas would be highly appreciated!


When your range wraps around (when the lower bound is greater than the upper bound,) you will need two separate selection windows: one from 0 to the upper bound, and the other from the lower bound to the maximum index. (Otherwise the lower bound and upper bound will work like you’d expect.) You’ll want to join these two selections with a Boolean “or.”

Could you let us know what you are trying to do? I had a setup to generate balconies by deleting modulo 4 from the start and from the end so the setup will give symmetrical pattern. I attach the setup here, just in case it has similar logic with what you want to do


This is what you mean, I think? Could be many other ways to do it, I’m sure:

Couldn’t wrap my head around the modulo math with negative numbers, so I decided to look at the absolute distance between each Index and the chosen index (IndexSelection). If the ‘distance’ is close enough (less than the given range) it is selected. Halving the domain size first allows me to ‘center’ the chosen index:

Thank you, this works like I intended! Now I only have to figure out why it works… :sweat_smile:

Apologies. I’m really no good at math so even when I manage to solve a problem I tend to do it in convoluted ways… I tried my hand at a more understandable version here (I think it’s equal or similar to what @Solvent was describing):

The logic is like this: assuming a loop of points means we have, topologically, a circle. Given a central index (X), we subtract every other index (P) from that center to find the distance between them. If this was a line, we could simply use that distance to compare to the Selection Range, using an Absolute to handle the negative values. However, this is a circle, simply using that distance would mean always taking the long route when going the other way could be the shorter path, so we need to use a Floored Modulo to wrap it around at domain size.

Floored Modulo makes the travel circular, but depending on the order of operation, the result will sometimes give the longer path (clockwise) and sometimes the shorter one (counterclockwise). But that’s fine: If the modulo result is smaller than Selection Range, it means P is close enough to X anyways. Conversely, if the modulo result is bigger than Outside Range (Domain Size - Selection Range) it also means P should be close enough to X (like someone starting to walk from South Pole towards north and walk so much that they wrap around earth to come close to South Pole again). If a point satisfies either comparison (OR) you select it.*


*Not technically a %100 accurate summary/diagram but I simplified to show it in one go.