src/bbox.cpp

changeset 359
bcdfc801658b
parent 319
d0f41342ef51
child 377
271d1da66b7e
--- a/src/bbox.cpp	Sun Jul 07 16:46:30 2013 +0300
+++ b/src/bbox.cpp	Sun Jul 07 17:45:48 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/>.
  */
@@ -24,48 +24,54 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-bbox::bbox () {
-	reset ();
+bbox::bbox()
+{
+	reset();
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::calculate () {
-	reset ();
+void bbox::calculate()
+{
+	reset();
 	
-	if (!g_curfile)
+	if( !g_curfile )
 		return;
 	
-	for (LDObject* obj : g_curfile->objs ())
-		calcObject (obj);
+	for( LDObject* obj : g_curfile->objs() )
+		calcObject( obj );
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::calcObject (LDObject* obj) {
-	switch (obj->getType ()) {
+void bbox::calcObject( LDObject* obj )
+{
+	switch( obj->getType() )
+	{
 	case LDObject::Line:
 	case LDObject::Triangle:
 	case LDObject::Quad:
 	case LDObject::CondLine:
-		for (short i = 0; i < obj->vertices (); ++i)
-			calcVertex (obj->getVertex (i));
+		for( short i = 0; i < obj->vertices(); ++i )
+			calcVertex( obj->getVertex( i ) );
+		
 		break;
-	
+
 	case LDObject::Subfile:
 		{
-			LDSubfile* ref = static_cast<LDSubfile*> (obj);
-			vector<LDObject*> objs = ref->inlineContents (true, true);
+			LDSubfile* ref = static_cast<LDSubfile*>( obj );
+			vector<LDObject*> objs = ref->inlineContents( true, true );
 			
-			for (LDObject* obj : objs) {
-				calcObject (obj);
+			for( LDObject * obj : objs )
+			{
+				calcObject( obj );
 				delete obj;
 			}
 		}
 		break;
-	
+
 	default:
 		break;
 	}
@@ -74,12 +80,14 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::calcVertex (const vertex& v) {
-	for (const Axis ax : g_Axes) {
-		if (v[ax] < m_v0[ax])
+void bbox::calcVertex( const vertex& v )
+{
+	for( const Axis ax : g_Axes )
+	{
+		if( v[ax] < m_v0[ax] )
 			m_v0[ax] = v[ax];
 		
-		if (v[ax] > m_v1[ax])
+		if( v[ax] > m_v1[ax] )
 			m_v1[ax] = v[ax];
 	}
 	
@@ -89,9 +97,10 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void bbox::reset () {
-	m_v0[X] = m_v0[Y] = m_v0[Z] = +0x7FFFFFFF;
-	m_v1[X] = m_v1[Y] = m_v1[Z] = -0x7FFFFFFF;
+void bbox::reset()
+{
+	m_v0[X] = m_v0[Y] = m_v0[Z] = 0x7FFFFFFF;
+	m_v1[X] = m_v1[Y] = m_v1[Z] = 0xFFFFFFFF;
 	
 	m_empty = true;
 }
@@ -99,28 +108,32 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-double bbox::size () const {
-	double fXScale = (m_v0[X] - m_v1[X]);
-	double fYScale = (m_v0[Y] - m_v1[Y]);
-	double fZScale = (m_v0[Z] - m_v1[Z]);
-	double fSize = fZScale;
+double bbox::size() const
+{
+	double xscale = ( m_v0[X] - m_v1[X] );
+	double yscale = ( m_v0[Y] - m_v1[Y] );
+	double zscale = ( m_v0[Z] - m_v1[Z] );
+	double size = zscale;
 	
-	if (fXScale > fYScale) {
-		if (fXScale > fZScale)
-			fSize = fXScale;
-	} elif (fYScale > fZScale)
-		fSize = fYScale;
+	if( xscale > yscale )
+	{
+		if( xscale > zscale )
+			size = xscale;
+	}
+	elif( yscale > zscale )
+		size = yscale;
 	
-	if (abs (fSize) >= 2.0f)
-		return abs (fSize / 2);
+	if( abs( size ) >= 2.0f )
+		return abs( size / 2 );
 	
 	return 1.0f;
 }
 
 // =============================================================================
-vertex bbox::center () const {
-	return vertex (
-		(m_v0[X] + m_v1[X]) / 2,
-		(m_v0[Y] + m_v1[Y]) / 2,
-		(m_v0[Z] + m_v1[Z]) / 2);
-}
\ No newline at end of file
+vertex bbox::center() const
+{
+	return vertex(
+		( m_v0[X] + m_v1[X] ) / 2,
+		( m_v0[Y] + m_v1[Y] ) / 2,
+		( m_v0[Z] + m_v1[Z] ) / 2 );
+}

mercurial