Translating a js script in gen

Mattebass's icon

Hi, I'm trying to port in gen the behavior of the js script included in this patch.
What I'm trying to achieve is to calculate the distance of all the particles in a system and to draw a segment between those particles that have a distance minor of a threshold

The problem with js is related to an high framerate drop, so I'm searching some alternatives in terms of efficiency.
I'm not a gen expert at all, so I'm not even sure if this is the best approach or even a feasible one.
Thanks in advance
Matteo

Gen_ny.maxpat
Max Patch

sketchy_0602.js
js 1.57 KB

Rob Ramirez's icon

without looking at your patch, I can say that I doubt very much porting to jit.gen will yield significant performance gains over JS. switching to a GPU process (e.g. via jit.gl.pix or GLSL via jit.gl.slab), may improve things. however in general these types of algorithms that require iterating several times over the the cells are not suitable for Gen processes. Instead optimizing your algorithms via partitioning structures (e.g. quadtree) is usually the way to go -