-------------------------------------------------------------------------------- Description: Local recursive function used by the bounding sphere generation algorithm --------------------------------------------------------------------------------
| 201 | // Local recursive function used by the bounding sphere generation algorithm |
| 202 | // -------------------------------------------------------------------------------- |
| 203 | Vector4d recurBoundingSphereCreate( Vector3 const** p, size_t len, size_t b ) |
| 204 | { |
| 205 | const double radiusEpsilon = 1e-4; |
| 206 | |
| 207 | Vector4d mb; |
| 208 | |
| 209 | // in case of the "trivial" ones we have an easy solution |
| 210 | switch( b ) |
| 211 | { |
| 212 | case 0: |
| 213 | BoundingSphereFromPoints( mb, nullptr, 0 ); |
| 214 | break; |
| 215 | case 1: |
| 216 | BoundingSphereFromPoints( mb, &p[-1], 1 ); |
| 217 | break; |
| 218 | case 2: |
| 219 | BoundingSphereFromPoints( mb, &p[-2], 2 ); |
| 220 | break; |
| 221 | case 3: |
| 222 | BoundingSphereFromPoints( mb, &p[-3], 3 ); |
| 223 | break; |
| 224 | case 4: |
| 225 | BoundingSphereFromPoints( mb, &p[-4], 4 ); |
| 226 | return mb; |
| 227 | } |
| 228 | |
| 229 | for( size_t i = 0; i < len; ++i ) |
| 230 | { |
| 231 | Vector3d delta = Vector3d( *p[i] ) - Vector3d( mb ); |
| 232 | // outside? |
| 233 | if( LengthSq( delta ) > mb.w * mb.w + radiusEpsilon ) |
| 234 | { |
| 235 | // avoid duplicates in the four points |
| 236 | bool isDuplicate = false; |
| 237 | for( size_t j = 0; j < b; ++j ) |
| 238 | { |
| 239 | if( TriVectorIsIdentical( p[i], p[-(int32_t)j - 1] ) ) |
| 240 | { |
| 241 | isDuplicate = true; |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | if( !isDuplicate ) |
| 246 | { |
| 247 | for( size_t j = i; j > 0; --j ) |
| 248 | { |
| 249 | std::swap( p[j], p[j - 1] ); |
| 250 | } |
| 251 | |
| 252 | mb = recurBoundingSphereCreate( p + 1, i, b + 1 ); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | return mb; |
| 258 | } |
| 259 | |
| 260 | // -------------------------------------------------------------------------------- |
no test coverage detected