Vex: efficient array slice?

   49   2   0
User Avatar
Member
507 posts
Joined: April 2017
Offline
Hi!

Lets say I have an array with numbers from 100 to 200 (representing @ptnum on a polyline) in a point wrangle. I want to remove all the points from the array that are before the current @ptnum. In other words, if I'm running over the point 50, the new array should be from 51 to 100;

The method I'm thinking of using is to do a foreach on the array and compare if the value is the same as my @ptnum and note what iteration(index) I was on and use the slice function later… This looks like a lot of processing and I'd like to know if there's a better method.

Thanks.

-Olivier
Edited by olivierth - June 14, 2019 10:31:55
User Avatar
Member
3857 posts
Joined: July 2007
Offline
you can use native array slicing [:]
like this:
int pts[] = expandpointgroup(0, ""); //get array of all points
i[]@pts = pts[@ptnum:]; // get only slice starting with current @ptnum

EDIT: note that @ptnum in the example is used directly as an index for the slice, so if your indices are not aligned with ptnumbers you need to find or compute the index you want to slice at first
Edited by tamte - June 14, 2019 12:10:30
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
507 posts
Joined: April 2017
Offline
Interesting!

I'll check it out. Thanks!

-Olivier
  • Quick Links