# The potential of search()

4 messages
Open this post in threaded view
|

## The potential of search()

 I just found that the function search in OpenSCAD has a greater potential than the documentation may suggests. The examples in the manual are restricted to the search of characters and numerical values. However, it seems that any kind of object may be used in an appropriate call of search. For instance:echo(search([[[0],1]], [[[1,2],0],[[0,1],1],[[[0],1],3],[[2,3],4]], 0, 0));// ECHO: [[2]] _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: The potential of search()

 I commonly search for vertices in list of vertices vertices= [[5,46,83],[97,28,66],[92,98,72],[62,28,60],[62,28,60], [36,5,37],[24,36,41],[97,28,66] ];   uniquevertices =[   for (i = [0:len(vertices)-1 ])    if (search([vertices[i]],vertices ,1)==[i]) vertices[i]  ];   Here in a mesh welding routine function glue(points,faces)=     points==[]?[]:      let( usedpoints=([for(i=faces,j=i)points[j]]),     upoints=truepoints(unique(usedpoints)),     nfaces= [for(i=faces)[for(j=i)     search([points[j]],upoints,1)[0]]])     [upoints,nfaces]; function truepoints(p)= [for(i=p)if(i!=undef)i]; function  uniquejoin(m,n) =       concat(m,[   for (i = n)    if (search([i],m,1)==[[]]) i  ]);         function  unique(m,first,last) =     last==undef?unique(m,0,len(m)-1) :     last-first>1? let(mid=(first+last)/2)     uniquejoin(  unique(m,first,floor(mid)),  unique(m,ceil(mid),last) )     :m[first]==undef? [m[last]]:      m[last]==undef?[m[first]] :     concat([m[first]],[if( m[last]!=m[first])m[last]] ) ; -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org