+
+ /* if the plane clipped the polygon, and the two polygons intersect
+ * within their bounds, also clip the cell polygon by the original
+ * mesh polygon.
+ *
+ * TODO clipping with the polygon's plane is incorrect, and will lead
+ * to gaps in the cell walls when the surface is concave. We'll need
+ * to clip by the polygon itself, which can make the wall polygon
+ * concave, and will need to be split into multiple convex ones.
+ */
+ if(clipres == 0 && poly_poly(&poly, cell->polys + j)) {
+ poly_plane(&poly, &plane);
+ init_poly(&wallclipped);
+
+ if((clipres = clip_poly(&wallclipped, cell->polys + j, &plane)) < 0) {
+ /* mark for deletion */
+ delwall[j] = 1;
+ } else if(clipres == 0) {
+ destroy_poly(cell->polys + j);
+ cell->polys[j] = wallclipped;
+ } else {
+ destroy_poly(&wallclipped);
+ }
+ }
+