Skip to content

Commit

Permalink
Created 2DCoordinates header
Browse files Browse the repository at this point in the history
  • Loading branch information
spoutn1k committed Dec 7, 2021
1 parent 5332266 commit ee6ca97
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
33 changes: 1 addition & 32 deletions src/chunk.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
#pragma once

#include "./section.h"
#include <2DCoordinates.hpp>
#include <map.hpp>
#include <nbt/nbt.hpp>

struct Coordinates {
int32_t x, z;

template <typename I, std::enable_if_t<std::is_integral<I>::value, int> = 0>
Coordinates(std::initializer_list<I> l) {
x = *l.begin();
z = *(l.begin() + 1);
}

Coordinates operator+(const Coordinates &other) const {
return {x + other.x, z + other.z};
}

bool operator<(const Coordinates &other) const {
// Code from <bits/stl_pair.h>
return x < other.x || (!(other.x < x) && z < other.z);
}

bool operator==(const Coordinates &other) const {
return x == other.x && z == other.z;
}

bool operator!=(const Coordinates &other) const {
return !this->operator==(other);
}

template <typename I, std::enable_if_t<std::is_integral<I>::value, int> = 0>
Coordinates operator%(const I &m) const {
return {x % m, z % m};
}
};

namespace mcmap {

struct Chunk {
Expand Down
42 changes: 42 additions & 0 deletions src/include/2DCoordinates.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <initializer_list>
#include <stdint.h>
#include <type_traits>

struct Coordinates {
int32_t x, z;

template <typename I, std::enable_if_t<std::is_integral<I>::value, int> = 0>
Coordinates(std::initializer_list<I> l) {
x = *l.begin();
z = *(l.begin() + 1);
}

Coordinates() {
x = int32_t();
z = int32_t();
}

Coordinates operator+(const Coordinates &other) const {
return {x + other.x, z + other.z};
}

bool operator<(const Coordinates &other) const {
// Code from <bits/stl_pair.h>
return x < other.x || (!(other.x < x) && z < other.z);
}

bool operator==(const Coordinates &other) const {
return x == other.x && z == other.z;
}

bool operator!=(const Coordinates &other) const {
return !this->operator==(other);
}

template <typename I, std::enable_if_t<std::is_integral<I>::value, int> = 0>
Coordinates operator%(const I &m) const {
return {x % m, z % m};
}
};

0 comments on commit ee6ca97

Please sign in to comment.