Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Array2D.hpp
1// INFINITY_API_PUBLIC
2
3#pragma once
4
5#include <Infinity/Types/Containers/Array.hpp>
6#include <Infinity/Types/Math/Vector2.hpp>
7#include <Infinity/Types/Math/Vector3.hpp>
8#include <Infinity/Types/Math/Vector4.hpp>
9
10#include <vector>
11#include <cassert>
12
13namespace Infinity::IO::Data
14{
16 template<typename T>
17 class Array2DSerializer;
19}
20
22{
23
80 template<typename T>
81 class INFINITY_API_TEMPLATE Array2D : public Array<T>
82 {
83 public:
89 Array2D() : Array<T>(), _width(0), _height(0) { }
90
100 Array2D(size_t width, size_t height) : Array<T>(width * height), _width(width), _height(height) { }
101
113 Array2D(size_t width, size_t height, Array<T> data) : Array<T>(data), _width(width), _height(height) { }
114
124 Array2D(size_t width, size_t height, T* data) : Array<T>(data, width * height), _width(width), _height(height) { }
125
137 Array2D(size_t colStride, const std::vector<T>& data) : Array<T>(data), _width(data.size() / colStride), _height(colStride) { }
138
144 virtual ~Array2D() { }
145
146 std::unique_ptr<Core::Base> clone() const override
147 {
148 return std::make_unique<Array2D<T>>(*this);
149 }
150
156 const Infinity::Types::TypeID& typeId() const override { return Infinity::Types::getTypeID<Array2D<T>>(); }
157
163 inline size_t width() const noexcept
164 {
165 return _width;
166 }
167
173 inline size_t height() const noexcept
174 {
175 return _height;
176 }
177
178 using Array<T>::at;
179
192 T& at(size_t x, size_t y)
193 {
194 return at(y * _width + x);
195 }
196
209 const T& at(size_t x, size_t y) const
210 {
211 return at(y * _width + x);
212 }
213
219 virtual size_t dimensions() const noexcept override
220 {
221 return 2;
222 }
223
237 void resize(size_t width, size_t height)
238 {
239 size_t newSize = width * height;
240
241 if (newSize == Array<T>::size())
242 {
243 _width = width;
244 _height = height;
245 return;
246 }
247
248 Array<T>::resize(newSize);
249
250 _width = width;
251 _height = height;
252 }
253
254 protected:
255 using Array<T>::resize;
256
257 private:
258 size_t _width;
259 size_t _height;
260
261 friend class Infinity::IO::Data::Array2DSerializer<T>;
262 };
263
271
277
286
294
303
311
319
328
337
346
355}
356
357// Type registration for common scalar specializations
368
369// Type registration for Vector2 specializations
373
374// Type registration for Vector2d (double) specializations
378
379// Type registration for Vector2b (int8_t) specializations
383
384// Type registration for Vector2s (int16_t) specializations
388
389// Type registration for Vector2i (int32_t) specializations
393
394// Type registration for Vector2l (int64_t) specializations
398
399// Type registration for Vector2ub (uint8_t) specializations
403
404// Type registration for Vector2us (uint16_t) specializations
408
409// Type registration for Vector2ui (uint32_t) specializations
413
414// Type registration for Vector2ul (uint64_t) specializations
418
419// Type registration for common 2D texture array types (arrays of 2D textures)
421INFINITY_TYPE(Infinity::Types::Containers::Array<Infinity::Types::Containers::Array2D<int8_t>>)
422INFINITY_TYPE(Infinity::Types::Containers::Array<Infinity::Types::Containers::Array2D<float>>)
423INFINITY_TYPE(Infinity::Types::Containers::Array<Infinity::Types::Containers::Array2D<Infinity::Types::Math::Vector4ub>>)
Two-dimensional array container for grid-based data in procedural generation.
Definition Array2D.hpp:82
Array2D()
Default constructor.
Definition Array2D.hpp:89
size_t width() const noexcept
Gets the width (number of columns) of the 2D array.
Definition Array2D.hpp:163
virtual size_t dimensions() const noexcept override
Gets the number of dimensions in this container.
Definition Array2D.hpp:219
std::unique_ptr< Core::Base > clone() const override
Definition Array2D.hpp:146
Array2D(size_t width, size_t height)
Constructs a 2D array with specified dimensions.
Definition Array2D.hpp:100
virtual ~Array2D()
Destructor.
Definition Array2D.hpp:144
size_t height() const noexcept
Gets the height (number of rows) of the 2D array.
Definition Array2D.hpp:173
const Infinity::Types::TypeID & typeId() const override
Gets the TypeID for this Array2D type.
Definition Array2D.hpp:156
Array2D(size_t width, size_t height, T *data)
Constructs a 2D array by copying from a raw data pointer.
Definition Array2D.hpp:124
T & at(size_t x, size_t y)
Accesses element at 2D coordinates.
Definition Array2D.hpp:192
void resize(size_t width, size_t height)
Resizes the 2D array to new dimensions.
Definition Array2D.hpp:237
const T & at(size_t x, size_t y) const
Accesses element at 2D coordinates (const).
Definition Array2D.hpp:209
Array2D(size_t colStride, const std::vector< T > &data)
Constructs a 2D array from a 1D vector with column stride.
Definition Array2D.hpp:137
Array2D(size_t width, size_t height, Array< T > data)
Constructs a 2D array from existing Array data with specified dimensions.
Definition Array2D.hpp:113
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77
Definition Array.hpp:17
Definition Array.hpp:25
Definition Asset.hpp:11
Runtime type identifier for the Infinity type system.
Definition TypeID.hpp:71