Iは円形で(SDL_Point
は単にxとyのための2つのint
複数を含む)のグリッド座標を生成するためにいくつかのコードを持っている:重複のない中間点の円ですか?
std::vector<SDL_Point> circle(const SDL_Point & start, const int radius)
{
int x{ radius }, y{ 0 };
int xChange{ 1 - 2 * radius };
int yChange{ 1 };
int rError{ 0 };
std::vector<SDL_Point> circle;
SDL_Point coord;
while (x >= y)
{
/* Due to circle's symmetry, we need only to calculate
points in the first 45º of the circle.
*/
coord = { start.x + x, start.y + y }; // Octant 1.
circle.push_back(coord);
coord = { start.x - x, start.y + y }; // Octant 4.
circle.push_back(coord);
coord = { start.x - x, start.y - y }; // Octant 5.
circle.push_back(coord);
coord = { start.x + x, start.y - y }; // Octant 8.
circle.push_back(coord);
coord = { start.x + y, start.y + x }; // Octant 2.
circle.push_back(coord);
coord = { start.x - y, start.y + x }; // Octant 3.
circle.push_back(coord);
coord = { start.x - y, start.y - x }; // Octant 6.
circle.push_back(coord);
coord = { start.x + y, start.y - x }; // Octant 7.
circle.push_back(coord);
++y;
rError += yChange;
yChange += 2;
if (2 * rError + xChange > 0)
{
--x;
rError += xChange;
xChange += 2;
}
}
return circle;
}
これはうまく動作するが、私は1つからコピーする場合、いくつかの座標を二回追加され気づい別の八分儀(写真の明確グレー):
それらの重複を持つか、私はちょうどvector
に追加する前に確認する必要があります回避するための既知の方法はありますか?
これを行う最も効率的な方法は何ですか?私は答えは見つけられませんでした。普通の色のサークルを印刷するときにはそれが問題ではないと思います。
EDIT:出力としてベクトルが必要です。
ありがとうございます! :)
実際のパフォーマンスや正確性には何らかの影響がありますか?そうでない場合、それを無視することは常に有効なオプションです。 –