@@ -64,41 +64,12 @@ public String getType() {
6464 return "Sweep" ;
6565 }
6666
67- public static CSG sweep (Polygon p , Transform increment , Transform offset , int steps ) {
68- Polygon offsetP = p .transformed (offset );
69- List <Polygon > newPolygons = new ArrayList <>();
70- newPolygons .addAll (PolygonUtil .concaveToConvex (offsetP ));
71- Transform running = new Transform ();
72- Polygon prev = offsetP ;
73- for (int i = 0 ; i < steps ; i ++) {
74- running .apply (increment );
75- Polygon step = offsetP .transformed (running );
76- List <Polygon > parts = monotoneExtrude (prev , step );
77- prev = step ;
78- newPolygons .addAll (parts );
79- }
80- Polygon polygon2 = offsetP .transformed (running );
81- List <Polygon > topPolygons = PolygonUtil .concaveToConvex (polygon2 .flipped ());
82- newPolygons .addAll (topPolygons );
83-
84- return CSG .fromPolygons (newPolygons );
85- }
86-
87- public static CSG sweep (Polygon p , double angle , double z , double radius , int steps ) {
88- return sweep (p , new Transform ().rotX (angle ).movex (z ), new Transform ().movey (radius ), steps );
89- }
90-
9167 public CSG sweep (Polygon p , String name , Bounds b ) {
9268 double sweepTot = angle (name ).getMM ();
9369 double d = sweepTot / 360 ;
9470 int steps = (int ) (steps (name ).getMM () * d );
9571 double angle = sweepTot / steps ;
9672 Parameter zp = zoffset (name );
97- // double d = zp.getMM()-b.getTotalY();
98- // if(d<0) {
99- // d=0;
100- // zp.setMM(b.getTotalY());
101- // }
10273 double z = zp .getMM () * d / steps ;
10374 double radius = radius (name ).getMM ();
10475 if (angle < 0 )
@@ -107,7 +78,7 @@ public CSG sweep(Polygon p, String name, Bounds b) {
10778 Transform increment = new Transform ().rotY (-angle ).movey (z );
10879 Transform radiusT = new Transform ().movex (radius );
10980 Polygon transformedP = p .transformed (centerandAllignedPolygon );
110- return sweep (transformedP , increment , radiusT , steps ).rotx (-90 ).setName (name );
81+ return Extrude . sweep (transformedP , increment , radiusT , steps ).rotx (-90 ).setName (name );
11182 }
11283
11384 private LengthParameter radius (String name ) {
@@ -144,47 +115,7 @@ private LengthParameter angle(String name) {
144115 return angle ;
145116 }
146117
147- public static List <Polygon > monotoneExtrude (Polygon polygon2 , Polygon polygon1 ) {
148- List <Polygon > newPolygons = new ArrayList <>();
149- // CSG extrude;
150- // polygon1=polygon1.flipped();
151- // newPolygons.addAll(PolygonUtil.concaveToConvex(polygon1.flipped()));
152- // Polygon polygon2 = polygon1.translated(dir);
153-
154- int numvertices = polygon1 .vertices .size ();
155- // com.neuronrobotics.sdk.common.Log.error("Building Polygon
156- // "+polygon1.getPoints().size());
157- for (int i = 0 ; i < numvertices ; i ++) {
158118
159- int nexti = (i + 1 ) % numvertices ;
160-
161- Vector3d bottomV1 = polygon1 .vertices .get (i ).pos ;
162- Vector3d topV1 = polygon2 .vertices .get (i ).pos ;
163- Vector3d bottomV2 = polygon1 .vertices .get (nexti ).pos ;
164- Vector3d topV2 = polygon2 .vertices .get (nexti ).pos ;
165- double distance = bottomV1 .minus (bottomV2 ).magnitude ();
166- if (Math .abs (distance ) < Plane .getEPSILON ()) {
167- // com.neuronrobotics.sdk.common.Log.error("Skipping invalid polygon "+i+" to
168- // "+nexti);
169- continue ;
170- }
171- try {
172- newPolygons .add (Polygon .fromPoints (Arrays .asList (bottomV2 , topV2 , topV1 ), polygon1 .getStorage ()));
173- newPolygons .add (Polygon .fromPoints (Arrays .asList (bottomV2 , topV1 , bottomV1 ), polygon1 .getStorage ()));
174- } catch (Exception ex ) {
175- // com.neuronrobotics.sdk.common.Log.error("Polygon has problems: ");
176- ex .printStackTrace ();
177- }
178- }
179-
180- // polygon2 = polygon2.flipped();
181- // List<Polygon> topPolygons = PolygonUtil.concaveToConvex(polygon2.flipped());
182- //
183- // newPolygons.addAll(topPolygons);
184- // extrude = CSG.fromPolygons(newPolygons);
185-
186- return newPolygons ;
187- }
188119
189120 @ Override
190121 public List <CSG > process (List <CSG > incoming ) {
0 commit comments