Skip to content

Commit 32613f2

Browse files
committed
formatting
1 parent 70aced4 commit 32613f2

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

  • src/main/java/eu/mihosoft/vrl/v3d

src/main/java/eu/mihosoft/vrl/v3d/CSG.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ public static enum OptType {
166166
// GPU processing
167167
transient private static boolean useGPU = false;
168168
transient private static int ExtraSpace = 100;
169-
transient private static ICSGProgress progressMoniter=new ICSGProgress(){@Override public void progressUpdate(int currentIndex,int finalIndex,String type,CSG intermediateShape){System.err.println(type+" cur:"+currentIndex+" of "+finalIndex);}};
169+
transient private static ICSGProgress progressMoniter = new ICSGProgress() {
170+
@Override
171+
public void progressUpdate(int currentIndex, int finalIndex, String type, CSG intermediateShape) {
172+
System.err.println(type + " cur:" + currentIndex + " of " + finalIndex);
173+
}
174+
};
170175
transient private static ForkJoinPool poolGlobal = null;
171176

172177
/** The polygons. */
@@ -243,8 +248,11 @@ public ArrayList<Polygon> generatePolygonsFromMesh() throws ColinearPointsExcept
243248
ArrayList<Polygon> polygons = new ArrayList<Polygon>();
244249

245250
for (long t = 0; t < triCount; t++) {
246-
int base =(int) (t * 3);
247-
polygons.add(getPolygonByIndex(base));
251+
try {
252+
polygons.add(getPolygonByIndex((int) t));
253+
} catch (Exception ex) {
254+
ex.printStackTrace();
255+
}
248256
}
249257
return polygons;
250258
}
@@ -253,6 +261,7 @@ private static Vector3d vertexAt(double[] verts, long index) {
253261
long base = index * 3;
254262
return new Vector3d(verts[(int) base], verts[(int) (base + 1)], verts[(int) (base + 2)]);
255263
}
264+
256265
public Vector3d vertexAt(long i) {
257266
return vertexAt(vertices, i);
258267
}
@@ -277,16 +286,14 @@ public CSG processPolygonsToTriangles(ArrayList<Polygon> polygons) throws Coline
277286
// Use a tolerance-free exact key so we don't merge
278287
// numerically-close-but-distinct verts.
279288
Map<String, Integer> vertexIndex = new HashMap<>();
280-
List<double[]> vertexList = new ArrayList<>();
289+
List<Vector3d> vertexList = new ArrayList<>();
281290
List<Long> triList = new ArrayList<>();
282291

283292
for (Polygon incoming : polygons) {
284293
for (Polygon poly : PolygonUtil.triangulatePolygon(incoming)) {
285294
List<Vertex> pverts = poly.getVertices();
286-
if (pverts == null || pverts.size() < 3)
295+
if (pverts == null || pverts.size() != 3)
287296
continue;
288-
289-
// Fan triangulation: (0,1,2), (0,2,3), (0,3,4), ...
290297
int i0 = intern(pverts.get(0), vertexIndex, vertexList);
291298
int i1 = intern(pverts.get(1), vertexIndex, vertexList);
292299
int i2 = intern(pverts.get(2), vertexIndex, vertexList);
@@ -305,30 +312,50 @@ public CSG processPolygonsToTriangles(ArrayList<Polygon> polygons) throws Coline
305312
if (triList.isEmpty())
306313
throw new IllegalArgumentException("CSG produced no valid triangles after triangulation");
307314

308-
long nVerts = vertexList.size();
309-
long nTris = triList.size() / 3;
315+
vertCount = vertexList.size();
316+
triCount = triList.size() / 3;
310317

311318
// Flatten vertex list into a primitive array.
312-
double[] vertices = new double[(int) (nVerts * 3)];
313-
for (int i = 0; i < nVerts; i++) {
314-
double[] v = vertexList.get(i);
315-
vertices[i * 3] = v[0];
316-
vertices[i * 3 + 1] = v[1];
317-
vertices[i * 3 + 2] = v[2];
319+
vertices = new double[(int) (vertCount * 3)];
320+
for (int i = 0; i < vertCount; i++) {
321+
Vector3d v = vertexList.get(i);
322+
vertices[i * 3] = v.x;
323+
vertices[i * 3 + 1] = v.y;
324+
vertices[i * 3 + 2] = v.z;
318325
}
319326

320327
// Flatten triangle index list.
321-
long[] triangles = new long[triList.size()];
322-
for (int i = 0; i < triList.size(); i++) {
328+
triangles = new long[(int) triCount*3];
329+
for (int i = 0; i < triangles.length; i++) {
323330
triangles[i] = triList.get(i);
324331
}
325-
this.vertices = vertices;
326-
this.triangles = triangles;
327-
this.vertCount = nVerts;
328-
this.triCount = nTris;
329332
return this;
330333
}
334+
/**
335+
* Returns the index of {@code v} in {@code vertexList}, inserting it if not
336+
* already present. The key is an exact string representation of (x, y, z) using
337+
* {@link Double#toHexString} so that only bit-identical positions are merged,
338+
* matching the BSP's behavior.
339+
*/
340+
private static int intern(Vertex v, Map<String, Integer> index, List<Vector3d> list) {
341+
// 1. Lower the precision slightly. 1e9 is too high for 'double' stability
342+
// after multiple CSG operations. 1e7 (0.1 nanometer) is the "sweet spot".
343+
double precision = 1e9;
344+
345+
long x = Math.round(v.pos.x * precision);
346+
long y = Math.round(v.pos.y * precision);
347+
long z = Math.round(v.pos.z * precision);
348+
349+
String key = x + "_" + y + "_" + z;
331350

351+
return index.computeIfAbsent(key, k -> {
352+
int idx = list.size();
353+
// Use the RAW position for the first instance of this vertex.
354+
// This keeps the geometry as true to the BSP as possible.
355+
list.add(v.pos.clone());
356+
return idx;
357+
});
358+
}
332359
/**
333360
* Gets the polygons.
334361
*
@@ -360,31 +387,7 @@ public long getNumberOfTriangles() {
360387
return triCount;
361388
}
362389

363-
/**
364-
* Returns the index of {@code v} in {@code vertexList}, inserting it if not
365-
* already present. The key is an exact string representation of (x, y, z) using
366-
* {@link Double#toHexString} so that only bit-identical positions are merged,
367-
* matching the BSP's behavior.
368-
*/
369-
private static int intern(Vertex v, Map<String, Integer> index, List<double[]> list) {
370-
// 1. Lower the precision slightly. 1e9 is too high for 'double' stability
371-
// after multiple CSG operations. 1e7 (0.1 nanometer) is the "sweet spot".
372-
double precision = 1e7;
373390

374-
long x = Math.round(v.pos.x * precision);
375-
long y = Math.round(v.pos.y * precision);
376-
long z = Math.round(v.pos.z * precision);
377-
378-
String key = x + "," + y + "," + z;
379-
380-
return index.computeIfAbsent(key, k -> {
381-
int idx = list.size();
382-
// Use the RAW position for the first instance of this vertex.
383-
// This keeps the geometry as true to the BSP as possible.
384-
list.add(new double[] { v.pos.x, v.pos.y, v.pos.z });
385-
return idx;
386-
});
387-
}
388391

389392
public CSG setID(CSG dying) {
390393
uniqueId = dying.uniqueId;
@@ -2339,8 +2342,7 @@ public void run() {
23392342
}
23402343

23412344
public static List<ForkJoinWorkerThread> getForkJoinWorkers(ForkJoinPool pool) {
2342-
return Thread.getAllStackTraces().keySet().stream().filter(
2343-
thread -> thread instanceof ForkJoinWorkerThread)
2345+
return Thread.getAllStackTraces().keySet().stream().filter(thread -> thread instanceof ForkJoinWorkerThread)
23442346
.map(thread -> (ForkJoinWorkerThread) thread).collect(Collectors.toList());
23452347
}
23462348

@@ -2972,8 +2974,6 @@ public CSG setOptType(OptType optType) {
29722974
}
29732975

29742976

2975-
2976-
29772977
/**
29782978
* Hail Zeon! In case you forget the name of minkowski and are a Gundam fan
29792979
*

0 commit comments

Comments
 (0)