Skip to content

Commit 1e3177a

Browse files
committed
Make sure the Union operation produces exactly the same point from the
standard and single operation
1 parent 6159117 commit 1e3177a

4 files changed

Lines changed: 48 additions & 18 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,13 +877,13 @@ public CSG dumbUnion(CSG csg) {
877877
*/
878878
public CSG union(List<CSG> csgs) {
879879
if (CSGClient.isRunning()) {
880-
ArrayList<CSG> go = new ArrayList<CSG>(csgs);
880+
ArrayList<CSG> go = new ArrayList<CSG>();
881881
go.add(this);
882+
go.addAll(csgs);
882883
try {
883884
return CSGClient.getClient().union(go).get(0);
884885
} catch (Exception e) {
885-
// TODO Auto-generated catch block
886-
e.printStackTrace();
886+
throw new RuntimeException(e);
887887
}
888888
}
889889
CSG result = this;

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,8 @@ private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation op
141141

142142
ArrayList <CSG> toSend = new ArrayList<CSG>();
143143
for(CSG c:csgList) {
144-
CSG tmp = c.clone();
145-
tmp.setStorage(new PropertyStorage());
146-
tmp.setManipulator(null);
147-
tmp.setManufacturing(null);
148-
tmp.getMapOfparametrics().clear();
149-
tmp.setRegenerate(null);
144+
CSG tmp = CSG.fromPolygons(c.getPolygons());
145+
tmp.setOptType(c.getOptType());
150146
toSend.add(tmp);
151147
}
152148
CSGRequest request = new CSGRequest(toSend, operation,points,storage);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ private CSGResponse processCSGRequest(CSGRequest request) {
107107
back.add(c.triangulate(true));
108108
break;
109109
case UNION:
110-
CSG d = csgList.remove(0);
111-
back.add(d.union(csgList));
110+
if(csgList.size()==2) {
111+
back.add(csgList.get(0).union(csgList.get(1)));
112+
}else
113+
back.add(CSG.unionAll(csgList));
112114
break;
113115
case minkowskiHullShape:
114116
CSG m1 = csgList.remove(0);

src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public CSG prep(CSG incoming) {
5454
CSG c = new Cube(10, 10, 10).toCSG();
5555
c.getBounds();
5656

57-
CSG u1 = CSG.unionAll(a, b, c);
57+
CSG u1 = a.union( b,c);
5858
CSG d1 = a.difference(b);
5959
CSG t1 = d1.clone().triangulate(true);
6060
ArrayList<CSG> m1 = a.minkowskiHullShape(b);
@@ -66,26 +66,29 @@ public CSG prep(CSG incoming) {
6666
// Connect to server
6767
System.out.println("Client info: " + CSGClient.getClient().getServerInfo());
6868

69-
CSG u = CSG.unionAll(a, b, c);
70-
if(u.getPolygons().size()!=u1.getPolygons().size())
69+
CSG u =a.union( b,c);
70+
if(testPoly(u1,u))
7171
fail();
72+
7273
CSG d = a.difference(b);
73-
if(d.getPolygons().size()!=d1.getPolygons().size())
74+
if(testPoly(d1,d))
7475
fail("Difference Step fail , expected "+d1.getPolygons().size()+" got "+d.getPolygons().size());
7576
CSG t = d.clone().triangulate(true);
76-
if(t.getPolygons().size()!=t1.getPolygons().size())
77+
if(testPoly(t1,t))
7778
fail();
7879
ArrayList<CSG> m = a.minkowskiHullShape(b);
7980
if(m.size()!=m1.size()) {
8081
fail();
8182
}
8283
for(int i=0;i<m.size();i++) {
83-
if(m.get(i).getPolygons().size()!=m1.get(i).getPolygons().size()) {
84+
if(testPoly(
85+
m1.get(i),m.get(i)
86+
)) {
8487
fail();
8588
}
8689
}
8790
CSG h = u1.hull();
88-
if(h.getPolygons().size()!=h1.getPolygons().size())
91+
if(testPoly(h,h1))
8992
fail();
9093
CSGClient.close();
9194
} catch (Exception e) {
@@ -99,5 +102,34 @@ public CSG prep(CSG incoming) {
99102
serverThread.join();
100103
System.out.println("\nClient example completed.");
101104
}
105+
106+
boolean testPoly(CSG p1, CSG p2) {
107+
int size1 = p1.getPolygons().size();
108+
int size2 = p2.getPolygons().size();
109+
if(size1!=size2) {
110+
System.err.println("Mismatched number of polygons expected "+size1+" but got "+size2);
111+
return true;
112+
}
113+
for(int i=0;i<size1;i++) {
114+
Polygon poly1 = p1.getPolygons().get(i);
115+
Polygon poly2 = p2.getPolygons().get(i);
116+
int size = poly1.getPoints().size();
117+
if(size!=poly2.getPoints().size()) {
118+
System.err.println("Number of Points mismatch ");
119+
return true;
120+
}
121+
for(int j=0;j<size;j++) {
122+
Vector3d vector3d = poly1.getPoints().get(j);
123+
Vector3d obj = poly2.getPoints().get(j);
124+
if(!vector3d.test(obj, 0.000001)) {
125+
System.err.println("Point distance "+vector3d.distance(obj));
126+
return true;
127+
}else {
128+
//System.out.println("Point match ");
129+
}
130+
}
131+
}
132+
return false;
133+
}
102134

103135
}

0 commit comments

Comments
 (0)