Dest structure_cast( fcppt::math::box::object< T, N > const &_src ) { static_assert( fcppt::math::box::is_box< Dest >::value, "Dest must be a box" ); return Dest( fcppt::math::vector::structure_cast< typename Dest::vector, Conv >( _src.pos() ), fcppt::math::dim::structure_cast< typename Dest::dim, Conv >( _src.size() ) ); }
typename fcppt::math::box::object< T, N >::vector center( fcppt::math::box::object< T, N > const &_box ) { return _box.pos() + fcppt::math::dim::to_vector( _box.size() ) / fcppt::literal< T >( 2 ); }
fcppt::math::box::object< T, N > shrink( fcppt::math::box::object< T, N > const &_box, typename fcppt::math::box::object< T, N >::vector const &_absolute_values ) { return fcppt::math::box::object< T, N >( _box.pos() + _absolute_values , _box.size() - fcppt::literal< T >( 2 ) * fcppt::math::vector::to_dim( _absolute_values ) ); }
fcppt::math::vector::object < T, VN, S > const wrap_point_in_torus( fcppt::math::vector::object < T, VN, S > _p, fcppt::math::box::object < T, N > const &_b ) { typedef fcppt::math::vector::object < T, VN, S > vector; typedef typename vector::size_type size_type; for( size_type i = 0; i < _p.size(); ++i ) { T const left = _b.pos()[i], right = left + _b.size()[i]; if( _p[i] > right ) _p[i] = static_cast<T>( left + (_p[i] - right) ); else if( _p[i] < left ) _p[i] = static_cast<T>( right - (left - _p[i]) ); } return _p; }
std::array< fcppt::math::vector::static_< T, N >, fcppt::literal< std::size_t >( 1u ) << N > corner_points( fcppt::math::box::object< T, N > const &_box ) { typedef fcppt::math::vector::static_< T, N > vector_type; typedef std::array< vector_type, fcppt::literal< std::size_t >( 1u ) << N > result_type; result_type const corners( fcppt::math::generate_binary_vectors< T, N >() ); return fcppt::algorithm::array_init< result_type >( [ &_box, &corners ]( auto const _index ) { return _box.pos() + std::get< _index >( corners ) * fcppt::math::dim::to_vector( _box.size() ); } ); }