I'm trying to pass a arraylist of coordinates points to this class. But i'm not sure if this is being done correctly. When i callback the coords from the XYspline object, it returns as an empty array list. I know it being passed correctly because println(this.coords); in the class constructor returns:
[XYspline_test$Coords@d6b059, XYspline_test$Coords@d3c65d, XYspline_test$Coords@1843a75, XYspline_test$Coords@1a1399, XYspline_test$Coords@1fcc0a2, XYspline_test$Coords@caf6c1]
[XYspline_test$Coords@10e35d5, XYspline_test$Coords@1f03691, XYspline_test$Coords@18e8541]
void setup()
{
background(0);
size( 400, 400 );
xypoints = new ArrayList<Coords>();
splines = new ArrayList<XYspline>();
}
void draw()
{
for(int i = 0; i < splines.size(); i++)
{
XYspline spline = (XYspline) splines.get(i);
spline.getCoords();
spline.drawSpline();
}
}
void keyPressed()
{
if (key == 'l')
{
//load data from external source
splines.clear();
String lines[] = loadStrings("coordinates.csv");
for (int i=0; i < lines.length; i++)
{
String [] data=split(lines[i],',');
//println(data);
if(data[0].equals("s"))
{
splines.add(new XYspline(xypoints));
xypoints.clear();
}
else
{
xypoints.add(new Coords(int(data[0]), int(data[1])));
}
}
re_draw = true;
println(splines.size() + " splines loaded");
}
}
class XYspline
{
ArrayList<Coords> coords;
Spline xSpline;
Spline ySpline;
float[] x;
float[] y;
float[] t;
XYspline( ArrayList<Coords> xypoints)
{
this.coords = xypoints;
println(this.coords); //return points in memory
}
void getCoords()
{
println(this.coords.size()); //returns no values
}
}
class Coords
{
int x,y;
Coords(int px, int py)
{
this.x = px;
this.y = py;
}
}
1