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