src/main.h

Thu, 27 Feb 2020 12:23:42 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 27 Feb 2020 12:23:42 +0200
changeset 58
b7841cd31fb7
parent 55
cb81ecb5fb23
child 63
f7dd937667a5
permissions
-rw-r--r--

use glm::project instead of figuring out the conversion manually...

/*
 *  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
#include <QString>
#include <QVector>
#include <QSet>
#include <memory>
#include "basics.h"
#include "utility.h"
#include "maths.h"
#include "geometry.h"

namespace settingGroups
{
	// List of setting groups
	constexpr char mainwindow[] = "mainwindow";
}

namespace ldraw
{
	// Uniquely identifies a model body object
	struct Id
	{
		std::int32_t value;
		constexpr bool operator<(ldraw::Id other) const
		{
			return this->value < other.value;
		}
		friend constexpr unsigned int qHash(ldraw::Id id)
		{
			return qHash(id.value);
		}
		friend bool operator==(ldraw::Id one, ldraw::Id other)
		{
			return one.value == other.value;
		}
	};
	using id_t = Id;
	constexpr id_t NULL_ID = id_t{0};
}

constexpr std::size_t operator""_z(const unsigned long long int x)
{
	return static_cast<std::size_t>(x);
}

inline QString operator""_q(const char* string, const unsigned long int length)
{
	Q_UNUSED(length)
	return QString{string};
}

inline QPointF pointToPointF(const QPoint& point)
{
	return {static_cast<qreal>(point.x()), static_cast<qreal>(point.y())};
}

inline QPoint pointFToPoint(const QPointF& point)
{
	return {static_cast<int>(std::round(point.x())), static_cast<int>(std::round(point.y()))};
}

/**
 * \brief Hints to the specified vector that a certain amount of new elements are going to be added.
 * \param vector vector to consider
 * \param amount amount of new elements to expect
 */
template<typename T>
void reserveMore(std::vector<T>& vector, std::size_t amount)
{
	vector.reserve(vector.size() + amount);
}

mercurial