src/linetypes/polygon.cpp

changeset 14
20d2ed3af73d
parent 13
6e838748867b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/linetypes/polygon.cpp	Sun Nov 03 18:13:38 2019 +0200
@@ -0,0 +1,126 @@
+#include "polygon.h"
+
+linetypes::Triangle::Triangle(
+	const Vertex& point_1,
+	const Vertex& point_2,
+	const Vertex& point_3,
+	Color color_index) :
+	ColoredObject{color_index},
+	points{point_1, point_2, point_3}
+{
+}
+
+linetypes::Triangle::Triangle(const QVector<Vertex>& 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<Vertex>();
+		return SetPropertyResult::Success;
+	case Property::Point2:
+		points[1] = value.value<Vertex>();
+		return SetPropertyResult::Success;
+	case Property::Point3:
+		points[2] = value.value<Vertex>();
+		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]));
+}
+
+linetypes::Quadrilateral::Quadrilateral(
+	const Vertex& point_1,
+	const Vertex& point_2,
+	const Vertex& point_3,
+	const Vertex& point_4,
+	Color color_index) :
+	ColoredObject{color_index},
+	points{point_1, point_2, point_3, point_4}
+{
+}
+
+linetypes::Quadrilateral::Quadrilateral(const QVector<Vertex>& vertices, const Color color) :
+	ColoredObject{color},
+	points{vertices[0], vertices[1], vertices[2], vertices[3]}
+{
+}
+
+QVariant linetypes::Quadrilateral::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];
+	case Property::Point4:
+		return points[3];
+	default:
+		return ColoredObject::getProperty(id);
+	}
+}
+
+auto linetypes::Quadrilateral::setProperty(
+	const Property id,
+	const QVariant& value)
+	-> SetPropertyResult
+{
+	switch (id)
+	{
+	case Property::Point1:
+		points[0] = value.value<Vertex>();
+		return SetPropertyResult::Success;
+	case Property::Point2:
+		points[1] = value.value<Vertex>();
+		return SetPropertyResult::Success;
+	case Property::Point3:
+		points[2] = value.value<Vertex>();
+		return SetPropertyResult::Success;
+	case Property::Point4:
+		points[3] = value.value<Vertex>();
+		return SetPropertyResult::Success;
+	default:
+		return ColoredObject::setProperty(id, value);
+	}
+}
+
+QString linetypes::Quadrilateral::textRepresentation() const
+{
+	return utility::format("%1 %2 %3 %4",
+		vertexToStringParens(points[0]),
+		vertexToStringParens(points[1]),
+		vertexToStringParens(points[2]),
+		vertexToStringParens(points[3]));
+}

mercurial