1 #include "drawing_primitives.h"
2 
3 #include <functional>
4 #include <type_traits>
5 #include <vector>
6 
7 #include "line.h"
8 #include "point.h"
9 #include "rng.h"
10 
draw_line(const std::function<void (const point &)> & set,const point & p1,const point & p2)11 void draw_line( const std::function<void( const point & )> &set, const point &p1, const point &p2 )
12 {
13     std::vector<point> line = line_to( p1, p2, 0 );
14     for( auto &i : line ) {
15         set( i );
16     }
17     set( p1 );
18 }
19 
draw_square(const std::function<void (const point &)> & set,point p1,point p2)20 void draw_square( const std::function<void( const point & )> &set, point p1, point p2 )
21 {
22     if( p1.x > p2.x ) {
23         std::swap( p1.x, p2.x );
24     }
25     if( p1.y > p2.y ) {
26         std::swap( p1.y, p2.y );
27     }
28     for( int x = p1.x; x <= p2.x; x++ ) {
29         for( int y = p1.y; y <= p2.y; y++ ) {
30             set( point( x, y ) );
31         }
32     }
33 }
34 
draw_rough_circle(const std::function<void (const point &)> & set,const point & p,int rad)35 void draw_rough_circle( const std::function<void( const point & )> &set, const point &p, int rad )
36 {
37     for( int i = p.x - rad; i <= p.x + rad; i++ ) {
38         for( int j = p.y - rad; j <= p.y + rad; j++ ) {
39             if( trig_dist( p, point( i, j ) ) + rng( 0, 3 ) <= rad ) {
40                 set( point( i, j ) );
41             }
42         }
43     }
44 }
45 
draw_circle(const std::function<void (const point &)> & set,const rl_vec2d & p,double rad)46 void draw_circle( const std::function<void( const point & )> &set, const rl_vec2d &p, double rad )
47 {
48     for( int i = p.x - rad - 1; i <= p.x + rad + 1; i++ ) {
49         for( int j = p.y - rad - 1; j <= p.y + rad + 1; j++ ) {
50             if( ( p.x - i ) * ( p.x - i ) + ( p.y - j ) * ( p.y - j ) <= rad * rad ) {
51                 set( point( i, j ) );
52             }
53         }
54     }
55 }
56 
draw_circle(const std::function<void (const point &)> & set,const point & p,int rad)57 void draw_circle( const std::function<void( const point & )> &set, const point &p, int rad )
58 {
59     for( int i = p.x - rad; i <= p.x + rad; i++ ) {
60         for( int j = p.y - rad; j <= p.y + rad; j++ ) {
61             if( trig_dist( p, point( i, j ) ) <= rad ) {
62                 set( point( i, j ) );
63             }
64         }
65     }
66 }
67