src/linetypes/triangle.cpp

Sun, 19 Jan 2020 14:25:57 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 19 Jan 2020 14:25:57 +0200
changeset 25
6de5ac1fb471
parent 21
0133e565e072
child 26
3a9e761e4faa
permissions
-rw-r--r--

added debug and release to hgignore

#include "triangle.h"

linetypes::Triangle::Triangle(
	const Point3D& point_1,
	const Point3D& point_2,
	const Point3D& point_3,
	Color color_index) :
	ColoredObject{color_index},
	points{point_1, point_2, point_3}
{
}

linetypes::Triangle::Triangle(const QVector<Point3D>& vertices, const Color color) :
	ColoredObject{color},
	points{vertices[0], vertices[1], vertices[2]}
{
}

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

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

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

void linetypes::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));
}

mercurial