src/vertex.h

Sun, 26 Jan 2020 01:06:27 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 26 Jan 2020 01:06:27 +0200
changeset 32
767592024ec5
parent 24
1a0faaaceb84
permissions
-rw-r--r--

fix default angle

/*
 *  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 <functional>
#include <QVector3D>
#include "basics.h"
#include "maths.h"
#include "matrix.h"

struct Point3D
{
	double x, y, z;
	using CoordinateType = decltype(x);
	void assign(Axis axis, CoordinateType value);
	CoordinateType& get(Axis ax);
	CoordinateType get(Axis ax) const;
	operator QVariant() const;
};

constexpr Point3D origin = {0, 0, 0};

namespace math
{
	Point3D transform(const Point3D& point, const Matrix4x4& matrix);
	qreal distance(const Point3D& one, const Point3D& other);
}

Point3D& operator+=(Point3D &point, const QVector3D& other);
Point3D operator+(Point3D point, const QVector3D& other);
QVector3D operator-(const Point3D& point, const Point3D& other);
Point3D operator-(Point3D point, const QVector3D& vector);
Point3D& operator-=(Point3D &point, const QVector3D& vector);
Point3D& operator*=(Point3D &point, Point3D::CoordinateType scalar);
Point3D operator*(const Point3D &point, Point3D::CoordinateType scalar);
bool operator<(const Point3D &point, const Point3D& other);
bool operator==(const Point3D &point, const Point3D& other);
bool operator!=(const Point3D &point, const Point3D& other);

inline Point3D operator*(qreal scalar, const Point3D& vertex)
{
	return vertex * scalar;
}

Q_DECLARE_METATYPE(Point3D)
Point3D vertexFromVector(const QVector3D& vector);
QVector3D vertexToVector(const Point3D &vertex);
QString vertexToStringParens(const Point3D& vertex);
unsigned int qHash(const Point3D& key);
Point3D operator-(const Point3D& vertex);
QDataStream& operator<<(QDataStream& out, const Point3D& vertex);
QDataStream& operator>>(QDataStream& in, Point3D& vertex);

/*
 * Calls 'function' with the x, y and z coordinates of 'vertex'.
 */
template<typename Function>
inline auto xyz(Function&& function, const Point3D& vertex)
{
	return function(vertex.x, vertex.y, vertex.z);
}

mercurial