Wrapping or capping numbers in a domain

I’m trying to move points along both closed curves and open curves using evaluate length.

If I have a number going to the “Length” input of evaluate length and I add to the number and create a result that’s longer than a curve’s length, I get an error. Same if I subtract and I get a result lower than zero.

For closed curves, I wanted input less that zero to wrap backwards beyond the seam, and input over the curve length to wrap forwards beyond the seam.

For open curves, I wanted input less than zero to return zero, and input over the curve length to return the curve length.

Here’s the definition I wrote to do this. Wrap Numbers.gh (45.0 KB) It almost works, but I’m wondering if, as usual, I made something overcomplicated.


  1. Is there some domain component that will wrap numbers like I did for closed curves? or some simpler way to do this?

  2. Is there some math or logic component that will limit numbers to a range like I did for the open curves?

  3. My definition (I think because I’m using sift pattern/combine data) , only works with a pair of matched lists as input. Is there a way rewrite this to make it work with, for instance, a single input and a list, or a list and a tree, the way standard GH component works?

For both ways I would use Expression or Evaluate component for doing multiple math operation at once.

  1. This is a bit tricky but you could do it by modulo. First you need to transform your number to range 0.0 to 1.0. Then you you have to add some big integer to keep the result always larger then 0 (otherwise it wouldn’t work for negative numbers). Next you evaluate modulo by 1.0 (it will return you remainder of integer division - simply whatever is after dot. in this case). And at the and you will multiply it by length get it back from normalized (0.0 to 1.0) value. It sounds more difficult than it is.

((( x / length ) + 1000 ) % 1.0 ) * length

  1. You could do it by using min and max functions:


where a is minimum, b is maximum and x is your value

  1. I would rather use Dispatch and Weave. You don’t need to care about Null then.

Wrap Numbers_2.gh (14.8 KB)

1 Like

Few year ago I’ve made this Python component which will fit number to domain:

1 Like