Programming JavaScript

Javascript output structure error

benoitlahoz's picture

Hi !

Firstable, a big thanks for this site and the contributors ! This is a bible, and I can say that I'm learning QC at Kineme !

Here is my trouble, and I guess this is a simple problem of variable declaration in Javascript... But well... I can't manage to output a structure from this code !

In input I have a structure of 4 values structures (Mesh vertices). What I want is to output a new structure of 3 values structure (Points structure), so for each substructure I "pop" the last element.

But my code seems to be wrong and it returns an error : "TypeError : Result of 'MeshVerticesArray' [null] is not an object".

Here is the code :

function (__structure LineStructure) main (__structure MeshVerticesArray)
   for (i = 0; i < MeshVerticesArray.length; i++) {
      for (j = 0; j < 3; j++) {
         LineStructure[i][j] = MeshVertices[i].pop();
   var result = new Object();
   result.LineStructure = LineStructure;
   return result;

Could you please help me ? Am I doing things the right way ?

Thanks a lot in advance !


Depth Sorting with javascript

yanomano's picture

I'am trying to re-order an array of points according to the z component for depth sorting with javascript. There is an easy way to to manage the order with array.sort(), but it seems more complicated with an array of arrays...

My idea was to apply the array.sort() only on the Z component and find a way to return an array of int[] that represents the order of the original array with indices. Then re-order the original array of point according to these indices.

Is there an easy way to return the original indices of the array re-ordered with array.sort() ?

Thanks for your help !