src/ldObject.cpp

changeset 1217
314e12e23c3a
parent 1215
77a0270352a3
child 1218
e0b59d183f96
--- a/src/ldObject.cpp	Thu Jan 04 19:40:52 2018 +0200
+++ b/src/ldObject.cpp	Thu Jan 04 19:44:26 2018 +0200
@@ -27,9 +27,9 @@
 #include "colors.h"
 #include "glCompiler.h"
 
-ConfigOption (QString DefaultName = "")
-ConfigOption (QString DefaultUser = "")
-ConfigOption (bool UseCaLicense = true)
+ConfigOption(QString DefaultName = "")
+ConfigOption(QString DefaultUser = "")
+ConfigOption(bool UseCaLicense = true)
 
 // List of all LDObjects
 QMap<int32, LDObject*> g_allObjects;
@@ -37,22 +37,22 @@
 enum { MAX_LDOBJECT_IDS = (1 << 24) };
 
 #define LDOBJ_DEFAULT_CTOR(T,BASE) \
-	T :: T (LDDocument* document) : \
-		BASE (document) {}
+	T :: T(LDDocument* document) : \
+		BASE(document) {}
 
 // =============================================================================
 // LDObject constructors
 //
-LDObject::LDObject (LDDocument* document) :
-	m_isHidden (false),
-	m_isSelected (false),
-	m_isDestroyed (false),
-	m_document (nullptr)
+LDObject::LDObject(LDDocument* document) :
+	m_isHidden(false),
+	m_isSelected(false),
+	m_isDestroyed(false),
+	m_document(nullptr)
 {
 	if (document)
-		document->addObject (this);
+		document->addObject(this);
 
-	memset (m_coords, 0, sizeof m_coords);
+	memset(m_coords, 0, sizeof m_coords);
 
 	// Let's hope that nobody goes to create 17 million objects anytime soon...
 	static int32 nextId = 1; // 0 shalt be null
@@ -64,41 +64,41 @@
 	if (m_id != 0)
 		g_allObjects[m_id] = this;
 
-	m_randomColor = QColor::fromHsv (rand() % 360, rand() % 256, rand() % 96 + 128);
+	m_randomColor = QColor::fromHsv(rand() % 360, rand() % 256, rand() % 96 + 128);
 }
 
-LDSubfileReference::LDSubfileReference (LDDocument* document) :
-	LDMatrixObject (document) {}
+LDSubfileReference::LDSubfileReference(LDDocument* document) :
+	LDMatrixObject(document) {}
 
-LDOBJ_DEFAULT_CTOR (LDEmpty, LDObject)
-LDOBJ_DEFAULT_CTOR (LDError, LDObject)
-LDOBJ_DEFAULT_CTOR (LDLine, LDObject)
-LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject)
-LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine)
-LDOBJ_DEFAULT_CTOR (LDQuad, LDObject)
-LDOBJ_DEFAULT_CTOR (LDOverlay, LDObject)
-LDOBJ_DEFAULT_CTOR (LDBfc, LDObject)
-LDOBJ_DEFAULT_CTOR (LDComment, LDObject)
-LDOBJ_DEFAULT_CTOR (LDBezierCurve, LDObject)
+LDOBJ_DEFAULT_CTOR(LDEmpty, LDObject)
+LDOBJ_DEFAULT_CTOR(LDError, LDObject)
+LDOBJ_DEFAULT_CTOR(LDLine, LDObject)
+LDOBJ_DEFAULT_CTOR(LDTriangle, LDObject)
+LDOBJ_DEFAULT_CTOR(LDCondLine, LDLine)
+LDOBJ_DEFAULT_CTOR(LDQuad, LDObject)
+LDOBJ_DEFAULT_CTOR(LDOverlay, LDObject)
+LDOBJ_DEFAULT_CTOR(LDBfc, LDObject)
+LDOBJ_DEFAULT_CTOR(LDComment, LDObject)
+LDOBJ_DEFAULT_CTOR(LDBezierCurve, LDObject)
 
 LDObject::~LDObject()
 {
 	if (not m_isDestroyed)
-		print ("Warning: Object #%1 (%2) was not destroyed before being deleted\n", id(), this);
+		print("Warning: Object #%1(%2) was not destroyed before being deleted\n", id(), this);
 }
 
 // =============================================================================
 //
 QString LDComment::asText() const
 {
-	return format ("0 %1", text());
+	return format("0 %1", text());
 }
 
 // =============================================================================
 //
 QString LDSubfileReference::asText() const
 {
-	QString val = format ("1 %1 %2 ", color(), position());
+	QString val = format("1 %1 %2 ", color(), position());
 	val += transform().toString();
 	val += ' ';
 	val += fileInfo()->name();
@@ -109,10 +109,10 @@
 //
 QString LDLine::asText() const
 {
-	QString val = format ("2 %1", color());
+	QString val = format("2 %1", color());
 
 	for (int i = 0; i < 2; ++i)
-		val += format (" %1", vertex (i));
+		val += format(" %1", vertex(i));
 
 	return val;
 }
@@ -121,10 +121,10 @@
 //
 QString LDTriangle::asText() const
 {
-	QString val = format ("3 %1", color());
+	QString val = format("3 %1", color());
 
 	for (int i = 0; i < 3; ++i)
-		val += format (" %1", vertex (i));
+		val += format(" %1", vertex(i));
 
 	return val;
 }
@@ -133,10 +133,10 @@
 //
 QString LDQuad::asText() const
 {
-	QString val = format ("4 %1", color());
+	QString val = format("4 %1", color());
 
 	for (int i = 0; i < 4; ++i)
-		val += format (" %1", vertex (i));
+		val += format(" %1", vertex(i));
 
 	return val;
 }
@@ -145,22 +145,22 @@
 //
 QString LDCondLine::asText() const
 {
-	QString val = format ("5 %1", color());
+	QString val = format("5 %1", color());
 	
 	// Add the coordinates
 	for (int i = 0; i < 4; ++i)
-		val += format (" %1", vertex (i));
+		val += format(" %1", vertex(i));
 
 	return val;
 }
 
 QString LDBezierCurve::asText() const
 {
-	QString result = format ("0 !LDFORGE BEZIER_CURVE %1", color());
+	QString result = format("0 !LDFORGE BEZIER_CURVE %1", color());
 
 	// Add the coordinates
 	for (int i = 0; i < 4; ++i)
-		result += format (" %1", vertex (i));
+		result += format(" %1", vertex(i));
 
 	return result;
 }
@@ -183,7 +183,7 @@
 //
 QString LDBfc::asText() const
 {
-	return format ("0 BFC %1", statementToString());
+	return format("0 BFC %1", statementToString());
 }
 
 // =============================================================================
@@ -196,12 +196,12 @@
 	// |   |  ==>  | /    / |
 	// |   |       |/    /  |
 	// 1---2       1    1---2
-	LDTriangle* tri1 (new LDTriangle (vertex (0), vertex (1), vertex (3)));
-	LDTriangle* tri2 (new LDTriangle (vertex (1), vertex (2), vertex (3)));
+	LDTriangle* tri1(new LDTriangle(vertex(0), vertex(1), vertex(3)));
+	LDTriangle* tri2(new LDTriangle(vertex(1), vertex(2), vertex(3)));
 
 	// The triangles also inherit the quad's color
-	tri1->setColor (color());
-	tri2->setColor (color());
+	tri1->setColor(color());
+	tri2->setColor(color());
 
 	return {tri1, tri2};
 }
@@ -210,30 +210,30 @@
 //
 // Replace this LDObject with another LDObject. Object is deleted in the process.
 //
-void LDObject::replace (LDObject* other)
+void LDObject::replace(LDObject* other)
 {
 	int idx = lineNumber();
 
 	if (idx != -1)
 	{
 		// Replace the instance of the old object with the new object
-		document()->setObject (idx, other);
+		document()->setObject(idx, other);
 
 		// Remove the old object
 		destroy();
 	}
 }
 
-void LDObject::replace (const LDObjectList& others)
+void LDObject::replace(const LDObjectList& others)
 {
 	int idx = lineNumber();
 
 	if (idx != -1 and not others.isEmpty())
 	{
 		for (int i = 1; i < others.size(); ++i)
-			document()->insertObj (idx + i, others[i]);
+			document()->insertObj(idx + i, others[i]);
 
-		document()->setObject (idx, others[0]);
+		document()->setObject(idx, others[0]);
 		destroy();
 	}
 }
@@ -242,63 +242,63 @@
 //
 // Swap this object with another.
 //
-void LDObject::swap (LDObject* other)
+void LDObject::swap(LDObject* other)
 {
 	if (document() == other->document())
-		document()->swapObjects (this, other);
+		document()->swapObjects(this, other);
 }
 
 // =============================================================================
 //
-LDLine::LDLine (Vertex v1, Vertex v2, LDDocument* document) :
-	LDObject (document)
+LDLine::LDLine(Vertex v1, Vertex v2, LDDocument* document) :
+	LDObject(document)
 {
-	setVertex (0, v1);
-	setVertex (1, v2);
+	setVertex(0, v1);
+	setVertex(1, v2);
 }
 
 // =============================================================================
 //
-LDTriangle::LDTriangle (const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document) :
-	LDObject (document)
+LDTriangle::LDTriangle(const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document) :
+	LDObject(document)
 {
-	setVertex (0, v1);
-	setVertex (1, v2);
-	setVertex (2, v3);
+	setVertex(0, v1);
+	setVertex(1, v2);
+	setVertex(2, v3);
 }
 
 // =============================================================================
 //
-LDQuad::LDQuad (const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document) :
-	LDObject (document)
+LDQuad::LDQuad(const Vertex& v1, const Vertex& v2, const Vertex& v3, const Vertex& v4, LDDocument* document) :
+	LDObject(document)
 {
-	setVertex (0, v1);
-	setVertex (1, v2);
-	setVertex (2, v3);
-	setVertex (3, v4);
+	setVertex(0, v1);
+	setVertex(1, v2);
+	setVertex(2, v3);
+	setVertex(3, v4);
 }
 
 // =============================================================================
 //
-LDCondLine::LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document) :
-	LDLine (document)
+LDCondLine::LDCondLine(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3, LDDocument* document) :
+	LDLine(document)
 {
-	setVertex (0, v0);
-	setVertex (1, v1);
-	setVertex (2, v2);
-	setVertex (3, v3);
+	setVertex(0, v0);
+	setVertex(1, v1);
+	setVertex(2, v2);
+	setVertex(3, v3);
 }
 
 // =============================================================================
 //
 LDBezierCurve::LDBezierCurve(const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3,
 	LDDocument* document) :
-	LDObject (document)
+	LDObject(document)
 {
-	setVertex (0, v0);
-	setVertex (1, v1);
-	setVertex (2, v2);
-	setVertex (3, v3);
+	setVertex(0, v0);
+	setVertex(1, v1);
+	setVertex(2, v2);
+	setVertex(3, v3);
 }
 
 // =============================================================================
@@ -311,21 +311,21 @@
 
 	// If this object was associated to a file, remove it off it now
 	if (document())
-		document()->forgetObject (this);
+		document()->forgetObject(this);
 
 	// Delete the GL lists
 	if (g_win)
-		g_win->renderer()->forgetObject (this);
+		g_win->renderer()->forgetObject(this);
 
 	// Remove this object from the list of LDObjects
-	g_allObjects.erase (g_allObjects.find (id()));
+	g_allObjects.erase(g_allObjects.find(id()));
 	m_isDestroyed = true;
 	delete this;
 }
 
 // =============================================================================
 //
-void LDObject::setDocument (LDDocument* document)
+void LDObject::setDocument(LDDocument* document)
 {
 	m_document = document;
 
@@ -335,9 +335,9 @@
 
 // =============================================================================
 //
-static void TransformObject (LDObject* obj, Matrix transform, Vertex pos, LDColor parentcolor)
+static void TransformObject(LDObject* obj, Matrix transform, Vertex pos, LDColor parentcolor)
 {
-	switch (obj->type())
+	switch(obj->type())
 	{
 	case OBJ_Line:
 	case OBJ_CondLine:
@@ -345,20 +345,20 @@
 	case OBJ_Quad:
 		for (int i = 0; i < obj->numVertices(); ++i)
 		{
-			Vertex v = obj->vertex (i);
-			v.transform (transform, pos);
-			obj->setVertex (i, v);
+			Vertex v = obj->vertex(i);
+			v.transform(transform, pos);
+			obj->setVertex(i, v);
 		}
 		break;
 
 	case OBJ_SubfileReference:
 		{
-			LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj);
+			LDSubfileReference* ref = static_cast<LDSubfileReference*>(obj);
 			Matrix newMatrix = transform * ref->transform();
 			Vertex newpos = ref->position();
-			newpos.transform (transform, pos);
-			ref->setPosition (newpos);
-			ref->setTransform (newMatrix);
+			newpos.transform(transform, pos);
+			ref->setPosition(newpos);
+			ref->setTransform(newMatrix);
 		}
 		break;
 
@@ -367,18 +367,18 @@
 	}
 
 	if (obj->color() == MainColor)
-		obj->setColor (parentcolor);
+		obj->setColor(parentcolor);
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-LDObjectList LDSubfileReference::inlineContents (bool deep, bool render)
+LDObjectList LDSubfileReference::inlineContents(bool deep, bool render)
 {
-	LDObjectList objs = fileInfo()->inlineContents (deep, render);
+	LDObjectList objs = fileInfo()->inlineContents(deep, render);
 
 	// Transform the objects
 	for (LDObject* obj : objs)
-		TransformObject (obj, transform(), position(), color());
+		TransformObject(obj, transform(), position(), color());
 
 	return objs;
 }
@@ -389,9 +389,9 @@
 {
 	LDObjectType ot = type();
 	int num = (ot == OBJ_Line)		? 2
-			: (ot == OBJ_Triangle)	? 3
-			: (ot == OBJ_Quad)		? 4
-			: (ot == OBJ_CondLine)	? 5
+			:(ot == OBJ_Triangle)	? 3
+			:(ot == OBJ_Quad)		? 4
+			:(ot == OBJ_CondLine)	? 5
 			: 0;
 
 	if (num == 0)
@@ -403,7 +403,7 @@
 	data->color = color().index();
 
 	for (int i = 0; i < data->numVertices(); ++i)
-		data->vertices[i] = vertex (i);
+		data->vertices[i] = vertex(i);
 
 	return data;
 }
@@ -417,7 +417,7 @@
 	for (LDPolygon& entry : data)
 	{
 		for (int i = 0; i < entry.numVertices(); ++i)
-			entry.vertices[i].transform (transform(), position());
+			entry.vertices[i].transform(transform(), position());
 	}
 
 	return data;
@@ -425,7 +425,7 @@
 
 // =============================================================================
 //
-// Index (i.e. line number) of this object
+// Index(i.e. line number) of this object
 //
 int LDObject::lineNumber() const
 {
@@ -433,7 +433,7 @@
 	{
 		for (int i = 0; i < document()->getObjectCount(); ++i)
 		{
-			if (document()->getObject (i) == this)
+			if (document()->getObject(i) == this)
 				return i;
 		}
 	}
@@ -443,13 +443,13 @@
 
 // =============================================================================
 //
-void LDObject::moveObjects (LDObjectList objs, const bool up)
+void LDObject::moveObjects(LDObjectList objs, const bool up)
 {
 	if (objs.isEmpty())
 		return;
 
 	// If we move down, we need to iterate the array in reverse order.
-	long const start = up ? 0 : (objs.size() - 1);
+	long const start = up ? 0 :(objs.size() - 1);
 	long const end = up ? objs.size() : -1;
 	long const incr = up ? 1 : -1;
 	LDObjectList objsToCompile;
@@ -460,9 +460,9 @@
 		LDObject* obj = objs[i];
 
 		long const idx = obj->lineNumber();
-		long const target = idx + (up ? -1 : 1);
+		long const target = idx +(up ? -1 : 1);
 
-		if ((up and idx == 0) or (not up and idx == (long) file->objects().size() - 1l))
+		if ((up and idx == 0) or(not up and idx == (long) file->objects().size() - 1l))
 		{
 			// One of the objects hit the extrema. If this happens, this should be the first
 			// object to be iterated on. Thus, nothing has changed yet and it's safe to just
@@ -471,33 +471,33 @@
 		}
 
 		objsToCompile << obj;
-		objsToCompile << file->getObject (target);
+		objsToCompile << file->getObject(target);
 
-		obj->swap (file->getObject (target));
+		obj->swap(file->getObject(target));
 	}
 
-	removeDuplicates (objsToCompile);
+	removeDuplicates(objsToCompile);
 
 	// The objects need to be recompiled, otherwise their pick lists are left with
 	// the wrong index colors which messes up selection.
 	for (LDObject* obj : objsToCompile)
-		g_win->renderer()->compileObject (obj);
+		g_win->renderer()->compileObject(obj);
 }
 
 // =============================================================================
 //
 // Get type name by enumerator
 //
-QString LDObject::typeName (LDObjectType type)
+QString LDObject::typeName(LDObjectType type)
 {
-	return LDObject::getDefault (type)->typeName();
+	return LDObject::getDefault(type)->typeName();
 }
 
 // =============================================================================
 //
 // Get a description of a list of LDObjects
 //
-QString LDObject::describeObjects (const LDObjectList& objs)
+QString LDObject::describeObjects(const LDObjectList& objs)
 {
 	QString text;
 
@@ -520,8 +520,8 @@
 		if (not text.isEmpty())
 			text += ", ";
 
-		QString noun = format ("%1%2", typeName (objType), plural (count));
-		text += format ("%1 %2", count, noun);
+		QString noun = format("%1%2", typeName(objType), plural(count));
+		text += format("%1 %2", count, noun);
 	}
 
 	return text;
@@ -538,7 +538,7 @@
 	if (idx == -1 or idx == document()->getObjectCount() - 1)
 		return nullptr;
 
-	return document()->getObject (idx + 1);
+	return document()->getObject(idx + 1);
 }
 
 // =============================================================================
@@ -552,20 +552,20 @@
 	if (idx <= 0)
 		return nullptr;
 
-	return document()->getObject (idx - 1);
+	return document()->getObject(idx - 1);
 }
 
 // =============================================================================
 //
 // Is the previous object INVERTNEXT?
 //
-bool LDObject::previousIsInvertnext (LDBfc*& ptr)
+bool LDObject::previousIsInvertnext(LDBfc*& ptr)
 {
 	LDObject* prev = previous();
 
-	if (prev and prev->type() == OBJ_Bfc and static_cast<LDBfc*> (prev)->statement() == BfcStatement::InvertNext)
+	if (prev and prev->type() == OBJ_Bfc and static_cast<LDBfc*>(prev)->statement() == BfcStatement::InvertNext)
 	{
-		ptr = static_cast<LDBfc*> (prev);
+		ptr = static_cast<LDBfc*>(prev);
 		return true;
 	}
 
@@ -576,17 +576,17 @@
 //
 // Moves this object using the given vertex as a movement List
 //
-void LDObject::move (Vertex vect)
+void LDObject::move(Vertex vect)
 {
 	if (hasMatrix())
 	{
-		LDMatrixObject* mo = static_cast<LDMatrixObject*> (this);
-		mo->setPosition (mo->position() + vect);
+		LDMatrixObject* mo = static_cast<LDMatrixObject*>(this);
+		mo->setPosition(mo->position() + vect);
 	}
 	else
 	{
 		for (int i = 0; i < numVertices(); ++i)
-			setVertex (i, vertex (i) + vect);
+			setVertex(i, vertex(i) + vect);
 	}
 }
 
@@ -595,7 +595,7 @@
 	return m_isHidden;
 }
 
-void LDObject::setHidden (bool value)
+void LDObject::setHidden(bool value)
 {
 	m_isHidden = value;
 }
@@ -634,9 +634,9 @@
 //
 // Returns a default-constructed LDObject by the given type
 //
-LDObject* LDObject::getDefault (const LDObjectType type)
+LDObject* LDObject::getDefault(const LDObjectType type)
 {
-	switch (type)
+	switch(type)
 	{
 	case OBJ_Comment:		return LDSpawn<LDComment>();
 	case OBJ_Bfc:			return LDSpawn<LDBfc>();
@@ -668,9 +668,9 @@
 {
 	// Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1.
 	// Thus, we swap 1 and 2.
-	Vertex tmp = vertex (1);
-	setVertex (1, vertex (2));
-	setVertex (2, tmp);
+	Vertex tmp = vertex(1);
+	setVertex(1, vertex(2));
+	setVertex(2, tmp);
 
 	return;
 }
@@ -682,9 +682,9 @@
 	// Quad:     0 -> 1 -> 2 -> 3
 	// reversed: 0 -> 3 -> 2 -> 1
 	// Thus, we swap 1 and 3.
-	Vertex tmp = vertex (1);
-	setVertex (1, vertex (3));
-	setVertex (3, tmp);
+	Vertex tmp = vertex(1);
+	setVertex(1, vertex(3));
+	setVertex(3, tmp);
 }
 
 // =============================================================================
@@ -695,22 +695,22 @@
 		return;
 
 	// Check whether subfile is flat
-	int axisSet = (1 << X) | (1 << Y) | (1 << Z);
-	LDObjectList objs = fileInfo()->inlineContents (true, false);
+	int axisSet = (1 << X) |(1 << Y) |(1 << Z);
+	LDObjectList objs = fileInfo()->inlineContents(true, false);
 
 	for (LDObject* obj : objs)
 	{
 		for (int i = 0; i < obj->numVertices(); ++i)
 		{
-			Vertex const& vrt = obj->vertex (i);
+			Vertex const& vrt = obj->vertex(i);
 
-			if (axisSet & (1 << X) and vrt.x() != 0.0)
+			if (axisSet &(1 << X) and vrt.x() != 0.0)
 				axisSet &= ~(1 << X);
 
-			if (axisSet & (1 << Y) and vrt.y() != 0.0)
+			if (axisSet &(1 << Y) and vrt.y() != 0.0)
 				axisSet &= ~(1 << Y);
 
-			if (axisSet & (1 << Z) and vrt.z() != 0.0)
+			if (axisSet &(1 << Z) and vrt.z() != 0.0)
 				axisSet &= ~(1 << Z);
 		}
 
@@ -724,16 +724,16 @@
 		// Let's flip it.
 		Matrix matrixModifier = IdentityMatrix;
 
-		if (axisSet & (1 << X))
+		if (axisSet &(1 << X))
 			matrixModifier[0] = -1;
 
-		if (axisSet & (1 << Y))
+		if (axisSet &(1 << Y))
 			matrixModifier[4] = -1;
 
-		if (axisSet & (1 << Z))
+		if (axisSet &(1 << Z))
 			matrixModifier[8] = -1;
 
-		setTransform (transform() * matrixModifier);
+		setTransform(transform() * matrixModifier);
 		return;
 	}
 
@@ -742,7 +742,7 @@
 
 	if (idx > 0)
 	{
-		LDBfc* bfc = dynamic_cast<LDBfc*> (previous());
+		LDBfc* bfc = dynamic_cast<LDBfc*>(previous());
 
 		if (bfc and bfc->statement() == BfcStatement::InvertNext)
 		{
@@ -753,7 +753,7 @@
 	}
 
 	// Not inverted, thus prefix it with a new invertnext.
-	document()->insertObj (idx, new LDBfc (BfcStatement::InvertNext));
+	document()->insertObj(idx, new LDBfc(BfcStatement::InvertNext));
 }
 
 // =============================================================================
@@ -761,9 +761,9 @@
 void LDLine::invert()
 {
 	// For lines, we swap the vertices.
-	Vertex tmp = vertex (0);
-	setVertex (0, vertex (1));
-	setVertex (1, tmp);
+	Vertex tmp = vertex(0);
+	setVertex(0, vertex(1));
+	setVertex(1, tmp);
 }
 
 // =============================================================================
@@ -771,9 +771,9 @@
 void LDCondLine::invert()
 {
 	// I don't think that a conditional line's control points need to be swapped, do they?
-	Vertex tmp = vertex (0);
-	setVertex (0, vertex (1));
-	setVertex (1, tmp);
+	Vertex tmp = vertex(0);
+	setVertex(0, vertex(1));
+	setVertex(1, tmp);
 }
 
 // =============================================================================
@@ -781,12 +781,12 @@
 void LDBezierCurve::invert()
 {
 	// A Bézier curve's control points probably need to be, though.
-	Vertex tmp = vertex (1);
-	setVertex (1, vertex (0));
-	setVertex (0, tmp);
-	tmp = vertex (3);
-	setVertex (3, vertex (2));
-	setVertex (2, tmp);
+	Vertex tmp = vertex(1);
+	setVertex(1, vertex(0));
+	setVertex(0, tmp);
+	tmp = vertex(3);
+	setVertex(3, vertex(2));
+	setVertex(2, tmp);
 }
 
 // =============================================================================
@@ -796,18 +796,18 @@
 	LDLine* replacement = new LDLine;
 
 	for (int i = 0; i < replacement->numVertices(); ++i)
-		replacement->setVertex (i, vertex (i));
+		replacement->setVertex(i, vertex(i));
 
-	replacement->setColor (color());
-	replace (replacement);
+	replacement->setColor(color());
+	replace(replacement);
 	return replacement;
 }
 
 // =============================================================================
 //
-LDObject* LDObject::fromID (int id)
+LDObject* LDObject::fromID(int id)
 {
-	auto it = g_allObjects.find (id);
+	auto it = g_allObjects.find(id);
 
 	if (it != g_allObjects.end())
 		return *it;
@@ -819,7 +819,7 @@
 //
 QString LDOverlay::asText() const
 {
-	return format ("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6",
+	return format("0 !LDFORGE OVERLAY %1 %2 %3 %4 %5 %6",
 		fileName(), camera(), x(), y(), width(), height());
 }
 
@@ -832,14 +832,14 @@
 // makes history stuff work out of the box.
 //
 template<typename T>
-static void changeProperty (LDObject* obj, T* ptr, const T& val)
+static void changeProperty(LDObject* obj, T* ptr, const T& val)
 {
 	int idx;
 
 	if (*ptr == val)
 		return;
 
-	if (obj->document() and (idx = obj->lineNumber()) != -1)
+	if (obj->document() and(idx = obj->lineNumber()) != -1)
 	{
 		QString before = obj->asText();
 		*ptr = val;
@@ -847,8 +847,8 @@
 
 		if (before != after)
 		{
-			obj->document()->addToHistory (new EditHistoryEntry (idx, before, after));
-			g_win->renderer()->compileObject (obj);
+			obj->document()->addToHistory(new EditHistoryEntry(idx, before, after));
+			g_win->renderer()->compileObject(obj);
 			g_win->currentDocument()->redoVertices();
 		}
 	}
@@ -860,16 +860,16 @@
 
 // =============================================================================
 //
-void LDObject::setColor (LDColor color)
+void LDObject::setColor(LDColor color)
 {
-	changeProperty (this, &m_color, color);
+	changeProperty(this, &m_color, color);
 }
 
 // =============================================================================
 //
 // Get a vertex by index
 //
-const Vertex& LDObject::vertex (int i) const
+const Vertex& LDObject::vertex(int i) const
 {
 	return m_coords[i];
 }
@@ -878,32 +878,32 @@
 //
 // Set a vertex to the given value
 //
-void LDObject::setVertex (int i, const Vertex& vert)
+void LDObject::setVertex(int i, const Vertex& vert)
 {
-	changeProperty (this, &m_coords[i], vert);
+	changeProperty(this, &m_coords[i], vert);
 }
 
-LDMatrixObject::LDMatrixObject (LDDocument* document) :
-	LDObject (document),
-	m_position (Origin) {}
+LDMatrixObject::LDMatrixObject(LDDocument* document) :
+	LDObject(document),
+	m_position(Origin) {}
 
-LDMatrixObject::LDMatrixObject (const Matrix& transform, const Vertex& pos, LDDocument* document) :
-	LDObject (document),
-	m_position (pos),
-	m_transform (transform) {}
+LDMatrixObject::LDMatrixObject(const Matrix& transform, const Vertex& pos, LDDocument* document) :
+	LDObject(document),
+	m_position(pos),
+	m_transform(transform) {}
 
-void LDMatrixObject::setCoordinate (const Axis ax, double value)
+void LDMatrixObject::setCoordinate(const Axis ax, double value)
 {
 	Vertex v = position();
 
-	switch (ax)
+	switch(ax)
 	{
-		case X: v.setX (value); break;
-		case Y: v.setY (value); break;
-		case Z: v.setZ (value); break;
+		case X: v.setX(value); break;
+		case Y: v.setY(value); break;
+		case Z: v.setZ(value); break;
 	}
 
-	setPosition (v);
+	setPosition(v);
 }
 
 const Vertex& LDMatrixObject::position() const
@@ -913,9 +913,9 @@
 
 // =============================================================================
 //
-void LDMatrixObject::setPosition (const Vertex& a)
+void LDMatrixObject::setPosition(const Vertex& a)
 {
-	changeProperty (this, &m_position, a);
+	changeProperty(this, &m_position, a);
 }
 
 // =============================================================================
@@ -925,15 +925,15 @@
 	return m_transform;
 }
 
-void LDMatrixObject::setTransform (const Matrix& val)
+void LDMatrixObject::setTransform(const Matrix& val)
 {
-	changeProperty (this, &m_transform, val);
+	changeProperty(this, &m_transform, val);
 }
 
-LDError::LDError (QString contents, QString reason, LDDocument* document) :
-	LDObject (document),
-	m_contents (contents),
-	m_reason (reason) {}
+LDError::LDError(QString contents, QString reason, LDDocument* document) :
+	LDObject(document),
+	m_contents(contents),
+	m_reason(reason) {}
 
 QString LDError::reason() const
 {
@@ -950,45 +950,45 @@
 	return m_fileReferenced;
 }
 
-void LDError::setFileReferenced (QString value)
+void LDError::setFileReferenced(QString value)
 {
 	m_fileReferenced = value;
 }
 
-LDComment::LDComment (QString text, LDDocument* document) :
-	LDObject (document),
-	m_text (text) {}
+LDComment::LDComment(QString text, LDDocument* document) :
+	LDObject(document),
+	m_text(text) {}
 
 QString LDComment::text() const
 {
 	return m_text;
 }
 
-void LDComment::setText (QString value)
+void LDComment::setText(QString value)
 {
-	changeProperty (this, &m_text, value);
+	changeProperty(this, &m_text, value);
 }
 
-LDBfc::LDBfc (const BfcStatement type, LDDocument* document) :
-	LDObject (document),
-	m_statement (type) {}
+LDBfc::LDBfc(const BfcStatement type, LDDocument* document) :
+	LDObject(document),
+	m_statement(type) {}
 
 BfcStatement LDBfc::statement() const
 {
 	return m_statement;
 }
 
-void LDBfc::setStatement (BfcStatement value)
+void LDBfc::setStatement(BfcStatement value)
 {
 	m_statement = value;
 }
 
 QString LDBfc::statementToString() const
 {
-	return LDBfc::statementToString (statement());
+	return LDBfc::statementToString(statement());
 }
 
-QString LDBfc::statementToString (BfcStatement statement)
+QString LDBfc::statementToString(BfcStatement statement)
 {
 	static const char* statementStrings[] =
 	{
@@ -1004,8 +1004,8 @@
 		"NOCLIP",
 	};
 
-	if ((int) statement >= 0 and (int) statement < countof (statementStrings))
-		return QString::fromLatin1 (statementStrings[(int) statement]);
+	if ((int) statement >= 0 and(int) statement < countof(statementStrings))
+		return QString::fromLatin1(statementStrings[(int) statement]);
 	else
 		return "";
 }
@@ -1015,7 +1015,7 @@
 	return m_camera;
 }
 
-void LDOverlay::setCamera (int value)
+void LDOverlay::setCamera(int value)
 {
 	m_camera = value;
 }
@@ -1025,7 +1025,7 @@
 	return m_x;
 }
 
-void LDOverlay::setX (int value)
+void LDOverlay::setX(int value)
 {
 	m_x = value;
 }
@@ -1035,7 +1035,7 @@
 	return m_y;
 }
 
-void LDOverlay::setY (int value)
+void LDOverlay::setY(int value)
 {
 	m_y = value;
 }
@@ -1045,7 +1045,7 @@
 	return m_width;
 }
 
-void LDOverlay::setWidth (int value)
+void LDOverlay::setWidth(int value)
 {
 	m_width = value;
 }
@@ -1055,7 +1055,7 @@
 	return m_height;
 }
 
-void LDOverlay::setHeight (int value)
+void LDOverlay::setHeight(int value)
 {
 	m_height = value;
 }
@@ -1065,57 +1065,57 @@
 	return m_fileName;
 }
 
-void LDOverlay::setFileName (QString value)
+void LDOverlay::setFileName(QString value)
 {
 	m_fileName = value;
 }
 
-Vertex LDBezierCurve::pointAt (qreal t) const
+Vertex LDBezierCurve::pointAt(qreal t) const
 {
 	if (t >= 0.0 and t <= 1.0)
 	{
 		Vertex result;
-		result += pow (1.0 - t, 3) * vertex (0);
-		result += (3 * pow (1.0 - t, 2) * t) * vertex (2);
-		result += (3 * (1.0 - t) * pow (t, 2)) * vertex (3);
-		result += pow (t, 3) * vertex (1);
+		result += pow(1.0 - t, 3) * vertex(0);
+		result += (3 * pow(1.0 - t, 2) * t) * vertex(2);
+		result += (3 *(1.0 - t) * pow(t, 2)) * vertex(3);
+		result += pow(t, 3) * vertex(1);
 		return result;
 	}
 	else
 		return Vertex();
 }
 
-LDObjectList LDBezierCurve::rasterize (int segments)
+LDObjectList LDBezierCurve::rasterize(int segments)
 {
 	if (segments == 0)
 		segments = gridBezierCurveSegments();
 
-	QVector<LDPolygon> polygons = rasterizePolygons (segments);
+	QVector<LDPolygon> polygons = rasterizePolygons(segments);
 	LDObjectList result;
 
 	for (LDPolygon& poly : polygons)
 	{
-		LDLine* line = LDSpawn<LDLine> (poly.vertices[0], poly.vertices[1]);
-		line->setColor (poly.color);
+		LDLine* line = LDSpawn<LDLine>(poly.vertices[0], poly.vertices[1]);
+		line->setColor(poly.color);
 		result << line;
 	}
 
 	return result;
 }
 
-QVector<LDPolygon> LDBezierCurve::rasterizePolygons (int segments)
+QVector<LDPolygon> LDBezierCurve::rasterizePolygons(int segments)
 {
 	if (segments == 0)
 		segments = gridBezierCurveSegments();
 
 	QVector<LDPolygon> result;
 	QVector<Vertex> parms;
-	parms.append (pointAt (0.0));
+	parms.append(pointAt(0.0));
 
 	for (int i = 1; i < segments; ++i)
-		parms.append (pointAt (double (i) / segments));
+		parms.append(pointAt(double(i) / segments));
 
-	parms.append (pointAt (1.0));
+	parms.append(pointAt(1.0));
 	LDPolygon poly;
 	poly.color = color().index();
 	poly.id = id();
@@ -1140,7 +1140,7 @@
 	if (not isSelected() and document())
 	{
 		m_isSelected = true;
-		document()->addToSelection (this);
+		document()->addToSelection(this);
 	}
 }
 
@@ -1153,12 +1153,12 @@
 	if (isSelected() and document())
 	{
 		m_isSelected = false;
-		document()->removeFromSelection (this);
+		document()->removeFromSelection(this);
 
 		// If this object is inverted with INVERTNEXT, deselect the INVERTNEXT as well.
 		LDBfc* invertnext;
 
-		if (previousIsInvertnext (invertnext))
+		if (previousIsInvertnext(invertnext))
 			invertnext->deselect();
 	}
 }
@@ -1174,7 +1174,7 @@
 //
 LDObject* LDObject::createCopy() const
 {
-	LDObject* copy = ParseLine (asText());
+	LDObject* copy = ParseLine(asText());
 	return copy;
 }
 
@@ -1185,11 +1185,11 @@
 	return m_fileInfo;
 }
 
-void LDSubfileReference::setFileInfo (LDDocument* document)
+void LDSubfileReference::setFileInfo(LDDocument* document)
 {
-	changeProperty (this, &m_fileInfo, document);
+	changeProperty(this, &m_fileInfo, document);
 
-	// If it's an immediate subfile reference (i.e. this subfile is in an opened document), we need to pre-compile the
+	// If it's an immediate subfile reference(i.e. this subfile is in an opened document), we need to pre-compile the
 	// GL polygons for the document if they don't exist already.
 	if (document and
 		document->isCache() == false and
@@ -1199,13 +1199,13 @@
 	}
 };
 
-void LDObject::getVertices (QVector<Vertex>& verts) const
+void LDObject::getVertices(QVector<Vertex>& verts) const
 {
 	for (int i = 0; i < numVertices(); ++i)
-		verts << vertex (i);
+		verts << vertex(i);
 }
 
-void LDSubfileReference::getVertices (QVector<Vertex>& verts) const
+void LDSubfileReference::getVertices(QVector<Vertex>& verts) const
 {
 	verts << fileInfo()->inlineVertices();
 }
\ No newline at end of file

mercurial