src/vertexmap.cpp

changeset 119
24275a4064f4
parent 118
8e1c9f18ae15
child 120
8c9fff699241
--- a/src/vertexmap.cpp	Tue Jul 27 16:29:00 2021 +0300
+++ b/src/vertexmap.cpp	Wed Jul 28 08:23:09 2021 +0300
@@ -29,6 +29,7 @@
 {
 	this->map.clear();
 	this->vertices.clear();
+	this->vertexHashes.clear();
 	this->model->apply<ldraw::Object>([&](const ldraw::Object* object)
 	{
 		for (int i = 0; i < object->numPoints(); i += 1)
@@ -36,7 +37,11 @@
 			const glm::vec3& point = object->getPoint(i);
 			const unsigned int hash = qHash(point);
 			this->map[hash].insert(object->id);
-			this->vertices[hash] = point;
+			if (not this->vertexHashes.contains(hash))
+			{
+				this->vertexHashes.insert(hash);
+				this->vertices.push_back(point);
+			}
 		}
 	});
 	Q_EMIT this->verticesChanged();
@@ -48,9 +53,9 @@
  */
 void VertexMap::apply(ApplyFunction fn) const
 {
-	for (auto it = this->map.cbegin(); it != this->map.cend(); ++it)
+	for (unsigned int i = 0; i < this->vertices.size(); i += 1)
 	{
-		const glm::vec3& point = this->vertices.at(it->first);
-		fn(point, it->second);
+		const glm::vec3& point = this->vertices[i];
+		fn(point, this->map.at(qHash(point)));
 	}
 }

mercurial