10template<Dimensionality dim, Precision fp>
20 Point(std::initializer_list<fp> list) :
NumVec<fp, dim::N>(list) {}
22 explicit Point(
const fp(&list)[dim::N]) :
NumVec<fp, dim::N>(list) {}
29 auto diff = p - *
this;
30 auto diff2 = diff * diff;
31 auto dist = std::sqrt(diff2.sum());
36template<Dimensionality dim, Precision fp,
bool topBoundaryInclusive = false>
39 bool _betweenIn(
const fp min,
const fp val,
const fp max)
const {
40 return (min <= val) & (val <= max);
43 bool _betweenEx(
const fp min,
const fp val,
const fp max)
const {
44 return (min <= val) & (val < max);
47 bool between(
const fp min,
const fp val,
const fp max)
const {
48 if (topBoundaryInclusive)
return this->
_betweenIn(min, val, max);
63 for (
i32 axis = 0; axis < dim::N; axis++) {
64 highEx[axis] = std::nexttoward(highEx[axis], highEx[axis] + 1);
70 return this->low ==
r.low & this->high ==
r.high;
74 return this->low !=
r.low | this->high !=
r.high;
78 auto delta = this->high - this->
low;
82 for (
i32 i = 0; i < dim::N; i++) {
91 for (
i32 i = 0; i < dim::N; i++) {
92 result &=
between(this->low[i], p[i], this->high[i]);
99 for (
i32 i = 0; i < dim::N; i++) {
100 result &=
_betweenIn(this->low[i], p[i], this->high[i]);
108 for (
i32 i = 0; i < dim::N; i++) {
109 result[i] = -1 * !
between(this->low[i], p[i], this->high[i]);
118 for (
i32 i = 0; i < dim::N; i++) {
119 res &= this->low[i] <
r.high[i] & this->high[i] >
r.low[i];
127 for (
i32 i = 0; i < dim::N; i++) {
128 auto lmin = this->low[i];
129 auto lmax = this->high[i];
131 auto rmin =
r.low[i];
132 auto rmax =
r.high[i];
134 if (topBoundaryInclusive) {
137 result &=
between(lmin, rmin, lmax) & ((lmin <= rmax) & (rmax <= lmax));
145 auto lowDelta = this->low -
r.low;
146 bool isLowZero =
false;
148 for (
u32 i = 0; i < D::N; i++) isLowZero |= lowDelta[i] == 0;
150 if (isLowZero)
return true;
152 auto highDelta = this->high -
r.high;
154 bool isHighZero =
false;
155 for (
u32 i = 0; i < D::N; i++) isHighZero |= highDelta[i] == 0;
157 if (isHighZero)
return true;
165 for (
i32 i = 0; i < dim::N; i++) {
166 iLow[i] = std::max(this->low[i],
r.low[i]);
167 iHigh[i] = std::min(this->high[i],
r.high[i]);
172 for (
int i = 0; i < dim::N; i++) {
173 valid &= iLow[i] < iHigh[i];
176 if (valid)
return Region{iLow, iHigh};
181 return (this->low + this->high) / 2;
187 for (
i32 i = 0; i < dim::N; i++) {
188 inc[i] = (this->high[i] - this->low[i]) / n;
191 for (
u32 i = 0; i < (
u32) std::pow(n, dim::N); i++) {
195 for (
u32 d = 0; d < dim::N; d++) {
196 auto didx = (i / (
u32) std::pow(n, d)) % n;
197 pLow[d] += inc[d] * didx;
198 pHigh[d] += inc[d] * (didx + 1);
201 regions[i] =
Region{pLow, pHigh};
207 auto center = this->low + (this->high - this->
low) / 2;
211 for (
u32 d = 0; d < dim::N; d++) {
212 idx += (center[d] <= p[d]) * std::pow(n, d);
218 auto pnorm = (p - this->
low) / (this->high - this->low);
220 auto pidx = (pnorm * n).floor();
223 for (
u32 d = 0; d < dim::N; d++) {
224 idx += pidx[d] * std::pow(n, d);
227 assert(idx < std::pow(n, dim::N))
232 stream <<
"{ L:" << value.low <<
" H:" << value.high <<
" }";
Point(const Point &other)
Point(const NumVec< fp, dim::N > &other)
Point(const fp(&list)[dim::N])
Point(std::initializer_list< fp > list)
fp distance(const Point &p) const
constexpr T pow_constexpr(T val, T exp)
static constexpr u32 TwoPowerN()
static constexpr u32 PowerN()
void split(u32 n, Region *regions) const
bool containsEx(const Point &p) const
friend std::ostream & operator<<(std::ostream &stream, const Region &value)
Region intersection(const Region &r) const
bool overlaps(const Region &r) const
static Region fromInclusiveBounds(const Point &low, const Point &high)
NumVec< i32, dim::N > containsAxis(const Point &p) const
bool contains(const Point &p) const
bool _betweenEx(const fp min, const fp val, const fp max) const
u32 splitIdx(u32 n, const Point &p) const
bool sharesBoundary(const Region &r) const
bool operator!=(const Region &r) const
bool operator==(const Region &r) const
bool contains(const Region &r) const
bool _betweenIn(const fp min, const fp val, const fp max) const
bool between(const fp min, const fp val, const fp max) const