PageRenderTime 57ms CodeModel.GetById 7ms app.highlight 46ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmath/tests/llbboxlocal_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 232 lines | 116 code | 48 blank | 68 comment | 0 complexity | cbd412e3abeedd25da83afde3490d774 MD5 | raw file
  1/**
  2 * @file   llbboxlocal_test.cpp
  3 * @author Martin Reddy
  4 * @date   2009-06-25
  5 * @brief  Test for llbboxlocal.cpp.
  6 * 
  7 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "linden_common.h"
 30#include "../test/lltut.h"
 31#include "../llbboxlocal.h"
 32
 33namespace tut
 34{
 35	struct LLBBoxLocalData
 36	{
 37	};
 38
 39	typedef test_group<LLBBoxLocalData> factory;
 40	typedef factory::object object;
 41}
 42
 43namespace
 44{
 45	tut::factory llbboxlocal_test_factory("LLBBoxLocal");
 46}
 47
 48namespace tut
 49{
 50	template<> template<>
 51	void object::test<1>()
 52	{	
 53		//
 54		// test the default constructor
 55		//
 56		
 57		LLBBoxLocal bbox1;
 58		
 59		ensure_equals("Default bbox min", bbox1.getMin(), LLVector3(0.0f, 0.0f, 0.0f));
 60		ensure_equals("Default bbox max", bbox1.getMax(), LLVector3(0.0f, 0.0f, 0.0f));
 61	}
 62
 63	template<> template<>
 64	void object::test<2>()
 65	{	
 66		//
 67		// test the non-default constructor
 68		//
 69		
 70		LLBBoxLocal bbox2(LLVector3(-1.0f, -2.0f, 0.0f), LLVector3(1.0f, 2.0f, 3.0f));
 71		
 72		ensure_equals("Custom bbox min", bbox2.getMin(), LLVector3(-1.0f, -2.0f, 0.0f));
 73		ensure_equals("Custom bbox max", bbox2.getMax(), LLVector3(1.0f, 2.0f, 3.0f));		
 74	}
 75	
 76	template<> template<>
 77	void object::test<3>()
 78	{	
 79		//
 80		// test the setMin()
 81		//
 82		// N.B. no validation is currently performed to ensure that the min
 83		// and max vectors are actually the min/max values.
 84		//
 85		
 86		LLBBoxLocal bbox2;
 87		bbox2.setMin(LLVector3(1.0f, 2.0f, 3.0f));
 88		
 89		ensure_equals("Custom bbox min (2)", bbox2.getMin(), LLVector3(1.0f, 2.0f, 3.0f));
 90	}
 91	
 92	template<> template<>
 93	void object::test<4>()
 94	{	
 95		//
 96		// test the setMax()
 97		//
 98		// N.B. no validation is currently performed to ensure that the min
 99		// and max vectors are actually the min/max values.
100		//
101		
102		LLBBoxLocal bbox2;
103		bbox2.setMax(LLVector3(10.0f, 20.0f, 30.0f));
104		
105		ensure_equals("Custom bbox max (2)", bbox2.getMax(), LLVector3(10.0f, 20.0f, 30.0f));
106	}
107	
108	template<> template<>
109	void object::test<5>()
110	{	
111		//
112		// test the getCenter() method
113		//
114		
115		ensure_equals("Default bbox center", LLBBoxLocal().getCenter(), LLVector3(0.0f, 0.0f, 0.0f));
116		
117		LLBBoxLocal bbox1(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(0.0f, 0.0f, 0.0f));
118		
119		ensure_equals("Custom bbox center", bbox1.getCenter(), LLVector3(-0.5f, -0.5f, -0.5f));
120		
121		LLBBoxLocal bbox2(LLVector3(0.0f, 0.0f, 0.0f), LLVector3(-1.0f, -1.0f, -1.0f));
122		
123		ensure_equals("Invalid bbox center", bbox2.getCenter(), LLVector3(-0.5f, -0.5f, -0.5f));
124	}
125
126	template<> template<>
127	void object::test<6>()
128	{	
129		//
130		// test the getExtent() method
131		//
132		
133		LLBBoxLocal bbox2(LLVector3(0.0f, 0.0f, 0.0f), LLVector3(-1.0f, -1.0f, -1.0f));
134		
135		ensure_equals("Default bbox extent", LLBBoxLocal().getExtent(), LLVector3(0.0f, 0.0f, 0.0f));
136		
137		LLBBoxLocal bbox3(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(1.0f, 2.0f, 0.0f));
138		
139		ensure_equals("Custom bbox extent", bbox3.getExtent(), LLVector3(2.0f, 3.0f, 1.0f));
140	}
141	
142	template<> template<>
143	void object::test<7>()
144	{
145		//
146		// test the addPoint() method
147		//
148		// N.B. if you create an empty bbox and then add points,
149		// the vector (0, 0, 0) will always be part of the bbox.
150		// (Fixing this would require adding a bool to the class size).
151		//
152		
153		LLBBoxLocal bbox1;
154		bbox1.addPoint(LLVector3(-1.0f, -2.0f, -3.0f));
155		bbox1.addPoint(LLVector3(3.0f, 4.0f, 5.0f));
156		
157		ensure_equals("Custom BBox center (1)", bbox1.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
158		ensure_equals("Custom BBox min (1)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
159		ensure_equals("Custom BBox max (1)", bbox1.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
160		
161		bbox1.addPoint(LLVector3(0.0f, 0.0f, 0.0f));
162		bbox1.addPoint(LLVector3(1.0f, 2.0f, 3.0f));
163		bbox1.addPoint(LLVector3(2.0f, 2.0f, 2.0f));
164		
165		ensure_equals("Custom BBox center (2)", bbox1.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
166		ensure_equals("Custom BBox min (2)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
167		ensure_equals("Custom BBox max (2)", bbox1.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
168		
169		bbox1.addPoint(LLVector3(5.0f, 5.0f, 5.0f));
170		
171		ensure_equals("Custom BBox center (3)", bbox1.getCenter(), LLVector3(2.0f, 1.5f, 1.0f));
172		ensure_equals("Custom BBox min (3)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
173		ensure_equals("Custom BBox max (3)", bbox1.getMax(), LLVector3(5.0f, 5.0f, 5.0f));
174	}
175		
176	template<> template<>
177	void object::test<8>()
178	{
179		//
180		// test the addBBox() methods
181		//
182		// N.B. if you create an empty bbox and then add points,
183		// the vector (0, 0, 0) will always be part of the bbox.
184		// (Fixing this would require adding a bool to the class size).
185		//
186		
187		LLBBoxLocal bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLVector3(2.0f, 2.0f, 2.0f));
188		bbox2.addBBox(LLBBoxLocal(LLVector3(1.5f, 1.5f, 1.5f), LLVector3(3.0f, 3.0f, 3.0f)));
189		
190		ensure_equals("Custom BBox center (4)", bbox2.getCenter(), LLVector3(2.0f, 2.0f, 2.0f));
191		ensure_equals("Custom BBox min (4)", bbox2.getMin(), LLVector3(1.0f, 1.0f, 1.0f));
192		ensure_equals("Custom BBox max (4)", bbox2.getMax(), LLVector3(3.0f, 3.0f, 3.0f));
193		
194		bbox2.addBBox(LLBBoxLocal(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(0.0f, 0.0f, 0.0f)));
195		
196		ensure_equals("Custom BBox center (5)", bbox2.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
197		ensure_equals("Custom BBox min (5)", bbox2.getMin(), LLVector3(-1.0f, -1.0f, -1.0f));
198		ensure_equals("Custom BBox max (5)", bbox2.getMax(), LLVector3(3.0f, 3.0f, 3.0f));
199	}
200	
201	template<> template<>
202	void object::test<9>()
203	{
204		//
205		// test the expand() method
206		//
207		
208		LLBBoxLocal bbox1;
209		bbox1.expand(0.0f);
210
211		ensure_equals("Zero-expanded Default BBox center", bbox1.getCenter(), LLVector3(0.0f, 0.0f, 0.0f));
212
213		LLBBoxLocal bbox2(LLVector3(1.0f, 2.0f, 3.0f), LLVector3(3.0f, 4.0f, 5.0f));
214		bbox2.expand(0.0f);
215		
216		ensure_equals("Zero-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
217		ensure_equals("Zero-expanded BBox min", bbox2.getMin(), LLVector3(1.0f, 2.0f, 3.0f));
218		ensure_equals("Zero-expanded BBox max", bbox2.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
219
220		bbox2.expand(0.5f);
221
222		ensure_equals("Positive-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
223		ensure_equals("Positive-expanded BBox min", bbox2.getMin(), LLVector3(0.5f, 1.5f, 2.5f));
224		ensure_equals("Positive-expanded BBox max", bbox2.getMax(), LLVector3(3.5f, 4.5f, 5.5f));
225
226		bbox2.expand(-1.0f);
227		
228		ensure_equals("Negative-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
229		ensure_equals("Negative-expanded BBox min", bbox2.getMin(), LLVector3(1.5f, 2.5f, 3.5f));
230		ensure_equals("Negative-expanded BBox max", bbox2.getMax(), LLVector3(2.5f, 3.5f, 4.5f));		
231	}
232}