3232import eu .mihosoft .jcsg .Polygon ;
3333import eu .mihosoft .vvecmath .Transform ;
3434import eu .mihosoft .vvecmath .Vector3d ;
35+
3536import java .util .ArrayList ;
3637import java .util .List ;
3738import java .util .stream .Collectors ;
@@ -52,30 +53,64 @@ private ExtrudeProfile() {
5253 * Extrudes the specified profile along the given path.
5354 *
5455 * @param profile profile to extrude (profile expected in XY plane)
55- * @param path path
56+ * @param path path
5657 * @return CSG object (extruded profile)
5758 */
5859 public static CSG alongPath (PathProfile profile , List <Vector3d > path ) {
5960 List <Segment > segments = path .stream ().
6061 map (p -> new Segment (p , profile )).
6162 collect (Collectors .toList ());
6263
63- return extrudeSegments (profile , segments );
64+ return extrudeSegments (profile , true , true , segments );
6465 }
6566
6667 /**
6768 * Extrudes the specified profile along the given path.
6869 *
6970 * @param profile profile to extrude (profile expected in XY plane)
70- * @param path path
71+ * @param path path
7172 * @return CSG object (extruded profile)
7273 */
7374 public static CSG alongPath (PathProfile profile , Vector3d ... path ) {
7475 List <Segment > segments = Stream .of (path ).
7576 map (p -> new Segment (p , profile )).
7677 collect (Collectors .toList ());
7778
78- return extrudeSegments (profile , segments );
79+ return extrudeSegments (profile , true , true , segments );
80+ }
81+
82+ /**
83+ * Extrudes the specified profile along the given path.
84+ *
85+ * @param profile profile to extrude (profile expected in XY plane)
86+ * @param bottom determines whether to close bottom segment
87+ * @param top determines whether to close top segment
88+ * @param path path
89+ * @return list of polygons (extruded profile)
90+ */
91+ public static List <Polygon > alongPath (PathProfile profile , boolean bottom , boolean top , List <Vector3d > path ) {
92+ List <Segment > segments = path .stream ().
93+ map (p -> new Segment (p , profile )).
94+ collect (Collectors .toList ());
95+
96+ return extrudeSegments (profile , bottom , top , segments ).getPolygons ();
97+ }
98+
99+ /**
100+ * Extrudes the specified profile along the given path.
101+ *
102+ * @param profile profile to extrude (profile expected in XY plane)
103+ * @param bottom determines whether to close bottom segment
104+ * @param top determines whether to close top segment
105+ * @param path path
106+ * @return list of polygons (extruded profile)
107+ */
108+ public static List <Polygon > alongPath (PathProfile profile , boolean bottom , boolean top , Vector3d ... path ) {
109+ List <Segment > segments = Stream .of (path ).
110+ map (p -> new Segment (p , profile )).
111+ collect (Collectors .toList ());
112+
113+ return extrudeSegments (profile , bottom , top , segments ).getPolygons ();
79114 }
80115
81116 /**
@@ -85,34 +120,35 @@ public static CSG alongPath(PathProfile profile, Vector3d... path) {
85120 * @return CSG object
86121 */
87122 private static CSG extrudeSegments (PathProfile profile ,
88- List <Segment > segments ) {
123+ boolean bottom , boolean top ,
124+ List <Segment > segments ) {
89125
90126 computeSegmentNormals (segments );
91127
92128 List <Vector3d > profilePoints = new ArrayList <>(profile .getPoints ());
93129
94130 // transform profile points to path direction
95-
131+
96132 Vector3d profileNormal
97133 = Polygon .fromPoints (profilePoints ).plane .getNormal ();
98134
99135 if (!profileNormal .equals (segments .get (0 ).normal )) {
100136 Transform rot = Transform .unity ().rot (profileNormal ,
101137 segments .get (0 ).normal );
102138 for (int i = 0 ; i < profilePoints .size (); i ++) {
103- profilePoints .set (i ,
139+ profilePoints .set (i ,
104140 profilePoints .get (i ).transformed (rot ));
105141 }
106142 }
107143
108144 // translate profile to first path segment location
109145 Vector3d offset = segments .get (0 ).pos .minus (profile .getCenter ());
110-
146+
111147 Transform translate = Transform .unity ().
112148 translate (profile .getCenter ().plus (offset ));
113-
149+
114150 for (int i = 0 ; i < profilePoints .size (); i ++) {
115- profilePoints .set (i ,
151+ profilePoints .set (i ,
116152 profilePoints .get (i ).transformed (translate ));
117153 }
118154
@@ -174,7 +210,7 @@ private static CSG extrudeSegments(PathProfile profile,
174210 CSG csg = CSG .fromPolygons (Extrude .combine (
175211 Polygon .fromPoints (profilePoints ),
176212 Polygon .fromPoints (profilePointsTransformed ),
177- i == 1 , i == segments .size () - 1 ));
213+ i == 1 && bottom , i == segments .size () - 1 && top ));
178214
179215 polygons .addAll (csg .getPolygons ());
180216
0 commit comments