Moved the bbox class to types

Mon, 15 Jul 2013 13:52:46 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 15 Jul 2013 13:52:46 +0300
changeset 380
e442d9b7c251
parent 379
f5f3faac60cd
child 381
241f65769a57

Moved the bbox class to types

src/bbox.cpp file | annotate | diff | comparison | revisions
src/bbox.h file | annotate | diff | comparison | revisions
src/types.cpp file | annotate | diff | comparison | revisions
src/types.h file | annotate | diff | comparison | revisions
--- a/src/bbox.cpp	Mon Jul 15 13:50:12 2013 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- *  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/>.
- */
-
-#include "common.h"
-#include "bbox.h"
-#include "ldtypes.h"
-#include "file.h"
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-bbox::bbox()
-{
-	reset();
-}
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-void bbox::calculate()
-{
-	reset();
-	
-	if( !currentFile() )
-		return;
-	
-	for( LDObject* obj : currentFile()->objs() )
-		calcObject( obj );
-}
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-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 ) );
-		
-		break;
-
-	case LDObject::Subfile:
-		{
-			LDSubfileObject* ref = static_cast<LDSubfileObject*>( obj );
-			vector<LDObject*> objs = ref->inlineContents( true, true );
-			
-			for( LDObject * obj : objs )
-			{
-				calcObject( obj );
-				delete obj;
-			}
-		}
-		break;
-
-	default:
-		break;
-	}
-}
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-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] )
-			m_v1[ax] = v[ax];
-	}
-	
-	m_empty = false;
-}
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-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;
-}
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-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( xscale > yscale )
-	{
-		if( xscale > zscale )
-			size = xscale;
-	}
-	elif( yscale > zscale )
-		size = yscale;
-	
-	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 );
-}
--- a/src/bbox.h	Mon Jul 15 13:50:12 2013 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- *  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/>.
- */
-
-#ifndef BBOX_H
-#define BBOX_H
-
-#include "common.h"
-#include "types.h"
-
-// =============================================================================
-// bbox
-//
-// The bounding box is the box that encompasses a given set of objects. The
-// global instance g_BBox is the bbox for the model we have open.
-// v0 is the minimum vertex, v1 is the maximum vertex.
-// =============================================================================
-class bbox
-{
-	READ_PROPERTY( bool, empty, setEmpty )
-	READ_PROPERTY( vertex, v0, setV0 )
-	READ_PROPERTY( vertex, v1, setV1 )
-	
-public:
-	bbox();
-	void reset();
-	void calculate();
-	double size() const;
-	void calcObject( LDObject* obj );
-	void calcVertex( const vertex& v );
-	vertex center() const;
-	
-	bbox& operator<< ( LDObject* obj )
-	{
-		calcObject( obj );
-		return *this;
-	}
-	
-	bbox& operator<< ( const vertex& v )
-	{
-		calcVertex( v );
-		return *this;
-	}
-};
-
-#endif // BBOX_H
--- a/src/types.cpp	Mon Jul 15 13:50:12 2013 +0300
+++ b/src/types.cpp	Mon Jul 15 13:52:46 2013 +0300
@@ -25,8 +25,6 @@
 #include "types.h"
 #include "misc.h"
 
-const File nullfile;
-
 str DoFormat( vector<StringFormatArg> args )
 {
 	assert( args.size() >= 1 );
@@ -484,3 +482,107 @@
 {
 	return !operator== ( other );
 }
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+bbox::bbox() {
+	reset();
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+void bbox::calculate() {
+	reset();
+	
+	if (!currentFile())
+		return;
+	
+	for (LDObject* obj : currentFile()->objs())
+		calcObject (obj);
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+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));
+		
+		break;
+
+	case LDObject::Subfile: {
+		LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj);
+		vector<LDObject*> objs = ref->inlineContents (true, true);
+	
+		for (LDObject* obj : objs) {
+			calcObject (obj);
+			delete obj;
+		}
+	}
+	break;
+	
+	default:
+		break;
+	}
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+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])
+			m_v1[ax] = v[ax];
+	}
+	
+	m_empty = false;
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+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;
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+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 (xscale > yscale) {
+		if (xscale > zscale)
+			size = xscale;
+	} elif (yscale > zscale)
+		size = yscale;
+	
+	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
--- a/src/types.h	Mon Jul 15 13:50:12 2013 +0300
+++ b/src/types.h	Mon Jul 15 13:52:46 2013 +0300
@@ -466,7 +466,35 @@
 	iterator     m_endIterator;
 };
 
-// Null-file, equivalent to a null FILE*
-extern const File nullfile;
+// =============================================================================
+// bbox
+//
+// The bounding box is the box that encompasses a given set of objects.
+// v0 is the minimum vertex, v1 is the maximum vertex.
+// =============================================================================
+class bbox {
+	READ_PROPERTY (bool, empty, setEmpty)
+	READ_PROPERTY (vertex, v0, setV0)
+	READ_PROPERTY (vertex, v1, setV1)
+	
+public:
+	bbox();
+	void reset();
+	void calculate();
+	double size() const;
+	void calcObject (LDObject* obj);
+	void calcVertex (const vertex& v);
+	vertex center() const;
+	
+	bbox& operator<< (LDObject* obj) {
+		calcObject (obj);
+		return *this;
+	}
+	
+	bbox& operator<< (const vertex& v) {
+		calcVertex (v);
+		return *this;
+	}
+};
 
 #endif // TYPES_H

mercurial