Skip to content

Commit b0454c0

Browse files
committed
make use of org.sunflow.util.FloatArray and IntArray
1 parent adebff4 commit b0454c0

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

src/main/java/joons/JRFiller.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package joons;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
3+
import org.sunflow.util.FloatArray;
4+
import org.sunflow.util.IntArray;
55

66
public class JRFiller {
77

8-
private final List<Float> vertices;
9-
private final List<Integer> triangleIndices;
10-
private final List<Float> spheres;
11-
private final List<Float> points;
8+
private final FloatArray vertices;
9+
private final IntArray triangleIndices;
10+
private final FloatArray spheres;
11+
private final FloatArray points;
1212

1313
private final String fillType;
1414
public float[] p; //array of parameters
1515
public int np = 0; //number of parameters
1616

1717
public JRFiller(String fillType, float... params) {
18-
vertices = new ArrayList<>();
19-
triangleIndices = new ArrayList<>();
20-
spheres = new ArrayList<>();
21-
points = new ArrayList<>();
18+
vertices = new FloatArray();
19+
triangleIndices = new IntArray();
20+
spheres = new FloatArray();
21+
points = new FloatArray();
2222

2323
this.fillType = fillType;
2424
p = params;
@@ -29,12 +29,12 @@ public String getType() {
2929
return fillType;
3030
}
3131

32-
public List<Float> getVertices() {
32+
public FloatArray getVertices() {
3333
return vertices;
3434
}
3535

3636
private void writeTriangleIndices() {
37-
for (int i = 0; i < (vertices.size() / 9); i++) {
37+
for (int i = 0; i < (vertices.getSize() / 9); i++) {
3838
//vertices/3 = number of 3d points
3939
//vertices/9 = number of triangles
4040
triangleIndices.add(i * 3);
@@ -44,20 +44,12 @@ private void writeTriangleIndices() {
4444
}
4545

4646
public float[] verticesToArray() {
47-
float[] v = new float[vertices.size()];
48-
for (int i = 0; i < vertices.size(); i++) {
49-
v[i] = vertices.get(i);
50-
}
51-
return v;
47+
return vertices.trim();
5248
}
5349

5450
public int[] triangleIndicesToArray() {
5551
writeTriangleIndices();
56-
int[] t = new int[triangleIndices.size()];
57-
for (int i = 0; i < triangleIndices.size(); i++) {
58-
t[i] = triangleIndices.get(i);
59-
}
60-
return t;
52+
return triangleIndices.trim();
6153
}
6254

6355
public void addSphere(float x, float y, float z, float r) {
@@ -67,7 +59,7 @@ public void addSphere(float x, float y, float z, float r) {
6759
spheres.add(r);
6860
}
6961

70-
public List<Float> getSpheres() {
62+
public FloatArray getSpheres() {
7163
return spheres;
7264
}
7365

src/main/java/joons/JoonsRenderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package joons;
22

3-
import java.util.List;
3+
import org.sunflow.util.FloatArray;
44

55
import org.sunflow.SunflowAPI;
66
import org.sunflow.math.Matrix4;
@@ -662,8 +662,8 @@ private boolean buildLight(JRFiller temp, int i) {
662662
}
663663

664664
//light spheres
665-
List<Float> spheres = temp.getSpheres();
666-
int noOfSpheres = (int) spheres.size() / 4;
665+
FloatArray spheres = temp.getSpheres();
666+
int noOfSpheres = (int) spheres.getSize() / 4;
667667

668668
for (int j = 0; j < noOfSpheres; j++) {
669669
float x = spheres.get(j * 4);
@@ -802,8 +802,8 @@ private void buildInstance(JRFiller temp, int i) {
802802
api.instance("Object_" + i + ".instance", "Object_" + i);
803803

804804
//render the respective spheres
805-
List<Float> spheres = temp.getSpheres();
806-
int noOfSpheres = spheres.size() / 4;
805+
FloatArray spheres = temp.getSpheres();
806+
int noOfSpheres = spheres.getSize() / 4;
807807

808808
for (int j = 0; j < noOfSpheres; j++) {
809809
float x = spheres.get(j * 4);

0 commit comments

Comments
 (0)