Remove ring.h

Tue, 28 Jun 2022 19:35:09 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 19:35:09 +0300
changeset 297
bc92f97498f7
parent 296
38f6fad61bad
child 298
9ca53009bc5c

Remove ring.h

CMakeLists.txt file | annotate | diff | comparison | revisions
src/geometry.cpp file | annotate | diff | comparison | revisions
src/gl/compiler.cpp file | annotate | diff | comparison | revisions
src/ring.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Tue Jun 28 19:31:55 2022 +0300
+++ b/CMakeLists.txt	Tue Jun 28 19:35:09 2022 +0300
@@ -106,7 +106,6 @@
 	src/model.h
 	src/parser.h
 	src/polygoncache.h
-	src/ring.h
 	src/settings.h
 	src/typeconversions.h
 	src/uiutilities.h
--- a/src/geometry.cpp	Tue Jun 28 19:31:55 2022 +0300
+++ b/src/geometry.cpp	Tue Jun 28 19:35:09 2022 +0300
@@ -1,7 +1,6 @@
 #include <glm/gtc/matrix_transform.hpp>
 #include "src/geometry.h"
 #include "src/basics.h"
-#include "src/ring.h"
 
 /**
  * @brief Computes line-plane intersection
@@ -218,12 +217,14 @@
 bool isConvex(const std::vector<glm::vec3>& polygon)
 {
 	const std::size_t n = polygon.size();
-	auto polygonRing = iter::ring(polygon, n);
 	std::vector<glm::vec3> crosses;
 	crosses.resize(n);
 	for (std::size_t i = 0; i < n; i += 1)
 	{
-		crosses[i] = glm::cross(polygonRing[i - 1] - polygonRing[i], polygonRing[i + 1] - polygonRing[i]);
+		const glm::vec3 v1 = polygon[(i + n - 1) % n];
+		const glm::vec3 v2 = polygon[i];
+		const glm::vec3 v3 = polygon[(i + 1) % n];
+		crosses[i] = glm::cross(v1 - v2, v3 - v2);
 	}
 	return not std::any_of(
 		crosses.begin() + 1,
--- a/src/gl/compiler.cpp	Tue Jun 28 19:31:55 2022 +0300
+++ b/src/gl/compiler.cpp	Tue Jun 28 19:35:09 2022 +0300
@@ -19,7 +19,6 @@
 #include <QMessageBox>
 #include "src/documentmanager.h"
 #include "src/invert.h"
-#include "src/ring.h"
 #include "src/gl/compiler.h"
 
 constexpr char VERTEX_SHADER_SOURCE[] = R"(
--- a/src/ring.h	Tue Jun 28 19:31:55 2022 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,108 +0,0 @@
-/*
- *  LDForge: LDraw parts authoring CAD
- *  Copyright (C) 2013 - 2020 Teemu Piippo
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-namespace iter
-{
-	namespace _imp
-	{
-		template<typename T, typename Tint>
-		class RingAdapter;
-	}
-
-	template<typename T>
-	_imp::RingAdapter<T, int> ring(T&& collection);
-
-	template<typename T, typename Tint>
-	_imp::RingAdapter<T, Tint> ring(T&& collection, Tint count);
-}
-
-/*
- * Implements a ring adapter over T. This class corrects indices given to the element-operator so that they're within
- * bounds. The maximum amount can be specified manually.
- *
- * Example:
- *
- *   int A[] = {10,20,30,40};
- *   ring(A)[0]  ==     A[0 % 4]    == A[0]
- *   ring(A)[5]  ==     A[5 % 4]    == A[1]
- *   ring(A)[-1] == ring(A)[-1 + 4] == A[3]
- */
-template<typename T, typename Tint>
-class iter::_imp::RingAdapter
-{
-private:
-	// The private section must come first because _collection is used in decltype() below.
-	T&& collection;
-	const Tint count;
-
-public:
-	RingAdapter(T&& collection, Tint count) :
-		collection {collection},
-		count {count} {}
-
-	decltype(collection[Tint{}]) operator[](Tint index)
-	{
-		if (count == 0)
-		{
-			// Argh! ...let the collection deal with this case.
-			return this->collection[index];
-		}
-		else
-		{
-			index %= this->count;
-
-			// Fix negative modulus...
-			if (index < 0)
-				index += this->count;
-
-			return this->collection[index];
-		}
-	}
-
-	Tint size() const
-	{
-		return this->count;
-	}
-};
-
-/*
- * Convenience function for RingAdapter so that the template parameter does not have to be provided. The ring
- * amount is assumed to be the amount of elements in the collection.
- */
-template<typename T>
-iter::_imp::RingAdapter<T, int> iter::ring(T&& collection)
-{
-	return {collection, countof(collection)};
-}
-
-/*
- * Version of ring() that allows manual specification of the count.
- */
-template<typename T, typename Tint>
-iter::_imp::RingAdapter<T, Tint> iter::ring(T&& collection, Tint count)
-{
-	return {collection, count};
-}
-
-template<typename T, typename Tint>
-int countof(const iter::_imp::RingAdapter<T, Tint>& ring)
-{
-	return ring.size();
-}

mercurial