Pulling numbers up or down to match a predefined list?

Hi,

Today I’m playing a bit with some data to generate lines with a specific precise width.
I have pulled a list of numbers from an output with a domain between 0.2 and 2.0

Now what I want to do with this list is to have all the values that are close to a set of seven values, to be pulled towards those values.

So as an example:
0.4 becomes 0.35
1.7 becomes 2
1.2 becomes 1
0.8 becomes 0.7
etc
etc

Is there a function that can do this and leave the data in the tree intact? I have managed to tackle many challenges, but this is above my knowledge. So the desired end result is a list that only contains values that match values from the list (see image).

To make it easy I have attached the file with the data:
pulldata_1.gh (11.3 KB)

I hope someone knows how to achieve this, if anything’s unclear, let me know!

For third method you’ll need closestNumbers from Heteroptera plug-in.


Marinus.gh (26.3 KB)

1 Like

you might do something like this: falls into a domain → then becomes → value


pulldata_1_re.gh (17.7 KB)

as it’s written, the domain boundaries are exactly in the middle between previous value and next value

this means that line thickness 1.5 will become 1 and line thickness 1.6 will become 2

but of course you can generate your own domain list as “X to Y” and use like this:


pulldata_1_re2.gh (14.0 KB)

2 Likes

Pufferfish plugin has a feature.


pulldata_1_re.gh (11.8 KB)

3 Likes


pulldata_2021Nov09a.gh (17.6 KB)

1 Like

Absolutely works fine, thanks a lot. I chose to go the Heteroptera route. I should’ve searched for a ‘closest[…]’ in the double click menu to add a new component before asking here. I already had Heteroptera installed.

Super useful advice. Thanks again.

Also thanks to everyone else replying in this topic. I had not expected an answer this soon, it’s so wonderful to see how people are helping each other out here. I hope my question can be of use to a future someone as well.

I totally missed this one, thanks. I was already using ‘Round to Decimal Place’ from Pufferfish but I didn’t know ‘Round to Nearest’ could do this as well. Super useful!