MCPcopy Create free account
hub / github.com/Geode-solutions/OpenGeode / ArrayImpl

Class ArrayImpl

include/geode/basic/internal/array_impl.hpp:36–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34{
35 template < index_t dimension >
36 class ArrayImpl
37 {
38 friend class bitsery::Access;
39 using CellIndices = typename CellArray< dimension >::CellIndices;
40
41 public:
42 [[nodiscard]] index_t cell_index( const CellArray< dimension >& array,
43 const CellIndices& index ) const
44 {
45 const auto nb_u = array.nb_cells_in_direction( 0 );
46 auto cell_id = index[0] + ( index[1] * nb_u );
47 if( dimension == 3 )
48 {
49 cell_id += index[2] * nb_u * array.nb_cells_in_direction( 1 );
50 }
51 return cell_id;
52 }
53
54 [[nodiscard]] CellIndices cell_indices(
55 const CellArray< dimension >& array, index_t index ) const
56 {
57 OpenGeodeBasicException::check_assertion( index < array.nb_cells(),
58 "[CellArray::cell_index] Invalid index" );
59 CellIndices cell_id;
60 for( const auto d : LRange{ dimension } )
61 {
62 index_t offset{ 1 };
63 for( const auto d2 : LRange{ dimension - d - 1 } )
64 {
65 offset *= array.nb_cells_in_direction( d2 );
66 }
67 const auto value =
68 static_cast< index_t >( std::floor( index / offset ) );
69 cell_id[dimension - d - 1] = value;
70 index -= value * offset;
71 }
72 return cell_id;
73 }
74
75 private:
76 template < typename Archive >
77 void serialize( Archive& serializer )
78 {
79 serializer.ext( *this,
80 Growable< Archive, ArrayImpl >{
81 { []( Archive& /*unused*/, ArrayImpl& /*unused*/ ) {} } } );
82 }
83 };
84} // namespace geode::internal

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected