src/linetypes/triangle.cpp

Wed, 11 Mar 2020 19:05:34 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 11 Mar 2020 19:05:34 +0200
changeset 80
764381756899
parent 77
028798a72591
child 81
62373840e33a
permissions
-rw-r--r--

simplification

#include "triangle.h"

ldraw::Triangle::Triangle(
	const glm::vec3& point_1,
	const glm::vec3& point_2,
	const glm::vec3& point_3,
	Color color_index) :
	ColoredObject{color_index},
	points{point_1, point_2, point_3}
{
}

ldraw::Triangle::Triangle(const std::array<glm::vec3, 3>& vertices, const Color color) :
	ColoredObject{color},
	points{vertices[0], vertices[1], vertices[2]}
{
}

ldraw::Triangle::Triangle(const glm::vec3 (&vertices)[3], const Color color) :
	ColoredObject{color},
	points{vertices[0], vertices[1], vertices[2]}
{
}

QVariant ldraw::Triangle::getProperty(const Property id) const
{
	switch (id)
	{
	case Property::Point1:
		return QVariant::fromValue(points[0]);
	case Property::Point2:
		return QVariant::fromValue(points[1]);
	case Property::Point3:
		return QVariant::fromValue(points[2]);
	default:
		return ColoredObject::getProperty(id);
	}
}

auto ldraw::Triangle::setProperty(Property id, const QVariant& value)
	-> SetPropertyResult
{
	switch (id)
	{
	case Property::Point1:
		points[0] = value.value<glm::vec3>();
		return SetPropertyResult::Success;
	case Property::Point2:
		points[1] = value.value<glm::vec3>();
		return SetPropertyResult::Success;
	case Property::Point3:
		points[2] = value.value<glm::vec3>();
		return SetPropertyResult::Success;
	default:
		return ColoredObject::setProperty(id, value);
	}
}

QString ldraw::Triangle::textRepresentation() const
{
	return utility::format("%1 %2 %3",
		utility::vertexToStringParens(points[0]),
		utility::vertexToStringParens(points[1]),
		utility::vertexToStringParens(points[2]));
}

void ldraw::Triangle::getPolygons(
	std::vector<gl::Polygon>& polygons,
	GetPolygonsContext* context) const
{
	Q_UNUSED(context)
	polygons.push_back(gl::triangle(
		this->points[0],
		this->points[1],
		this->points[2],
		this->colorIndex,
			this->id));
}

void ldraw::Triangle::invert()
{
	//    0 1 2
	// -> 1 0 2
	std::swap(this->points[0], this->points[1]);
}

mercurial