JWS C++ Library
C++ language utility library
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00046 #include <jwsc++/config.h> 00047 00048 #include <cassert> 00049 #include <inttypes.h> 00050 00051 #include <jwsc/vector/vector.h> 00052 #include <jwsc/matrix/matrix.h> 00053 #include <jwsc/matrix/matrix_math.h> 00054 00055 #include <jwsc++/base/exception.h> 00056 #include <jwsc++/graphics/parapiped.h> 00057 #include <jwsc++/graphics/cuboid.h> 00058 00059 #ifdef JWSCXX_HAVE_DMALLOC 00060 #include <dmalloc.h> 00061 #endif 00062 00063 00064 using namespace jwscxx::base; 00065 using namespace jwscxx::graphics; 00066 00067 00095 Cuboid_f::Cuboid_f(float width, float height, float length) 00096 throw (jwscxx::base::Arg_error) 00097 : Parapiped_f(0,0,0, width,0,0, width,height,0, width,height,length) 00098 { 00099 if (width <= 0 || height <= 0 || length <= 0) 00100 { 00101 throw Arg_error("Cuboid dimensions not positive"); 00102 } 00103 } 00104 00105 00136 Cuboid_f::Cuboid_f 00137 ( 00138 float width, 00139 float height, 00140 float length, 00141 float x, 00142 float y, 00143 float z 00144 ) 00145 throw (jwscxx::base::Arg_error) 00146 : Parapiped_f(x,y,z, x+width,y,z, x+width,y+height,z, x+width,y+height,z+length) 00147 { 00148 if (width <= 0 || height <= 0 || length <= 0) 00149 { 00150 throw Arg_error("Cuboid dimensions not positive"); 00151 } 00152 } 00153 00154 00184 Cuboid_f::Cuboid_f 00185 ( 00186 float width, 00187 float height, 00188 float length, 00189 const jwsc::Vector_f* p 00190 ) 00191 throw (jwscxx::base::Arg_error) 00192 : Parapiped_f(0,0,0, width,0,0, width,height,0, width,height,length) 00193 { 00194 using namespace jwsc; 00195 00196 if (width <= 0 || height <= 0 || length <= 0) 00197 { 00198 throw Arg_error("Cuboid dimensions not positive"); 00199 } 00200 00201 if (p->num_elts != 3) 00202 { 00203 throw Arg_error("Cuboid position vector not 3D"); 00204 } 00205 00206 Matrix_f* T = 0; 00207 assert(create_3d_homo_translation_matrix_1_f(&T, p) == 0); 00208 transform(T); 00209 free_matrix_f(T); 00210 } 00211 00212 00214 Cuboid_f::Cuboid_f(const Cuboid_f& c) : Parapiped_f(c) 00215 { 00216 } 00217 00218 00227 Cuboid_f::Cuboid_f(const char* fname) 00228 throw (jwscxx::base::Arg_error, jwscxx::base::IO_error) 00229 : Parapiped_f(0,0,0, 1,0,0, 1,1,0, 1,1,1) 00230 { 00231 jwscxx::base::Readable::read(fname); 00232 } 00233 00234 00243 Cuboid_f::Cuboid_f(std::istream& in) 00244 throw (jwscxx::base::Arg_error, jwscxx::base::IO_error) 00245 : Parapiped_f(0,0,0, 1,0,0, 1,1,0, 1,1,1) 00246 { 00247 read(in); 00248 } 00249 00250 00251 Cuboid_f::~Cuboid_f() 00252 { 00253 } 00254 00255 00261 Cuboid_f& Cuboid_f::operator= (const Cuboid_f& c) 00262 { 00263 Parapiped_f::operator=(c); 00264 00265 return *this; 00266 } 00267 00268 00270 Cuboid_f* Cuboid_f::clone() const 00271 { 00272 return new Cuboid_f(*this); 00273 } 00274 00275 00303 Cuboid_d::Cuboid_d(double width, double height, double length) 00304 throw (jwscxx::base::Arg_error) 00305 : Parapiped_d(0,0,0, width,0,0, width,height,0, width,height,length) 00306 { 00307 if (width <= 0 || height <= 0 || length <= 0) 00308 { 00309 throw Arg_error("Cuboid dimensions not positive"); 00310 } 00311 } 00312 00313 00344 Cuboid_d::Cuboid_d 00345 ( 00346 double width, 00347 double height, 00348 double length, 00349 double x, 00350 double y, 00351 double z 00352 ) 00353 throw (jwscxx::base::Arg_error) 00354 : Parapiped_d(x,y,z, x+width,y,z, x+width,y+height,z, x+width,y+height,z+length) 00355 { 00356 if (width <= 0 || height <= 0 || length <= 0) 00357 { 00358 throw Arg_error("Cuboid dimensions not positive"); 00359 } 00360 } 00361 00362 00392 Cuboid_d::Cuboid_d 00393 ( 00394 double width, 00395 double height, 00396 double length, 00397 const jwsc::Vector_d* p 00398 ) 00399 throw (jwscxx::base::Arg_error) 00400 : Parapiped_d(0,0,0, width,0,0, width,height,0, width,height,length) 00401 { 00402 using namespace jwsc; 00403 00404 if (width <= 0 || height <= 0 || length <= 0) 00405 { 00406 throw Arg_error("Cuboid dimensions not positive"); 00407 } 00408 00409 if (p->num_elts != 3) 00410 { 00411 throw Arg_error("Cuboid position vector not 3D"); 00412 } 00413 00414 Matrix_d* T = 0; 00415 assert(create_3d_homo_translation_matrix_1_d(&T, p) == 0); 00416 transform(T); 00417 free_matrix_d(T); 00418 } 00419 00420 00422 Cuboid_d::Cuboid_d(const Cuboid_d& c) : Parapiped_d(c) 00423 { 00424 } 00425 00426 00435 Cuboid_d::Cuboid_d(const char* fname) 00436 throw (jwscxx::base::Arg_error, jwscxx::base::IO_error) 00437 : Parapiped_d(0,0,0, 1,0,0, 1,1,0, 1,1,1) 00438 { 00439 jwscxx::base::Readable::read(fname); 00440 } 00441 00442 00451 Cuboid_d::Cuboid_d(std::istream& in) 00452 throw (jwscxx::base::Arg_error, jwscxx::base::IO_error) 00453 : Parapiped_d(0,0,0, 1,0,0, 1,1,0, 1,1,1) 00454 { 00455 read(in); 00456 } 00457 00458 00459 Cuboid_d::~Cuboid_d() 00460 { 00461 } 00462 00463 00469 Cuboid_d& Cuboid_d::operator= (const Cuboid_d& c) 00470 { 00471 Parapiped_d::operator=(c); 00472 00473 return *this; 00474 } 00475 00476 00478 Cuboid_d* Cuboid_d::clone() const 00479 { 00480 return new Cuboid_d(*this); 00481 }