27 : type_(type), width_(width), height_(height), hw_(width * .5f), hh_(height * .5f),
29 ?
std::min(side > 0 ? side : height * .5f, axisX ? width : height) : 0),
30 step_(((axisX ? width : height) + side_) * .5f), axis_x_(axisX), even_(even) {}
35 if (!staggered())
return {x * width_, -y * height_};
36 if (axis_x_)
return {x * step_, -y * height_ - (shifted(x) ? hh_ : 0)};
37 return {x * width_ + (shifted(y) ? hw_ : 0), -y * step_};
47 floor(-y / height_ - x / width_ + .5f)};
48 if (!staggered())
return {floor(x / width_), floor(-y / height_)};
50 const i32 line = floor(((axis_x_ ? x - hw_ : down - hh_) / step_) + .5f);
51 glm::ivec2 fallback{0, 0};
53 for (
const i32 delta : {0, -1, 1}) {
54 const i32 candidate = line + delta;
55 const f32 shift = shifted(candidate) ? (axis_x_ ? hh_ : hw_) : 0;
56 const i32 across = floor(((axis_x_ ? down : x) - shift) / (axis_x_ ? height_ : width_));
57 const glm::ivec2 cell = axis_x_ ? glm::ivec2{candidate, across} : glm::ivec2{across, candidate};
58 if (delta == 0) fallback = cell;
59 const auto c =
center(cell.x, cell.y);
60 if (contains(x - c.x, y - c.y))
return cell;
79 f32 width_, height_, hw_, hh_, side_, step_;