rectangle_region.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 2003-2005 Daniel F. Savarese 00003 * Copyright 2006-2009 Savarese Software Research Corporation 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * https://www.savarese.com/software/ApacheLicense-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00023 #ifndef __SSRC_SPATIAL_RECTANGLE_REGION_H 00024 #define __SSRC_SPATIAL_RECTANGLE_REGION_H 00025 00026 #include <ssrc/libssrckdtree-packages.h> 00027 00028 #include <tuple> 00029 00030 __BEGIN_NS_SSRC_SPATIAL 00031 00050 template<typename Point, 00051 const unsigned int i = NS_TR1::tuple_size<Point>::value - 1> 00052 struct rectangle_region { 00053 Point lower, upper; 00054 00055 //rectangle_region() = default; 00056 rectangle_region() : lower(), upper() { } 00057 00058 rectangle_region(const Point & lower, const Point & upper) : 00059 lower(lower), upper(upper) 00060 { } 00061 00062 // This is a helper function that is NOT part of the region concept. 00063 static bool 00064 contains(const Point & point, const Point & lower, const Point & upper) 00065 { 00066 return ((NS_TR1::get<i>(point) >= NS_TR1::get<i>(lower) && 00067 NS_TR1::get<i>(point) <= NS_TR1::get<i>(upper)) && 00068 rectangle_region<Point, i-1>::contains(point, lower, upper)); 00069 } 00070 00079 bool contains(const Point & point) const { 00080 return rectangle_region::contains(point, lower, upper); 00081 } 00082 }; 00083 00084 template<typename Point> 00085 struct rectangle_region<Point, 0> { 00086 Point lower, upper; 00087 00088 //rectangle_region() = default; 00089 rectangle_region() : lower(), upper() { } 00090 00091 rectangle_region(const Point & lower, const Point & upper) : 00092 lower(lower), upper(upper) 00093 { } 00094 00095 // This is a helper function that is NOT part of the region concept. 00096 static bool 00097 contains(const Point & point, const Point & lower, const Point & upper) { 00098 return !(NS_TR1::get<0>(point) < NS_TR1::get<0>(lower) || 00099 NS_TR1::get<0>(point) > NS_TR1::get<0>(upper)); 00100 } 00101 00102 00103 bool contains(const Point & point) const { 00104 return rectangle_region::contains(point, lower, upper); 00105 } 00106 }; 00107 00108 template<typename Point> 00109 struct rectangle_region<Point, 1> { 00110 Point lower, upper; 00111 00112 //rectangle_region() = default; 00113 rectangle_region() : lower(), upper() { } 00114 00115 rectangle_region(const Point & lower, const Point & upper) : 00116 lower(lower), upper(upper) 00117 { } 00118 00119 // This is a helper function that is NOT part of the region concept. 00120 static bool 00121 contains(const Point & point, const Point & lower, const Point & upper) { 00122 return !(NS_TR1::get<0>(point) < NS_TR1::get<0>(lower) || 00123 NS_TR1::get<1>(point) < NS_TR1::get<1>(lower) || 00124 NS_TR1::get<0>(point) > NS_TR1::get<0>(upper) || 00125 NS_TR1::get<1>(point) > NS_TR1::get<1>(upper)); 00126 } 00127 00128 bool contains(const Point & point) const { 00129 return rectangle_region::contains(point, lower, upper); 00130 } 00131 }; 00132 00133 template<typename Point> 00134 struct rectangle_region<Point, 2> { 00135 Point lower, upper; 00136 00137 //rectangle_region() = default; 00138 rectangle_region() : lower(), upper() { } 00139 00140 rectangle_region(const Point & lower, const Point & upper) : 00141 lower(lower), upper(upper) 00142 { } 00143 00144 // This is a helper function that is NOT part of the region concept. 00145 static bool 00146 contains(const Point & point, const Point & lower, const Point & upper) { 00147 return !(NS_TR1::get<0>(point) < NS_TR1::get<0>(lower) || 00148 NS_TR1::get<1>(point) < NS_TR1::get<1>(lower) || 00149 NS_TR1::get<2>(point) < NS_TR1::get<2>(lower) || 00150 NS_TR1::get<0>(point) > NS_TR1::get<0>(upper) || 00151 NS_TR1::get<1>(point) > NS_TR1::get<1>(upper) || 00152 NS_TR1::get<2>(point) > NS_TR1::get<2>(upper)); 00153 } 00154 00155 bool contains(const Point & point) const { 00156 return rectangle_region::contains(point, lower, upper); 00157 } 00158 }; 00159 00160 __END_NS_SSRC_SPATIAL 00161 00162 #endif