Created
March 15, 2020 03:06
-
-
Save HotelCalifornia/93d1275a1b07fe06f9fb2ded68b530d3 to your computer and use it in GitHub Desktop.
in lieu of doing anything remotely useful, i decided to do this
This file contains 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
#include <array> | |
#include <cmath> | |
#include <cstdlib> | |
#include <iostream> | |
#include <utility> | |
namespace circles { | |
namespace { | |
template <std::size_t radius, std::size_t cx, std::size_t cy, std::size_t N, std::size_t... I> | |
constexpr std::array<std::pair<double, double>, N> make_circle(std::index_sequence<I...>) { | |
return std::array<std::pair<double, double>, N>{{ | |
{cx + radius * std::cos(((double)I / N) * 2 * M_PI), cy + radius * std::sin(((double)I / N) * 2 * M_PI)}... | |
}}; | |
} | |
}; // <anonymous> | |
template < | |
std::size_t radius, | |
std::int32_t ox = 0, | |
std::int32_t oy = 0, | |
std::size_t resolution = 1000, | |
typename Indices=std::make_index_sequence<resolution> | |
> | |
struct Circle { | |
using Point = std::pair<double, double>; | |
static constexpr std::array<Point, resolution> points = make_circle<radius, ox, oy, resolution>(Indices{}); | |
}; | |
}; // <circles> | |
int main() { | |
for (auto p : circles::Circle<1, 0, 0, 20>::points) { | |
std::cout << "(" << p.first << ", " << p.second << ")" << std::endl; | |
} | |
} |
Author
HotelCalifornia
commented
Mar 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment