00001 #ifndef OPENTISSUE_CORE_MATH_INTERVAL_INTERVAL_INTERSECT_H 00002 #define OPENTISSUE_CORE_MATH_INTERVAL_INTERVAL_INTERSECT_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/math/interval/interval_fwd.h> //--- Needed for forward declaration of interval class 00013 #include <cmath> //--- Needed for std::min and std::max 00014 00015 namespace OpenTissue 00016 { 00017 namespace math 00018 { 00019 namespace interval 00020 { 00021 00030 template<typename value_type> 00031 inline Interval<value_type> intersect( Interval<value_type> const & A, Interval<value_type> const & B) 00032 { 00033 using std::min; 00034 using std::max; 00035 00036 typedef Interval<value_type> interval_type; 00037 00038 //--- TODO KE : why use register? 00039 register value_type tmp_lower; // jackj: -O4 probably makes register 00040 register value_type tmp_upper; // jackj: -O4 probably makes register 00041 00042 if(empty(A) || empty(B)) 00043 return interval_type::empty(); 00044 00045 if(B.lower()>A.upper() || A.lower()>B.upper()) 00046 return interval_type::empty(); 00047 00048 tmp_lower = max( A.lower(), B.lower() ); 00049 tmp_upper = min( A.upper(), B.upper() ); 00050 00051 return interval_type(tmp_lower, tmp_upper); 00052 } 00053 00054 } // namespace interval 00055 } // namespace math 00056 } // namespace OpenTissue 00057 00058 // OPENTISSUE_CORE_MATH_INTERVAL_INTERVAL_INTERSECT_H 00059 00060 #endif 00061