📄 bbox.h
字号:
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* * bbox.h - * Defines an axis parallel bounding box. * * Copyright 2000 Sariel Har-Peled (ssaarriieell@cs.uiuc.edu) * * 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 2, or (at your option) any * later version.\*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/#ifndef __BBOX__H#define __BBOX__H#include <limits.h>template <int DIM>class BBoxGeneric {private: real min_coords[ DIM ]; real max_coords[ DIM ]; typedef PointGeneric<DIM> point_d;public: void init( const BBoxGeneric & a, const BBoxGeneric & b ) { for (int ind = 0; ind < DIM; ind++ ) { min_coords[ ind ] = min( a.min_coords[ ind ], b.min_coords[ ind ] ); max_coords[ ind ] = max( a.max_coords[ ind ], b.max_coords[ ind ] ); } } PointGeneric<DIM> center() const { PointGeneric<DIM> pnt; for (int ind = 0; ind < DIM; ind++ ) { pnt.setCoord( ind, ( min_coords[ ind ] + max_coords[ ind ] ) / 2.0 ); } return pnt; } void init() { for (int ind = 0; ind < DIM; ind++ ) { min_coords[ ind ] = 1e20; max_coords[ ind ] = -1e20; } } void dump() const { printf( "---(" ); for (int ind = 0; ind < DIM; ind++ ) { printf( "[%g, %g] ", min_coords[ ind ], max_coords[ ind ] ); } printf( ")\n" ); } const real & min_coord( int coord ) const { return min_coords[ coord ]; } const real & max_coord( int coord ) const { return max_coords[ coord ]; } point_d project( point_d & pnt ) { point_d out; for ( int ind = 0; ind < DIM; ind++ ) { if ( pnt[ ind ] < min_coords[ ind ] ) out[ ind ] = min_coords[ ind ]; else if ( pnt[ ind ] > max_coords[ ind ] ) out[ ind ] = max_coords[ ind ]; else\ out[ ind ] = pnt[ ind ]; } return out; } void bound( const point_d & pnt ) { //cout << "bounding: " << pnt << "\n"; for ( int ind = 0; ind < DIM; ind++ ) { if ( pnt[ ind ] < min_coords[ ind ] ) min_coords[ ind ] = pnt[ ind ]; if ( pnt[ ind ] > max_coords[ ind ] ) max_coords[ ind ] = pnt[ ind ]; } } real length_dim( int dim ) const { return max_coords[ dim ] - min_coords[ dim ]; } int getLongestDim() const { int dim = 0; real len = length_dim( 0 ); for ( int ind = 1; ind < DIM; ind++ ) if ( length_dim( ind ) > len ) { len = length_dim( ind ); dim = ind; } return dim; } real getLongestEdge() const { return length_dim( getLongestDim() ); } real get_diam() const { real sum, val; sum = 0; for ( int ind = 0; ind < DIM; ind++ ) { val = length_dim( ind ); sum += val * val; } return sqrt( sum ); } real get_min_coord( int dim ) const { return min_coords[ dim ]; } real get_max_coord( int dim ) const { return max_coords[ dim ]; }};class BBox3d : public BBoxGeneric<3> {};class BBox2d : public BBoxGeneric<2> {};#else /* __BBOX__H */#error Header file bbox.h included twice#endif /* __BBOX__H *//* bbox.h - End of File ------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -