restyle..

Sun, 07 Jul 2013 16:46:30 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 07 Jul 2013 16:46:30 +0300
changeset 358
7885fa5b09c5
parent 357
9c954c222996
child 359
bcdfc801658b

restyle..

src/primitives.cpp file | annotate | diff | comparison | revisions
src/types.cpp file | annotate | diff | comparison | revisions
--- a/src/primitives.cpp	Sun Jul 07 15:08:38 2013 +0300
+++ b/src/primitives.cpp	Sun Jul 07 16:46:30 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 Santeri 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/>.
  */
@@ -33,129 +33,144 @@
 
 static const str g_Other = QObject::tr( "Other" );
 
-static void populateCategories ();
-static void loadPrimitiveCatgories ();
+static void populateCategories();
+static void loadPrimitiveCatgories();
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void loadPrimitives () {
-	print ("Loading primitives...\n");
+void loadPrimitives()
+{
+	print( "Loading primitives...\n" );
 	
-	loadPrimitiveCatgories ();
+	loadPrimitiveCatgories();
 	
 	// Try to load prims.cfg
-	File conf (config::dirpath () + "prims.cfg", File::Read);
-	if (!conf) {
+	File conf( config::dirpath() + "prims.cfg", File::Read );
+	
+	if( !conf )
+	{
 		// No prims.cfg, build it
-		PrimitiveLister::start ();
-	} else {
-		for (str line : conf) {
-			int space = line.indexOf (" ");
-			if (space == -1)
+		PrimitiveLister::start();
+	}
+	else
+	{
+		for( str line : conf )
+		{
+			int space = line.indexOf( " " );
+			
+			if( space == -1 )
 				continue;
 			
 			Primitive info;
-			info.name = line.left (space);
-			info.title = line.mid (space + 1);
+			info.name = line.left( space );
+			info.title = line.mid( space + 1 );
 			g_primitives << info;
 		}
 		
-		populateCategories ();
+		populateCategories();
 	}
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void recursiveGetFilenames (QDir dir, vector<str>& fnames) {
-	QFileInfoList flist = dir.entryInfoList ();
-	for (const QFileInfo& info : flist) {
-		if (info.fileName () == "." || info.fileName () == "..")
+void recursiveGetFilenames( QDir dir, vector<str>& fnames )
+{
+	QFileInfoList flist = dir.entryInfoList();
+	
+	for( const QFileInfo & info : flist )
+	{
+		if( info.fileName() == "." || info.fileName() == ".." )
 			continue; // skip . and ..
 		
-		if (info.isDir ())
-			recursiveGetFilenames (QDir (info.absoluteFilePath ()), fnames);
+		if( info.isDir() )
+			recursiveGetFilenames( QDir( info.absoluteFilePath() ), fnames );
 		else
-			fnames << info.absoluteFilePath ();
+			fnames << info.absoluteFilePath();
 	}
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void PrimitiveLister::work () {
+void PrimitiveLister::work()
+{
 	g_activePrimLister = this;
-	m_prims.clear ();
-	
-	QDir dir (LDPaths::prims ());
-	assert (dir.exists ());
+	m_prims.clear();
 	
-	ulong baselen = dir.absolutePath ().length ();
-	
+	QDir dir( LDPaths::prims() );
+	ulong baselen = dir.absolutePath().length();
+	ulong i = 0;
 	vector<str> fnames;
-	recursiveGetFilenames (dir, fnames);
-	emit starting (fnames.size ());
 	
-	ulong i = 0;
-	for (str fname : fnames) {
-		File f (fname, File::Read);
+	assert( dir.exists() );
+	recursiveGetFilenames( dir, fnames );
+	emit starting( fnames.size() );
+	
+	for( str fname : fnames )
+	{
+		File f( fname, File::Read );
 		
 		Primitive info;
-		info.name = fname.mid (baselen + 1); // make full path relative
-		info.name.replace ('/', '\\'); // use DOS backslashes, they're expected
+		info.name = fname.mid( baselen + 1 ); // make full path relative
+		info.name.replace( '/', '\\' ); // use DOS backslashes, they're expected
+		info.cat = null;
 		
-		if (!f.readLine (info.title))
+		if( !f.readLine( info.title ))
 			info.title = "";
 		
-		info.title = info.title.simplified ();
-		info.cat = null;
+		info.title = info.title.simplified();
 		
-		if (info.title[0] == '0') {
-			info.title.remove (0, 1); // remove 0
-			info.title = info.title.simplified ();
+		if( info.title[0] == '0' )
+		{
+			info.title.remove( 0, 1 ); // remove 0
+			info.title = info.title.simplified();
 		}
 		
 		m_prims << info;
-		emit update (++i);
+		emit update( ++i );
 	}
 	
 	// Save to a config file
-	File conf (config::dirpath () + "prims.cfg", File::Write);
-	for (Primitive& info : m_prims)
-		fprint (conf, "%1 %2\n", info.name, info.title);
+	File conf( config::dirpath() + "prims.cfg", File::Write );
 	
-	conf.close ();
+	for( Primitive & info : m_prims )
+		fprint( conf, "%1 %2\n", info.name, info.title );
+	
+	conf.close();
 	
 	g_primListerMutex = true;
 	g_primitives = m_prims;
-	populateCategories ();
+	populateCategories();
 	g_primListerMutex = false;
 	g_activePrimLister = null;
-	emit workDone ();
+	emit workDone();
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void PrimitiveLister::start () {
-	if (g_activePrimLister)
+void PrimitiveLister::start()
+{
+	if( g_activePrimLister )
 		return;
 	
 	PrimitiveLister* lister = new PrimitiveLister;
 	QThread* listerThread = new QThread;
-	lister->moveToThread (listerThread);
-	connect (lister, SIGNAL (starting (ulong)), g_win, SLOT (primitiveLoaderStart (ulong)));
-	connect (lister, SIGNAL (update (ulong)), g_win, SLOT (primitiveLoaderUpdate (ulong)));
-	connect (lister, SIGNAL (workDone ()), g_win, SLOT (primitiveLoaderEnd ()));
-	connect (listerThread, SIGNAL (started ()), lister, SLOT (work ()));
-	connect (listerThread, SIGNAL (finished ()), lister, SLOT (deleteLater ()));
-	listerThread->start ();
+	lister->moveToThread( listerThread );
+	connect( lister, SIGNAL( starting( ulong )), g_win, SLOT( primitiveLoaderStart( ulong )) );
+	connect( lister, SIGNAL( update( ulong )), g_win, SLOT( primitiveLoaderUpdate( ulong )) );
+	connect( lister, SIGNAL( workDone() ), g_win, SLOT( primitiveLoaderEnd() ));
+	connect( listerThread, SIGNAL( started() ), lister, SLOT( work() ));
+	connect( listerThread, SIGNAL( finished() ), lister, SLOT( deleteLater() ));
+	listerThread->start();
 }
 
-static PrimitiveCategory* findCategory (str name) {
-	for (PrimitiveCategory& cat : g_PrimitiveCategories)
-		if (cat.name () == name)
+static PrimitiveCategory* findCategory( str name )
+{
+	for( PrimitiveCategory & cat : g_PrimitiveCategories )
+		if( cat.name() == name )
 			return &cat;
 	
 	return null;
@@ -164,52 +179,59 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-static void populateCategories () {
-	for (PrimitiveCategory& cat : g_PrimitiveCategories)
-		cat.prims.clear ();
+static void populateCategories()
+{
+	for( PrimitiveCategory & cat : g_PrimitiveCategories )
+		cat.prims.clear();
 	
 	PrimitiveCategory* unmatched = findCategory( g_Other );
 	
-	if (!unmatched) {
+	if( !unmatched )
+	{
 		// Shouldn't happen.. but catch it anyway.
 		PrimitiveCategory cat;
 		cat.setName( g_Other );
-		unmatched = &(g_PrimitiveCategories << cat);
+		unmatched = &( g_PrimitiveCategories << cat );
 	}
 	
-	for (Primitive& prim : g_primitives) {
+	for( Primitive & prim : g_primitives )
+	{
 		bool matched = false;
 		
 		// Go over the categories and their regexes, if and when there's a match,
 		// the primitive's category is set to the category the regex beloings to.
-		for (PrimitiveCategory& cat : g_PrimitiveCategories) {
-			for (PrimitiveCategory::RegexEntry& entry : cat.regexes) {
-				switch (entry.type) {
+		for( PrimitiveCategory & cat : g_PrimitiveCategories )
+		{
+			for( PrimitiveCategory::RegexEntry & entry : cat.regexes )
+			{
+				switch( entry.type )
+				{
 				case PrimitiveCategory::Filename:
 					// f-regex, check against filename
-					matched = entry.regex.exactMatch (prim.name);
+					matched = entry.regex.exactMatch( prim.name );
 					break;
-					
+				
 				case PrimitiveCategory::Title:
 					// t-regex, check against title
-					matched = entry.regex.exactMatch (prim.title);
+					matched = entry.regex.exactMatch( prim.title );
 					break;
 				}
 				
-				if (matched) {
+				if( matched )
+				{
 					prim.cat = &cat;
 					break;
 				}
 			}
 			
 			// Drop out if a category was decided on.
-			if (prim.cat)
+			if( prim.cat )
 				break;
 		}
 		
 		// If there was a match, add the primitive to the category.
 		// Otherwise, add it to the list of unmatched primitives.
-		if (prim.cat)
+		if( prim.cat )
 			prim.cat->prims << prim;
 		else
 			unmatched->prims << prim;
@@ -219,51 +241,58 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-static void loadPrimitiveCatgories () {
-	g_PrimitiveCategories.clear ();
-	
-	File f (config::dirpath () + "primregexps.cfg", File::Read);
+static void loadPrimitiveCatgories()
+{
+	g_PrimitiveCategories.clear();
 	
-	if (!f)
-		f.open (":/data/primitive-categories.cfg", File::Read);
+	File f( config::dirpath() + "primregexps.cfg", File::Read );
 	
-	if (!f)
+	if( !f )
+		f.open( ":/data/primitive-categories.cfg", File::Read );
+	
+	if( !f )
 		critical( QObject::tr( "Failed to open primitive categories!" ));
 	
-	if (f) {
+	if( f )
+	{
 		PrimitiveCategory cat;
-		
-		for (str line : f) {
+	
+		for( str line : f )
+		{
 			int colon;
 			
-			if (line.length () == 0 || line[0] == '#')
+			if( line.length() == 0 || line[0] == '#' )
 				continue;
 			
-			if ((colon = line.indexOf (":")) == -1) {
-				if (cat.regexes.size () > 0)
+			if( ( colon = line.indexOf( ":" )) == -1 )
+			{
+				if( cat.regexes.size() > 0 )
 					g_PrimitiveCategories << cat;
 				
-				cat.regexes.clear ();
-				cat.prims.clear ();
-				cat.setName (line);
-			} else {
-				str cmd = line.left (colon);
+				cat.regexes.clear();
+				cat.prims.clear();
+				cat.setName( line );
+			}
+			else
+			{
+				str cmd = line.left( colon );
 				
 				PrimitiveCategory::Type type = PrimitiveCategory::Filename;
-				if (cmd == "f") {
+				
+				if( cmd == "f" )
 					type = PrimitiveCategory::Filename;
-				} elif (cmd == "t") {
+				elif( cmd == "t" )
 					type = PrimitiveCategory::Title;
-				} else
+				else
 					continue;
 				
-				QRegExp regex (line.mid (colon + 1));
+				QRegExp regex( line.mid( colon + 1 ));
 				PrimitiveCategory::RegexEntry entry = { regex, type };
 				cat.regexes << entry;
 			}
 		}
 		
-		if (cat.regexes.size () > 0)
+		if( cat.regexes.size() > 0 )
 			g_PrimitiveCategories << cat;
 	}
 	
@@ -285,106 +314,108 @@
 	
 	for( int i = 0; i < segs; ++i )
 	{
-		double x0 = cos(( i * 2 * pi ) / divs ),
-			x1 = cos((( i + 1 ) * 2 * pi) / divs ),
-			z0 = sin(( i * 2 * pi ) / divs ),
-			z1 = sin((( i + 1 ) * 2 * pi ) / divs );
+		double x0 = cos( ( i * 2 * pi ) / divs ),
+			x1 = cos( ( ( i + 1 ) * 2 * pi ) / divs ),
+			z0 = sin( ( i * 2 * pi ) / divs ),
+			z1 = sin( ( ( i + 1 ) * 2 * pi ) / divs );
 		
 		LDObject* obj = null;
 		
 		switch( type )
 		{
 		case Circle:
-			{
-				vertex v0( x0, 0.0f, z0 ),
-					v1( x1, 0.0f, z1 );
-				
-				LDLine* line = new LDLine;
-				line->setVertex( 0, v0 );
-				line->setVertex( 1, v1 );
-				line->setColor( edgecolor );
-				obj = line;
-			}
-			break;
+		{
+			vertex v0( x0, 0.0f, z0 ),
+				   v1( x1, 0.0f, z1 );
+			
+			LDLine* line = new LDLine;
+			line->setVertex( 0, v0 );
+			line->setVertex( 1, v1 );
+			line->setColor( edgecolor );
+			obj = line;
+		}
+		break;
 		
 		case Cylinder:
 		case Ring:
 		case Cone:
+		{
+			double x2, x3, z2, z3;
+			double y0, y1, y2, y3;
+			
+			if( type == Cylinder )
 			{
-				double x2, x3, z2, z3;
-				double y0, y1, y2, y3;
+				x2 = x1;
+				x3 = x0;
+				z2 = z1;
+				z3 = z0;
 				
-				if( type == Cylinder )
+				y0 = y1 = 0.0f;
+				y2 = y3 = 1.0f;
+			}
+			else
+			{
+				x2 = x1 * ( num + 1 );
+				x3 = x0 * ( num + 1 );
+				z2 = z1 * ( num + 1 );
+				z3 = z0 * ( num + 1 );
+				
+				x0 *= num;
+				x1 *= num;
+				z0 *= num;
+				z1 *= num;
+				
+				if( type == Ring )
+					y0 = y1 = y2 = y3 = 0.0f;
+				else
 				{
-					x2 = x1;
-					x3 = x0;
-					z2 = z1;
-					z3 = z0;
-					
-					y0 = y1 = 0.0f;
-					y2 = y3 = 1.0f;
-				} else {
-					x2 = x1 * (num + 1);
-					x3 = x0 * (num + 1);
-					z2 = z1 * (num + 1);
-					z3 = z0 * (num + 1);
-					
-					x0 *= num;
-					x1 *= num;
-					z0 *= num;
-					z1 *= num;
-					
-					if( type == Ring )
-						y0 = y1 = y2 = y3 = 0.0f;
-					else
-					{
-						y0 = y1 = 1.0f;
-						y2 = y3 = 0.0f;
-					} 
+					y0 = y1 = 1.0f;
+					y2 = y3 = 0.0f;
 				}
-				
-				vertex v0( x0, y0, z0 ),
-					v1( x1, y1, z1 ),
-					v2( x2, y2, z2 ),
-					v3( x3, y3, z3 );
-				
-				LDQuad* quad = new LDQuad;
-				quad->setColor( maincolor );
-				quad->setVertex( 0, v0 );
-				quad->setVertex( 1, v1 );
-				quad->setVertex( 2, v2 );
-				quad->setVertex( 3, v3 );
-				obj = quad;
 			}
-			break;
+			
+			vertex v0( x0, y0, z0 ),
+				   v1( x1, y1, z1 ),
+				   v2( x2, y2, z2 ),
+				   v3( x3, y3, z3 );
+			
+			LDQuad* quad = new LDQuad;
+			quad->setColor( maincolor );
+			quad->setVertex( 0, v0 );
+			quad->setVertex( 1, v1 );
+			quad->setVertex( 2, v2 );
+			quad->setVertex( 3, v3 );
+			obj = quad;
+		}
+		break;
 		
 		case Disc:
 		case DiscNeg:
+		{
+			double x2, z2;
+			
+			if( type == Disc )
+				x2 = z2 = 0.0f;
+			else
 			{
-				double x2, z2;
-				
-				if( type == Disc )
-					x2 = z2 = 0.0f;
-				else
-				{
-					x2 = ( x0 >= 0.0f ) ? 1.0f : -1.0f;
-					z2 = ( z0 >= 0.0f ) ? 1.0f : -1.0f;
-				}
-				
-				vertex v0( x0, 0.0f, z0 ),
-					v1( x1, 0.0f, z1 ),
-					v2( x2, 0.0f, z2 );
-				
-				// Disc negatives need to go the other way around, otherwise
-				// they'll end up upside-down.
-				LDTriangle* seg = new LDTriangle;
-				seg->setColor( maincolor );
-				seg->setVertex( type == Disc ? 0 : 2, v0 );
-				seg->setVertex( 1, v1 );
-				seg->setVertex( type == Disc ? 2 : 0, v2 );
-				obj = seg;
+				x2 = ( x0 >= 0.0f ) ? 1.0f : -1.0f;
+				z2 = ( z0 >= 0.0f ) ? 1.0f : -1.0f;
 			}
-			break;
+			
+			vertex v0( x0, 0.0f, z0 ),
+				   v1( x1, 0.0f, z1 ),
+				   v2( x2, 0.0f, z2 );
+			
+			// Disc negatives need to go the other way around, otherwise
+			// they'll end up upside-down.
+			LDTriangle* seg = new LDTriangle;
+			seg->setColor( maincolor );
+			seg->setVertex( type == Disc ? 0 : 2, v0 );
+			seg->setVertex( 1, v1 );
+			seg->setVertex( type == Disc ? 2 : 0, v2 );
+			obj = seg;
+		}
+		break;
 		
 		default:
 			break;
@@ -405,10 +436,11 @@
 	       type == Disc     ? "Disc" :
 	       type == DiscNeg  ? "Disc Negative" :
 	       type == Ring     ? "Ring" :
-	                          "Cone";
+	       "Cone";
 }
 
-static const str g_radialNameRoots[] = {
+static const str g_radialNameRoots[] =
+{
 	"edge",
 	"cyli",
 	"disc",
@@ -437,14 +469,14 @@
 	}
 	
 	// Compose some general information: prefix, fraction, root, ring number
-	str prefix = (divs == lores) ? "" : fmt( "%1/", divs );
+	str prefix = ( divs == lores ) ? "" : fmt( "%1/", divs );
 	str frac = fmt( "%1-%2", numer, denom );
 	str root = g_radialNameRoots[type];
-	str numstr = ( type == Ring || type == Cone ) ? fmt ( "%1", num ) : "";
+	str numstr = ( type == Ring || type == Cone ) ? fmt( "%1", num ) : "";
 	
 	// Truncate the root if necessary (7-16rin4.dat for instance).
 	// However, always keep the root at least 2 characters.
-	int extra = ( frac.length() + numstr.length() + root.length() ) - 8;
+	int extra = ( frac.length() + numstr.length() + root.length()) - 8;
 	root.chop( min<short>( max<short>( extra, 0 ), 2 ));
 	
 	// Stick them all together and return the result.
@@ -471,11 +503,10 @@
 		ui.rb_cylinder->isChecked() ? Cylinder :
 		ui.rb_disc->isChecked()     ? Disc :
 		ui.rb_ndisc->isChecked()    ? DiscNeg :
-		ui.rb_ring->isChecked()     ? Ring :
-		                              Cone;
+		ui.rb_ring->isChecked()     ? Ring : Cone;
 	
 	// Make the description
-	str frac = ftoa(( (float) segs ) / divs );
+	str frac = ftoa( ( ( float ) segs ) / divs );
 	str name = radialFileName( type, segs, divs, num );
 	str descr;
 	
@@ -483,7 +514,7 @@
 	if( frac.indexOf( "." ) == -1 )
 		frac += ".0";
 	
-	if (type == Ring || type == Cone)
+	if( type == Ring || type == Cone )
 		descr = fmt( "%1 %2 x %3", primitiveTypeName( type ), num, frac );
 	else
 		descr = fmt( "%1 %2", primitiveTypeName( type ), frac );
@@ -503,4 +534,4 @@
 	
 	g_win->save( f, false );
 	delete f;
-}
\ No newline at end of file
+}
--- a/src/types.cpp	Sun Jul 07 15:08:38 2013 +0300
+++ b/src/types.cpp	Sun Jul 07 16:46:30 2013 +0300
@@ -1,17 +1,17 @@
 /*
  *  LDForge: LDraw parts authoring CAD
  *  Copyright (C) 2013 Santeri 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/>.
  */
@@ -27,252 +27,291 @@
 
 const File nullfile;
 
-str DoFormat (vector<StringFormatArg> args) {
-	assert (args.size () >= 1);
-	str text = args[0].value ();
+str DoFormat( vector<StringFormatArg> args )
+{
+	assert( args.size() >= 1 );
+	str text = args[0].value();
 	
-	for (uchar i = 1; i < args.size (); ++i)
-		text = text.arg (args[i].value ());
+	for( uchar i = 1; i < args.size(); ++i )
+		text = text.arg( args[i].value() );
 	
 	return text;
 }
 
-vertex::vertex (double x, double y, double z) {
+vertex::vertex( double x, double y, double z )
+{
 	m_coords[X] = x;
 	m_coords[Y] = y;
 	m_coords[Z] = z;
 }
 
 // =============================================================================
-void vertex::move (const vertex& other) {
-	for (const Axis ax : g_Axes)
+void vertex::move( const vertex& other )
+{
+	for( const Axis ax : g_Axes )
 		m_coords[ax] += other[ax];
 }
 
 // =============================================================================
-vertex vertex::midpoint (const vertex& other) {
+vertex vertex::midpoint( const vertex& other )
+{
 	vertex mid;
 	
-	for (const Axis ax : g_Axes)
-		mid[ax] = (m_coords[ax] + other[ax]) / 2;
+	for( const Axis ax : g_Axes )
+		mid[ax] = ( m_coords[ax] + other[ax] ) / 2;
 	
 	return mid;
 }
 
 // =============================================================================
-str vertex::stringRep (bool mangled) const {
-	if (mangled)
-		return (str ("(") +
-		ftoa (coord (X)) + ", " +
-		ftoa (coord (Y)) + ", " +
-		ftoa (coord (Z)) + ")");
+str vertex::stringRep( bool mangled ) const
+{
+	str fmtstr = "%1 %2 %3";
+	if( mangled )
+		fmtstr = "(%1, %2, %3)";
 	
-	return QStringList ({ftoa (coord (X)), ftoa (coord (Y)),
-		ftoa (coord (Z))}).join (" ");
+	return fmt( fmtstr, coord( X ), coord( Y ), coord( Z ));
 }
 
 // =============================================================================
-void vertex::transform (matrix matr, vertex pos) {
-	double x2 = (matr[0] * x ()) + (matr[1] * y ()) + (matr[2] * z ()) + pos[X];
-	double y2 = (matr[3] * x ()) + (matr[4] * y ()) + (matr[5] * z ()) + pos[Y];
-	double z2 = (matr[6] * x ()) + (matr[7] * y ()) + (matr[8] * z ()) + pos[Z];
+void vertex::transform( matrix matr, vertex pos )
+{
+	double x2 = ( matr[0] * x()) + ( matr[1] * y()) + ( matr[2] * z()) + pos[X];
+	double y2 = ( matr[3] * x()) + ( matr[4] * y()) + ( matr[5] * z()) + pos[Y];
+	double z2 = ( matr[6] * x()) + ( matr[7] * y()) + ( matr[8] * z()) + pos[Z];
 	
-	x () = x2;
-	y () = y2;
-	z () = z2;
+	x() = x2;
+	y() = y2;
+	z() = z2;
 }
 
-vertex vertex::operator-() const {
-	return vertex (-m_coords[X], -m_coords[Y], -m_coords[Z]);
+vertex vertex::operator-() const
+{
+	return vertex( -m_coords[X], -m_coords[Y], -m_coords[Z] );
 }
 
-bool vertex::operator!= (const vertex& other) const {
-	return !operator== (other);
+bool vertex::operator!= ( const vertex& other ) const
+{
+	return !operator== ( other );
+}
+
+double& vertex::operator[]( const Axis ax )
+{
+	return coord( ( ushort ) ax );
 }
 
-double& vertex::operator[] (const Axis ax) {
-	return coord ((ushort) ax);
+const double& vertex::operator[]( const Axis ax ) const
+{
+	return coord( ( ushort ) ax );
 }
 
-const double& vertex::operator[] (const Axis ax) const {
-	return coord ((ushort) ax);
-}
-
-double& vertex::operator[] (const int ax) {
-	return coord (ax);
+double& vertex::operator[]( const int ax )
+{
+	return coord( ax );
 }
 
-const double& vertex::operator[] (const int ax) const {
-	return coord (ax);
+const double& vertex::operator[]( const int ax ) const
+{
+	return coord( ax );
 }
 
-bool vertex::operator== (const vertex& other) const {
-	return coord (X) == other[X] &&
-		coord (Y) == other[Y] &&
-		coord (Z) == other[Z];
+bool vertex::operator== ( const vertex& other ) const
+{
+	return coord( X ) == other[X] &&
+	       coord( Y ) == other[Y] &&
+	       coord( Z ) == other[Z];
 }
 
-vertex& vertex::operator/= (const double d) {
-	for (const Axis ax : g_Axes)
+vertex& vertex::operator/= ( const double d )
+{
+	for( const Axis ax : g_Axes )
 		m_coords[ax] /= d;
 	
 	return *this;
 }
 
-vertex vertex::operator/ (const double d) const {
-	vertex other (*this);
+vertex vertex::operator/ ( const double d ) const
+{
+	vertex other( *this );
 	return other /= d;
 }
 
-vertex& vertex::operator+= (const vertex& other) {
-	move (other);
+vertex& vertex::operator+= ( const vertex& other )
+{
+	move( other );
 	return *this;
 }
 
-vertex vertex::operator+ (const vertex& other) const {
-	vertex newvert (*this);
-	newvert.move (other);
+vertex vertex::operator+ ( const vertex& other ) const
+{
+	vertex newvert( *this );
+	newvert.move( other );
 	return newvert;
 }
 
-int vertex::operator< (const vertex& other) const {
-	if (operator== (other))
+int vertex::operator< ( const vertex& other ) const
+{
+	if( operator==( other ))
 		return false;
 	
-	if (coord (X) < other[X])
+	if( coord( X ) < other[X] )
 		return true;
 	
-	if (coord (X) > other[X])
+	if( coord( X ) > other[X] )
 		return false;
 	
-	if (coord (Y) < other[Y])
+	if( coord( Y ) < other[Y] )
 		return true;
 	
-	if (coord (Y) > other[Y])
+	if( coord( Y ) > other[Y] )
 		return false;
 	
-	return coord (Z) < other[Z];
+	return coord( Z ) < other[Z];
 }
 
 // =============================================================================
-matrix::matrix (double vals[]) {
-	for (short i = 0; i < 9; ++i)
+matrix::matrix( double vals[] )
+{
+	for( short i = 0; i < 9; ++i )
 		m_vals[i] = vals[i];
 }
 
-matrix::matrix (double fillval) {
-	for (short i = 0; i < 9; ++i)
+matrix::matrix( double fillval )
+{
+	for( short i = 0; i < 9; ++i )
 		m_vals[i] = fillval;
 }
 
-matrix::matrix (initlist<double> vals) {
-	assert (vals.size() == 9);
-	memcpy (&m_vals[0], &(*vals.begin ()), sizeof m_vals);
+matrix::matrix( initlist<double> vals )
+{
+	assert( vals.size() == 9 );
+	memcpy( &m_vals[0], &( *vals.begin() ), sizeof m_vals );
 }
-void matrix::puts () const {
-	for (short i = 0; i < 3; ++i) {
-		for (short j = 0; j < 3; ++j)
-			printf ("%*f\t", 10, m_vals[(i * 3) + j]);
+
+void matrix::puts() const
+{
+	for( short i = 0; i < 3; ++i )
+	{
+		for( short j = 0; j < 3; ++j )
+			print( "%1\t", m_vals[( i * 3 ) + j] );
 		
-		printf ("\n");
+		print( "\n" );
 	}
 }
 
 // =============================================================================
-str matrix::stringRep () const {
+str matrix::stringRep() const
+{
 	str val;
-	for (short i = 0; i < 9; ++i) {
-		if (i > 0)
+	
+	for( short i = 0; i < 9; ++i )
+	{
+		if( i > 0 )
 			val += ' ';
 		
-		val += ftoa (m_vals[i]);
+		val += ftoa( m_vals[i] );
 	}
 	
 	return val;
 }
 
 // =============================================================================
-void matrix::zero () {
-	memset (&m_vals[0], 0, sizeof (double) * 9);
+void matrix::zero()
+{
+	memset( &m_vals[0], 0, sizeof( double ) * 9 );
 }
 
 // =============================================================================
-matrix matrix::mult (matrix other) const {
+matrix matrix::mult( matrix other ) const
+{
 	matrix val;
-	val.zero ();
+	val.zero();
 	
-	for (short i = 0; i < 3; ++i)
-	for (short j = 0; j < 3; ++j)
-	for (short k = 0; k < 3; ++k)
-		val[(i * 3) + j] += m_vals[(i * 3) + k] * other[(k * 3) + j];
-	
+	for( short i = 0; i < 3; ++i )
+	for( short j = 0; j < 3; ++j )
+	for( short k = 0; k < 3; ++k )
+		val[( i * 3 ) + j] += m_vals[( i * 3 ) + k] * other[( k * 3 ) + j];
+
 	return val;
 }
 
 // =============================================================================
-matrix& matrix::operator= (matrix other) {
-	 memcpy (&m_vals[0], &other.m_vals[0], sizeof (double) * 9);
-	 return *this;
+matrix& matrix::operator= ( matrix other )
+{
+	memcpy( &m_vals[0], &other.m_vals[0], sizeof( double ) * 9 );
+	return *this;
+}
+
+// =============================================================================
+double matrix::determinant() const
+{
+	return ( val( 0 ) * val( 4 ) * val( 8 )) +
+	       ( val( 1 ) * val( 5 ) * val( 6 )) +
+	       ( val( 2 ) * val( 3 ) * val( 7 )) -
+	       ( val( 2 ) * val( 4 ) * val( 6 )) -
+	       ( val( 1 ) * val( 3 ) * val( 8 )) -
+	       ( val( 0 ) * val( 5 ) * val( 7 ));
 }
 
 // =============================================================================
-double matrix::determinant () const {
-	return
-		(val (0) * val (4) * val (8)) +
-		(val (1) * val (5) * val (6)) +
-		(val (2) * val (3) * val (7)) -
-		(val (2) * val (4) * val (6)) -
-		(val (1) * val (3) * val (8)) -
-		(val (0) * val (5) * val (7));
-}
-
-// =============================================================================
-StringFormatArg::StringFormatArg (const str& v) {
+StringFormatArg::StringFormatArg( const str& v )
+{
 	m_val = v;
 }
 
-StringFormatArg::StringFormatArg (const char& v) {
+StringFormatArg::StringFormatArg( const char& v )
+{
 	m_val = v;
 }
 
-StringFormatArg::StringFormatArg (const uchar& v) {
+StringFormatArg::StringFormatArg( const uchar& v )
+{
+	m_val = v;
+}
+
+StringFormatArg::StringFormatArg( const qchar& v )
+{
 	m_val = v;
 }
 
-StringFormatArg::StringFormatArg (const qchar& v) {
+StringFormatArg::StringFormatArg( const float& v )
+{
+	m_val = ftoa( v );
+}
+
+StringFormatArg::StringFormatArg( const double& v )
+{
+	m_val = ftoa( v );
+}
+
+StringFormatArg::StringFormatArg( const vertex& v )
+{
+	m_val = v.stringRep( false );
+}
+
+StringFormatArg::StringFormatArg( const matrix& v )
+{
+	m_val = v.stringRep();
+}
+
+StringFormatArg::StringFormatArg( const char* v )
+{
 	m_val = v;
 }
 
-StringFormatArg::StringFormatArg (const float& v) {
-	m_val = ftoa (v);
-}
-
-StringFormatArg::StringFormatArg (const double& v) {
-	m_val = ftoa (v);
-}
-
-StringFormatArg::StringFormatArg (const vertex& v) {
-	m_val = v.stringRep (false);
-}
-
-StringFormatArg::StringFormatArg (const matrix& v) {
-	m_val = v.stringRep ();
-}
-
-StringFormatArg::StringFormatArg (const char* v) {
-	m_val = v;
-}
-
-StringFormatArg::StringFormatArg (const strconfig& v) {
+StringFormatArg::StringFormatArg( const strconfig& v )
+{
 	m_val = v.value;
 }
 
-StringFormatArg::StringFormatArg (const intconfig& v) {
-	m_val.number (v.value);
+StringFormatArg::StringFormatArg( const intconfig& v )
+{
+	m_val.number( v.value );
 }
 
-StringFormatArg::StringFormatArg (const floatconfig& v) {
-	m_val.number (v.value);
+StringFormatArg::StringFormatArg( const floatconfig& v )
+{
+	m_val.number( v.value );
 }
 
 StringFormatArg::StringFormatArg( const void* v )
@@ -281,58 +320,65 @@
 }
 
 // =============================================================================
-File::File () {
+File::File()
+{
 	// Make a null file
 	m_file = null;
 	m_textstream = null;
 }
 
-File::File (str path, OpenType rtype) {
+File::File( str path, OpenType rtype )
+{
 	m_file = null;
-	open (path, rtype);
+	open( path, rtype );
 }
 
-File::File (FILE* fp, OpenType rtype) {
+File::File( FILE* fp, OpenType rtype )
+{
 	m_file = null;
-	open (fp, rtype);
+	open( fp, rtype );
 }
 
-File::~File () {
-	if (m_file) {
-		m_file->close ();
+File::~File()
+{
+	if( m_file )
+	{
+		m_file->close();
 		delete m_file;
 		
-		if (m_textstream)
+		if( m_textstream )
 			delete m_textstream;
 	}
 }
 
-bool File::open (FILE* fp, OpenType rtype) {
-	return open ("", rtype, fp);
+bool File::open( FILE* fp, OpenType rtype )
+{
+	return open( "", rtype, fp );
 }
 
-bool File::open (str path, OpenType rtype, FILE* fp) {
-	close ();
+bool File::open( str path, OpenType rtype, FILE* fp )
+{
+	close();
 	
-	if (!m_file)
+	if( !m_file )
 		m_file = new QFile;
 	
-	m_file->setFileName (path);
+	m_file->setFileName( path );
 	
 	bool result;
 	
 	QIODevice::OpenMode mode =
-		(rtype == Read) ? QIODevice::ReadOnly :
-		(rtype == Write) ? QIODevice::WriteOnly :
-		QIODevice::Append;
+		( rtype == Read ) ? QIODevice::ReadOnly :
+		( rtype == Write ) ? QIODevice::WriteOnly : QIODevice::Append;
 	
-	if (fp)
-		result = m_file->open (fp, mode);
+	if( fp )
+		result = m_file->open( fp, mode );
 	else
-		result = m_file->open (mode);
+		result = m_file->open( mode );
 	
-	if (result) {
-		m_textstream = new QTextStream (m_file);
+	if( result )
+	{
+		m_textstream = new QTextStream( m_file );
 		return true;
 	}
 	
@@ -341,83 +387,100 @@
 	return false;
 }
 
-File::iterator File::begin() {
-	return iterator (this);
+File::iterator File::begin()
+{
+	return iterator( this );
 }
 
-File::iterator& File::end () {
+File::iterator& File::end()
+{
 	return m_endIterator;
 }
 
-void File::write (str msg) {
-	m_file->write (msg.toUtf8 (), msg.length ());
+void File::write( str msg )
+{
+	m_file->write( msg.toUtf8(), msg.length() );
 }
 
-bool File::readLine (str& line) {
-	if (!m_textstream || m_textstream->atEnd ())
+bool File::readLine( str& line )
+{
+	if( !m_textstream || m_textstream->atEnd() )
 		return false;
 	
-	line = m_textstream->readLine ();
+	line = m_textstream->readLine();
 	return true;
 }
 
-bool File::atEnd () const {
-	if (!m_textstream)
-		fatal ("cannot use atEnd on a null file");
+bool File::atEnd() const
+{
+	if( !m_textstream )
+		fatal( "cannot use atEnd on a null file" );
 	
-	return m_textstream->atEnd ();
+	return m_textstream->atEnd();
 }
 
-bool File::isNull () const {
+bool File::isNull() const
+{
 	return m_file == null;
 }
 
-bool File::operator!() const {
-	return isNull ();
+bool File::operator!() const
+{
+	return isNull();
 }
 
-void File::close () {
-	if (!m_file)
+void File::close()
+{
+	if( !m_file )
 		return;
 	
 	delete m_file;
 	m_file = null;
 	
-	if (m_textstream) {
+	if( m_textstream )
+	{
 		delete m_textstream;
 		m_textstream = null;
 	}
 }
 
-bool File::flush () {
-	return m_file->flush ();
+bool File::flush()
+{
+	return m_file->flush();
 }
 
-File::operator bool () const {
-	return !isNull ();
+File::operator bool () const
+{
+	return !isNull();
 }
 
-void File::rewind () {
-	m_file->seek (0);
+void File::rewind()
+{
+	m_file->seek( 0 );
 }
 
-File::iterator::iterator (File* f) : m_file (f) {
+File::iterator::iterator( File* f ) : m_file( f )
+{
 	operator++ ();
 }
 
-void File::iterator::operator++ () {
-	m_gotdata = m_file->readLine (m_text);
+void File::iterator::operator++ ()
+{
+	m_gotdata = m_file->readLine( m_text );
 }
 
-str File::iterator::operator* () {
+str File::iterator::operator* ()
+{
 	return m_text;
 }
 
 // The prime contestant for the weirdest operator== 2013 award?
-bool File::iterator::operator== (File::iterator& other) {
-	return (other.m_file == null && !m_gotdata);
+bool File::iterator::operator== ( File::iterator& other )
+{
+	return ( other.m_file == null && !m_gotdata );
 }
 
-bool File::iterator::operator!= (File::iterator& other) {
-	return !operator== (other);
-}
\ No newline at end of file
+bool File::iterator::operator!= ( File::iterator& other )
+{
+	return !operator== ( other );
+}

mercurial