Hopefully fixed all problems with determining polygon winding

Sun, 09 Apr 2023 00:56:49 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 09 Apr 2023 00:56:49 +0300
changeset 358
ef90ed0a5720
parent 357
66c75604f5b8
child 359
73b6c478378e

Hopefully fixed all problems with determining polygon winding

src/parser.cpp file | annotate | diff | comparison | revisions
src/parser.h file | annotate | diff | comparison | revisions
src/polygoncache.cpp file | annotate | diff | comparison | revisions
--- a/src/parser.cpp	Sat Apr 08 22:09:29 2023 +0300
+++ b/src/parser.cpp	Sun Apr 09 00:56:49 2023 +0300
@@ -107,6 +107,10 @@
 		parsed->content = match.captured(0);
 		return parsed;
 	};
+	if (auto line1Match = tryRe(exprs().commentRe)) {
+		LineType0* const parsed = init(LineType0{}, *line1Match);
+		parsed->value = Comment{attrib<Attribute::Text>(*parsed)};
+	}
 	if (auto line1Match = tryRe(exprs().subfileRe)) {
 		LineType1* const parsed = init(LineType1{}, *line1Match);
 		parsed->value = {
@@ -116,7 +120,7 @@
 					glm::vec4{vectorAttrib<Attribute::X2, Attribute::Y2, Attribute::Z2>(*parsed), 0},
 					glm::vec4{vectorAttrib<Attribute::X3, Attribute::Y3, Attribute::Z3>(*parsed), 0},
 					glm::vec4{vectorAttrib<Attribute::X4, Attribute::Y4, Attribute::Z4>(*parsed), 0},
-					glm::vec4{vectorAttrib<Attribute::X1, Attribute::Y1, Attribute::Z1>(*parsed), 0}
+					glm::vec4{vectorAttrib<Attribute::X1, Attribute::Y1, Attribute::Z1>(*parsed), 1}
 				},
 			},
 			colorAttrib(parsed),
--- a/src/parser.h	Sat Apr 08 22:09:29 2023 +0300
+++ b/src/parser.h	Sun Apr 09 00:56:49 2023 +0300
@@ -55,7 +55,7 @@
 	T value;
 };
 
-using LineType0 = LineType<Comment, Attribute::Text>;
+using LineType0 = LineType<Comment, Attribute::LineType, Attribute::Text>;
 using LineType1 = LineType<Colored<SubfileReference>,
 	Attribute::LineType,
 	Attribute::Color,
--- a/src/polygoncache.cpp	Sat Apr 08 22:09:29 2023 +0300
+++ b/src/polygoncache.cpp	Sun Apr 09 00:56:49 2023 +0300
@@ -70,7 +70,7 @@
 		if (polygon.color == MAIN_COLOR) {
 			polygon.color = ref.color;
 		}
-		add(polygon);
+		add(1, polygon);
 	}
 }
 
@@ -106,16 +106,16 @@
 			}
 		},
 		[&](const LineType2& line2) {
-			add({line2.value, line2.value.color});
+			add(2, {line2.value, line2.value.color});
 		},
 		[&](const LineType3& line3) {
-			add({line3.value, line3.value.color});
+			add(3, {line3.value, line3.value.color});
 		},
 		[&](const LineType4& line4) {
-			add({line4.value, line4.value.color});
+			add(4, {line4.value, line4.value.color});
 		},
 		[&](const LineType5& line5) {
-			add({line5.value, line5.value.color});
+			add(5, {line5.value, line5.value.color});
 		},
 		[&add, context, &reserve](const LineType1& line1) {
 			QTextDocument* const dependency = findDependency(line1.value, context);
@@ -150,9 +150,9 @@
 	Winding winding = NoWinding;
 	std::vector<WithId<PolygonElement>> result;
 	int i = 0;
-	const auto add = [&result, winding, i](const PolygonElement& poly){
+	const auto add = [&result, &winding, &i](int lineno, const PolygonElement& poly){
 		result.push_back({poly, i});
-		if (winding == Winding::Clockwise) {
+		if (lineno != 1 and winding == Winding::Clockwise) {
 			gl::invert(result.back());
 		}
 	};

mercurial