Difference between revisions of "ListStridedReorder"

From Second Life Wiki
Jump to navigation Jump to search
m
(Fixed ListStridedReorderContents so it works with lists of different lengths.)
Line 6: Line 6:
     list temp = [];
     list temp = [];
     list out = [];
     list out = [];
     integer i = -strides;
     integer i = -stride;
     do{
     do{
         temp += llList2ListStrided(llList2List(src, llList2Integer(order, i), -1), 0, -1, stride);
         temp += llList2ListStrided(llList2List(src, llList2Integer(order, i), -1), 0, -1, stride);
Line 12: Line 12:
     do{
     do{
         out += llList2ListStrided(llList2List(temp, i, -1), 0, -1, strides);
         out += llList2ListStrided(llList2List(temp, i, -1), 0, -1, strides);
     }while(stride > ++i);
     }while(strides > ++i);
     return out;
     return out;
}
}

Revision as of 10:54, 6 January 2014

<lsl>list ListStridedReorderContents(list src, list order) {

   //change the order that the elements in the groups are arranged
   integer stride = llGetListLength(order);
   integer len = llGetListLength(src);
   integer strides = len / stride;
   list temp = [];
   list out = [];
   integer i = -stride;
   do{
       temp += llList2ListStrided(llList2List(src, llList2Integer(order, i), -1), 0, -1, stride);
   }while(++i);
   do{
       out += llList2ListStrided(llList2List(temp, i, -1), 0, -1, strides);
   }while(strides > ++i);
   return out;

}

list ListStridedReorderStrides(list src, list order) {

   //change the order that the groups are arranged
   integer strides = llGetListLength(order);
   integer len = llGetListLength(src);
   integer stride = len / strides;
   list temp = [];
   list out = [];
   integer i = 0;
   do
       temp += llList2ListStrided(llList2List(src, i, -1), 0, -1, stride);
   while(strides > ++i);
   i = -stride;
   do
       out += llList2ListStrided(llList2List(temp, llList2Integer(order, i), -1), 0, -1, strides);
   while(++i);
   return out;

}

list ListStridedReorderContentsAndStrides(list src, list element_order, list stride_order) {

   integer stride = llGetListLength(element_order);
   integer strides = llGetListLength(stride_order);
   list temp = [];
   list out = [];
   integer i = -strides;
   do
       temp += llList2ListStrided(llList2List(src, llList2Integer(element_order, i), -1), 0, -1, stride);
   while(++i);
   i = -stride;
   do
       out += llList2ListStrided(llList2List(temp, llList2Integer(stride_order, i), -1), 0, -1, strides);
   while(++i);
   return out;

}


default {

   state_entry(){
       llOwnerSay(llList2CSV(ListStridedReorderContents([0,1,2, 0,1,2, 0,1,2], [1,2,0])));
       llOwnerSay(llList2CSV(ListStridedReorderStrides([0,1,2, 3,4,5, 6,7,8], [1,2,0])));
       llOwnerSay(llList2CSV(ListStridedReorderContentsAndStrides([0,1,2, 3,4,5, 6,7,8], [1,2,0], [1,2,0])));
   }

}</lsl>