37#ifndef INCLUDE_GUARD_EUNOMIA_HEX_PAINTER_H
38#define INCLUDE_GUARD_EUNOMIA_HEX_PAINTER_H
65 static inline const double SQRT3_ = std::sqrt(3);
74 HexPainter(
int r,
int p0,
int q0) noexcept : r_(r), p0_(p0), q0_(q0) {}
167 p = SQRT3_ * r_ * (x + 0.5 * (y % 2)) + p0_;
168 q = (3.0 * y * r_) / 2.0 + q0_;
180 p = SQRT3_ * r_ * (x + 0.5 * (y % 2)) + p0_;
181 q = (3.0 * y * r_) / 2.0 + q0_;
197 int a = std::abs(x1 - x0 - y1_2 + y0_2);
198 int b = std::abs(y1 - y0);
199 int c = std::abs(x1 + y1 - y1_2 - x0 - y0 + y0_2);
201 return std::max({a, b, c});
217 int& p1,
int& p2,
int& q1,
int& q2,
int& q3,
int &q4,
228 p1 = p - SQRT3_ * r_ / 2.0;
229 p2 = p + SQRT3_ * r_ / 2.0;
238 void fillLeftHalf_(ImageBuffer<C_>& pict,
int x,
int y,
const C_& color);
240 void fillRightHalf_(ImageBuffer<C_>& pict,
int x,
int y,
const C_& color);
252 getPixelPosition(x, y,
p,
q);
279 for (
int j = 0;
j < h;
j++) {
282 if ((y +
j) % 2 == 0) {
283 getPixelPosition(x, y +
j,
p,
q);
289 for (
int i = 0;
i < w;
i++) {
290 getPixelPosition(x +
i, y +
j,
p,
q);
299 getPixelPosition(x + w - 1, y +
j,
p,
q);
302 if ((y +
j) % 2 == 1) {
308 for (
int i = 0;
i < w;
i++) {
309 getPixelPosition(x +
i, y + h - 1,
p,
q);
334 getPixelPosition(x, y,
p,
q);
353 int lx = (
dp + 1) / 2;
354 for (
int i = 0;
i <
lx;
i++) {
381HexPainter<C_>::fillRightHalf_(
382 ImageBuffer<C_>& pict,
int x,
int y,
const C_& color)
386 getPixelPosition(x, y,
p,
q);
404 int lx = (
dp + 1) / 2;
405 for (
int i = 0;
i <
lx;
i++) {
444 getPixelPosition(x, y,
p,
q);
449 getPixelPosition(x + w - 1, y,
p,
q);
453 getPixelPosition(x + w - 1, y + h - 1,
p,
q);
457 getPixelPosition(x, y,
p,
q);
462 getPixelPosition(x + w - 1, y,
p,
q);
466 getPixelPosition(x + w - 1, y + h - 1,
p,
q);
473 for (
int j = 0;
j < h;
j++) {
474 if ((y +
j) % 2 == 0) {
480 for (
int j = 0;
j < h;
j++) {
481 if ((y +
j) % 2 != 0) {
482 fillRightHalf_(
pict, x + w - 1, y +
j,
color);
486 for (
int i = 0;
i < w;
i++) {
492 getPixelPosition(x +
i, y,
p,
q);
506 for (
int i = 0;
i <
lx;
i++) {
532 for (
int i = 0;
i <
lx;
i++) {
551 getPixelPosition(x +
i, y + h - 1,
p,
q);
565 for (
int i = 0;
i <
lx;
i++) {
592 for (
int i = 0;
i <
lx;
i++) {
633 int y0 = std::floor(
qq / 3.0 / r_) * 2;
634 double dq =
qq - (
y0 / 2) * 3 * r_;
637 int x0 = std::floor(
pp * SQRT3_ / 3.0 / r_);
638 double dp =
pp -
x0 * SQRT3_ * r_;
640 double u = -1 *
dp * SQRT3_ / 3;
641 double v =
dp * SQRT3_ / 3;
643 if ((
dq <
u + r_) || (
dq <
v)) {
644 if (
dp < SQRT3_ * r_ / 2) {
651 else if ((
dq >=
u + 3 * r_) || (
dq >=
v + 2 * r_)) {
652 if (
dp < SQRT3_ * r_ / 2) {
正六角形マス描畫クラス
Definition hexpainter.h:59
void getPixelPosition(int x, int y, int &p, int &q)
ピクセル座標の取得
Definition hexpainter.h:165
void fill(ImageBuffer< C_ > &pict, int x, int y, const C_ &color)
HEXの塗り潰し
Definition hexpainter.h:320
int getRadius() const noexcept
HEXの大きさの取得
Definition hexpainter.h:107
int distance(int x0, int y0, int x1, int y1)
距離の取得
Definition hexpainter.h:187
void getPixelPosition(int x, int y, double &p, double &q)
ピクセル位置の取得
Definition hexpainter.h:178
void getOrigin(int &p, int &q) const noexcept
原點の取得
Definition hexpainter.h:98
void resetOrigin(int p0, int q0) noexcept
原點の再設定
Definition hexpainter.h:81
void resetRadius(int r) noexcept
HEXの大きさの再設定
Definition hexpainter.h:91
void getHexPosition(int p, int q, int &x, int &y)
HEX位置の取得
Definition hexpainter.h:618
void draw(ImageBuffer< C_ > &pict, int x, int y, const C_ &color)
HEX外周の描畫
Definition hexpainter.h:249
HexPainter(int r, int p0, int q0) noexcept
構築子
Definition hexpainter.h:74
畫像バッファ基底クラステンプレート
Definition imagebuffer.h:84
ImageBuffer(int w, int h, int p) noexcept
構築子
Definition imagebuffer.h:101
void line(int x1, int y1, int x2, int y2, const C_ &color)
線分の描畫
Definition ibuf_draw.h:60
void box(int left, int top, int right, int bottom, const C_ &color, bool fill=false)
長方形の描畫
Definition ibuf_draw.h:200