remove duplicates from array doesn't work (VEX)

   1045   0   0
User Avatar
Member
5 posts
Joined: Nov. 2019
Offline
int primAmt= nprimitives(geoself());
vector currentN = 0; // = prim(0,"PrimN",0);
vector uniqueN[];

for(int i =0; i<primAmt;i++){
    currentN = prim(0,"PrimN",i);
    
    
    int noN = find(uniqueN,currentN);
    
    if(noN<0){
        append(uniqueN,currentN);
    }

I don't see why this shouldn't work, but it doesn't. Can somebody clear things up for me?

The geo spreadsheet shows what I start with, and the console shows the results I get from the script.

Thanks in advance

EDIT:
Ok I found it's due to floating point inconsistencies. I wish there was a simple solution to just round to a certain decimal place with a function. If this is a common problem in Houdini there should be some integrated method to deal with it.

EDIT 2:

I solved the issue by multiplying my values by 1000000, truncating them, and dividing by 1000000 again.
Edited by hghtch - Feb. 27, 2021 21:53:39

Attachments:
startvals.jpg (19.2 KB)
resultvals.jpg (10.6 KB)

  • Quick Links