13 IVector_3(
int X,
int Y,
int Z) : x(X), y(Y), z(Z) { }
14 IVector_3(
const IVector_2 &v,
int Z) : x(v.x), y(v.y), z(Z) { }
15 IVector_3(
const IVector_3 &v) : x(v.x), y(v.y), z(v.z) { }
16 IVector_3& operator=(
const IVector_3 &v) { x = v.x; y = v.y; z = v.z;
return *
this; }
17 bool operator==(
const IVector_3 &v)
const {
return x == v.x && y == v.y && z == v.z; }
18 bool operator!=(
const IVector_3 &v)
const {
return x != v.x || y != v.y || z != v.z; }
19 IVector_3 operator+(
const IVector_3 &v)
const {
return IVector_3(x + v.x, y + v.y, z + v.z); }
20 IVector_3 operator-(
const IVector_3 &v)
const {
return IVector_3(x - v.x, y - v.y, z - v.z); }
21 IVector_3 operator*(
int s)
const {
return IVector_3(x * s, y * s, z * s); }
22 IVector_3 operator/(
int s)
const {
return IVector_3((x + s - 1) / s, (y + s - 1) / s, (z + s - 1) / s); }
23 IVector_3& operator+=(
const IVector_3 &v) { x += v.x; y += v.y; z += v.z;
return *
this; }
24 IVector_3& operator-=(
const IVector_3 &v) { x -= v.x; y -= v.y; z -= v.z;
return *
this; }
25 IVector_3& operator*=(
int s) { *
this = *
this * s;
return *
this; }
26 IVector_3& operator/=(
int s) { *
this = *
this / s;
return *
this; }
27 IVector_3 abs()
const {
return IVector_3(std::abs(x), std::abs(y), std::abs(z)); }
28 int32_t dot(
const IVector_3 &v)
const {
return x * v.x + y * v.y + z * v.z; }
29 int32_t norm1()
const {
return std::abs(x) + std::abs(y) + std::abs(z); }
30 int32_t hprod()
const {
return x * y * z; }
31 IVector_3 max_cw(
const IVector_3 &v)
const {
return IVector_3(std::max(x, v.x), std::max(y, v.y), std::max(z, v.z)); }
32 IVector_3 min_cw(
const IVector_3 &v)
const {
return IVector_3(std::min(x, v.x), std::min(y, v.y), std::min(z, v.z)); }
41 constexpr IPoint_3(
int X,
int Y,
int Z) : x(X), y(Y), z(Z) { }
42 IPoint_3(
const IVector_3 &v) : x(v.x), y(v.y), z(v.z) { }
43 IPoint_3(
const int *v) : x(v[0]), y(v[1]), z(v[2]) { }
44 IPoint_3(
const uint *v) : x(v[0]), y(v[1]), z(v[2]) { }
45 IPoint_3& operator=(
const IPoint_3 &P) { x = P.x; y = P.y; z = P.z;
return *
this; }
46 bool operator==(
const IPoint_3 &P)
const {
return x == P.x && y == P.y && z == P.z; }
47 bool operator!=(
const IPoint_3 &P)
const {
return x != P.x || y != P.y || z != P.z; }
48 bool isPositive()
const {
return x >= 0 && y >= 0 && z >= 0; }
49 uint index(
const IVector_3 &size)
const { assert(isPositive());
return z * size.z + y * size.y + x * size.x; }
51 IPoint_3 operator+(
const IVector_3 &v)
const {
return IPoint_3(x + v.x, y + v.y, z + v.z); }
52 IPoint_3 operator-(
const IVector_3 &v)
const {
return IPoint_3(x - v.x, y - v.y, z - v.z); }
53 IVector_3 operator-(
const IPoint_3 &P)
const {
return IVector_3(x - P.x, y - P.y, z - P.z); }
54 IPoint_3& operator+=(
const IVector_3 &v) { x += v.x; y += v.y; z += v.z;
return *
this; }
55 IPoint_3& operator-=(
const IVector_3 &v) { x -= v.x; y -= v.y; z -= v.z;
return *
this; }