computer-graphics-0/src/drawing_assets.hpp

117 lines
2.8 KiB
C++

#pragma once
#include <type_traits>
#include "frame.hpp"
void draw_circle(Frame *frame, int cx, int cy, int radius, COLOR outline);
inline void draw_circle(Frame *frame, Point c, int radius, COLOR outline) {
draw_circle(frame, c.x, c.y, radius, outline);
}
void draw_line(Frame *frame, int x1, int y1, int x2, int y2, COLOR color);
inline void draw_line(Frame *frame, Point p1, Point p2, COLOR color) {
draw_line(frame, p1.x, p1.y, p2.x, p2.y, color);
}
template<class ...>
struct draw_polyline_ {
template<class ...point_t>
friend
void draw_polyline(Frame *frame, COLOR color, point_t ...points);
template<class ...>
friend
struct draw_polyline_;
private:
};
template<class p0_t, class p1_t, class ...pp_t>
struct draw_polyline_<p0_t, p1_t, pp_t...> {
template<class ...point_t>
friend
void draw_polyline(Frame *frame, COLOR color, point_t ...points);
template<class ...>
friend
struct draw_polyline_;
private:
static_assert(std::is_same_v<p0_t, Point>);
static_assert(std::is_same_v<p1_t, Point>);
static void draw(Frame *frame, COLOR color, p0_t p0, p1_t p1, pp_t ...points) {
draw_line(frame, p0, p1, color);
draw_polyline_<p1_t, pp_t...>::draw(frame, color, p1, points...);
}
static constexpr bool HAS_ANY = true;
static Point first(p0_t p0, p1_t p1, pp_t ...points) {
return p0;
}
static Point last(p0_t p0, p1_t p1, pp_t ...points) {
return draw_polyline_<p1_t, pp_t...>::last(p1, points...);
}
};
template<class p0_t>
struct draw_polyline_<p0_t> {
template<class ...point_t>
friend
void draw_polyline(Frame *frame, COLOR color, point_t ...points);
template<class ...>
friend
struct draw_polyline_;
private:
static_assert(std::is_same_v<p0_t, Point>);
static void draw(Frame *frame, COLOR color, p0_t p0) {}
static constexpr bool HAS_ANY = true;
static Point first(p0_t p0) {
return p0;
}
static Point last(p0_t p0) {
return p0;
}
};
template<>
struct draw_polyline_<> {
template<class ...point_t>
friend
void draw_polyline(Frame *frame, COLOR color, point_t ...points);
template<class ...>
friend
struct draw_polyline_;
private:
static void draw(Frame *frame, COLOR color) {}
static constexpr bool HAS_ANY = false;
static Point first() {
return Point{0, 0};
}
static Point last() {
return Point{0, 0};
}
};
template<class ...point_t>
void draw_polyline(Frame *frame, COLOR color, point_t ...points) {
if constexpr (!draw_polyline_<point_t...>::HAS_ANY) {}
else {
draw_polyline_<point_t...>::draw(frame, color, points...);
draw_line(frame, draw_polyline_<point_t...>::last(points...), draw_polyline_<point_t...>::first(points...), color);
}
}