Last active
June 19, 2017 07:15
-
-
Save x100ex/d303e9089408491ddad449395ba0f0f7 to your computer and use it in GitHub Desktop.
прореживание сетки пикселей и сетки тайлов
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2017, Aleksander A. Popov. | |
// | |
// Функции прореживания сетки пикселей и сетки тайлов | |
// | |
#include <QRect> | |
QRect subsample_erosion_twice(const QRect& rc) { | |
return rc.isValid() ? QRect(QPoint(rc.left() / 2, rc.top() / 2), | |
QPoint(rc.right() == 0 ? -1 : rc.right() / 2, | |
rc.bottom() == 0 ? -1 : rc.bottom() / 2)) | |
: rc; | |
} | |
int sign(int v) { | |
return v < 0 ? -1 : 1; | |
} | |
QRect subsample_dilation(const QRect& rc, int sx, int sy) { | |
DCHECK_GE(sx, 1); | |
DCHECK_GE(sy, 1); | |
return rc.isValid() | |
? QRect(QPoint((rc.left() + sign(rc.left()) * (sx - 1)) / sx, | |
(rc.top() + sign(rc.top()) * (sy - 1)) / sy), | |
QPoint((rc.right() + sx - 1) / sx, | |
(rc.bottom() + sy - 1) / sy)) | |
: rc; | |
} | |
void generate_levels_rects(const QRect& pixels_rect_level0, | |
int sx, | |
int sy, | |
std::vector<QRect>* output_pixels_rects, | |
std::vector<QRect>* output_tiles_rects) { | |
DCHECK(output_pixels_rects); | |
DCHECK(output_tiles_rects); | |
output_pixels_rects->clear(); | |
output_tiles_rects->clear(); | |
QRect pixels_rc = pixels_rect_level0; | |
while (pixels_rc.isValid()) { | |
output_pixels_rects->push_back(pixels_rc); | |
output_tiles_rects->push_back(subsample_dilation(pixels_rc, sx, sy)); | |
pixels_rc = subsample_erosion_twice(pixels_rc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment