src/invert.cpp

changeset 210
232e7634cc8a
parent 206
654661eab7f3
child 264
76a025db4948
--- a/src/invert.cpp	Thu Jun 09 11:51:42 2022 +0300
+++ b/src/invert.cpp	Thu Jun 09 13:32:55 2022 +0300
@@ -36,19 +36,16 @@
 /*
  * Inverts the winding of a polygon.
  */
-void gl::invert(gl::Polygon& polygon)
+void gl::invert(PolygonElement& polygon)
 {
-	switch (polygon.numPolygonVertices())
-	{
-	case 2:
-	case 3:
-		// 0 1 => 1 0
-		// 0 1 2 => 1 0 2
-		std::swap(polygon.vertices[0], polygon.vertices[1]);
-		break;
-	case 4:
-		// 0 1 2 3 => 0 3 2 1
-		std::swap(polygon.vertices[1], polygon.vertices[3]);
-		break;
-	}
+	visitPolygon<void>(
+		[](LineSegment&) {},
+		[](Triangle& tri) {
+			std::swap(tri.p1, tri.p2);
+		},
+		[](Quadrilateral& quad) {
+			std::swap(quad.p1, quad.p3);
+		},
+		[](ConditionalEdge&) {},
+		polygon);
 }

mercurial