src/ldrawalgorithm.h

Fri, 01 Jul 2022 16:46:43 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Fri, 01 Jul 2022 16:46:43 +0300
changeset 312
2637134bc37c
parent 264
76a025db4948
child 333
07e65a4c6611
permissions
-rw-r--r--

Fix right click to delete not really working properly
Instead of removing the point that had been added, it would remove
the point that is being drawn, which would cause it to overwrite the
previous point using the new point, causing a bit of a delay

#pragma once
#include "src/basics.h"
#include "src/model.h"

namespace ldraw
{
	/// Determines how quadrilaterals are split into triangles
	enum class Diagonal
	{
		Diagonal_13,
		Diagonal_24
	};

	std::pair<Triangle, Triangle> splitTriangles(
		const Quadrilateral& q,
		ldraw::Diagonal diagonal);

	std::vector<ModelAction> makeUnofficial(const Model *model);

	constexpr float circleAngle(unsigned int divisions, unsigned int i)
	{
		constexpr float ofs = 0.5 * pi;
		float factor = -2.0f * pi / static_cast<float>(divisions);
		return static_cast<float>(i) * factor + ofs;
	}

	constexpr glm::vec2 rimpoint(unsigned int divisions, unsigned int i)
	{
		const float angle = circleAngle(divisions, i);
		return glm::vec2{std::sin(angle), std::cos(angle)};
	}

	template<typename Fn>
	void circleAngles(unsigned int segments, unsigned int divisions, Fn&& fn)
	{
		for (unsigned int i = 0; i < segments; i += 1)
		{
			const float a1 = circleAngle(divisions, i - 1);
			const float a2 = circleAngle(divisions, i);
			const float a3 = circleAngle(divisions, i + 1);
			fn(a1, a2, a3);
		}
	}

	template<typename Fn>
	void circle(unsigned int segments, unsigned int divisions, Fn&& fn)
	{
		circleAngles(segments, divisions, [&fn](
			const float a1,
			const float a2,
			const float a3
		){
			fn(
				glm::vec2{std::sin(a1), std::cos(a1)},
				glm::vec2{std::sin(a2), std::cos(a2)},
				glm::vec2{std::sin(a3), std::cos(a3)}
			);
		});
	}
}

ModelElement inverted(const ModelElement &element);

mercurial