1 #ifndef BLOBS_WORLD_PLANET_HPP_
2 #define BLOBS_WORLD_PLANET_HPP_
15 /// A planet has six surfaces, numbered 0 to 5, each with tiles from
16 /// +radius to -radius.
20 explicit Planet(int radius);
24 Planet &operator =(Planet &&);
26 Planet(const Planet &) = delete;
27 Planet &operator =(const Planet &) = delete;
30 /// Get the tile at given surface and coordinates.
31 Tile &TileAt(int surface, int x, int y) {
32 return tiles[IndexOf(surface, x, y)];
34 const Tile &TileAt(int surface, int x, int y) const {
35 return tiles[IndexOf(surface, x, y)];
38 /// Convert coordinates into a tile index.
39 int IndexOf(int surface, int x, int y) const {
40 assert(0 <= surface && surface <= 5);
41 assert(-radius <= x && x <= radius);
42 assert(-radius <= y && y <= radius);
43 return surface * SurfaceArea() + ToOffset(y) * SideLength() + ToOffset(x);
45 /// Convert coordinate into offset
46 int ToOffset(int c) const {
49 /// The "radius" of the planet.
53 /// The length of the side of each surface.
54 int SideLength() const {
55 return 2 * radius + 1;
57 /// The area (or number of tiles) of one surface
58 int SurfaceArea() const {
59 return SideLength() * SideLength();
61 /// Total area of all surfaces combined.
62 int TotalArea() const {
63 return 6 * SurfaceArea();
68 std::unique_ptr<Tile []> tiles;
72 void GenerateTest(Planet &);