Loading...
Logo
Processing Forum
Hi all, I would like to reverse a list of RPoint, but it tells me that you can not do:

points_ = grp.getPoints();   
points_ = reverse(points_);

and it say:

"cannot convert from Object to RPoint[];"

Thank you all...

Replies(2)

Function reverse() directly works on 5 primitive data-types ( boolean, byte, char, int, float) + String objects.
Copy code
    byte[] b = {1, 2, 3, 4, 5};
    println(b);
    println();
    
    b = reverse(b);
    println(b);
    
    exit();
    
For the less fortunate primitive data-types ( short, long and double) + for any object which isn't a String,
we gotta explicit use a (cast[]) operator on a returning Array from reverse().

That is so b/c they're internally treated as a generalized Object data-type.
And needs to be converted back to their specific data-type.

Outta curiosity, check out how the short primitive data-type is so prejudiced and ignored by Processing,
that even println() doesn't work on it! 
Copy code
    short[] s = {1, 2, 3, 4, 5};
    println(s);
    println();
    
    s = (short[]) reverse(s);
    println(s);
    
    exit();
    
And finally an example using PVector objects, which you can use as a template for your RPoint ones:
Copy code
    final int NUM = 5;
    PVector[] vecs = new PVector[NUM];
    
    for (int i = 0; i != NUM; ++i)
      vecs[i] = new PVector(i, i+i, i*i);
    
    println(vecs);
    println();
    
    vecs = (PVector[]) reverse(vecs);
    
    println(vecs);
    
    exit();