Skip to main content

Shape3D .numGeometries() wrong?

1 reply [Last post]
jarodrussell
Offline
Joined: 2010-05-19

I ran into a small error, which is sometimes a little annoying.

I created a Shape3D object:

<br />
LineArray line1 = new LineArray(20, GeometryArray.COORDINATES | GeometryArray.COLOR_3);<br />
/* add Coordinate Points and Colors */<br />
LineArray line2 =  new LineArray(20, GeometryArray.COORDINATES | GeometryArray.COLOR_3);<br />
/* add Coordinate Points and Colors */</p>
<p>Shape3D shape = new Shape3D();<br />
shape.insertGeometry(line1, 0);<br />
shape.insertGeometry(line2, 1);<br />

Now when I print shape.numGeometries() it returns 3, not 2. And:

<br />
shape.getGeometry(0); //returns line1<br />
shape.getGeometry(1); //returns line2<br />
shape.getGeometry(2); //returns null<br />

If I create the shape using:

<br />
Shape3D shape = new Shape3D();<br />
shape.addGeometry(line1);<br />
shape.addGeometry(line2);<br />

then I get these:

<br />
shape.numGeometries(); //returns 3<br />
shape.getGeometry(0); //returns null<br />
shape.getGeometry(1); //returns line1<br />
shape.getGeometry(2); //returns line2<br />

It's not a big issue, but I'm wondering why this happens.

Cheers,
Jarod

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jarodrussell
Offline
Joined: 2010-05-19

Actually, the trick is to do this:

[code]
Shape3D shape = new Shape3D();
shape.setGeometry(line1, 0);
shape.addGeometry(line2);
[/code]

then I get the 'correct' information:

[code]
shape.numGeometries(); //returns 2
shape.getGeometry(0); //returns line1
shape.getGeometry(1); //returns line2
shape.getGeometry(2); //NullPointerException, of course
[/code]

Cheers again,
Jarod