-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.h
92 lines (78 loc) · 2.45 KB
/
shape.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#include <stdint.h>
#include "image.h"
#include "pixel.h"
typedef struct point {
uint16_t x;
uint16_t y;
} Point;
typedef struct line {
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
} Line;
typedef struct circle {
uint16_t x; // center of the circle - x position
uint16_t y; // center of the circle - y position
double radius;
} Circle;
typedef double radians;
typedef struct arc {
uint16_t x;
uint16_t y;
double radius;
radians start_rads;
radians end_rads;
} Arc;
/*
* Simple algorithm to draw the line onto the image.
*
* "Walks" down the line, drawing a pixel on the image for each point on the
* line
*
* Kinda slow, kinda simple.
*/
void rasterize_line_simple(Image *image, const Line *line, const Pixel *pixel);
/*
* Bresenham's Algorithm is an alternative way to rasterize a line.
*
* It only uses integer addition, subtraction and bit shifting instead of the
* floating point operations in the 'simple' algorithm.
*
* The basic idea is that when drawing a line, the coordinate which is changing
* fractionally either stays the same or changes y +/- 1 pixel coordinate on
* each iteration.
*/
void rasterize_line_bresenham(Image *image, const Line *line,
const Pixel *pixel);
/*
* Method to draw a circle.
*
* It uses (a lot of) floating point math to draw the circle onto the image
* There's some trivial ways to improve the performance, none which I'll do.
*
* There's also some algorithmic changes that can be done to improve the
* performace - using the midpoint algorithm or bresenham's algorithm is good
* idea.
*
*/
void rasterize_circle_simple(Image *image, const Circle *circle,
const Pixel *pixel,
const double step_size_radians);
/*
* Uses the midpoint algorithm to draw a circle onto the image
*/
void rasterize_circle_midpoint(Image *image, const Circle *circle,
const Pixel *pixel);
/*
* Uses the bresenham's modifications to the midpoint algorithm to draw a circle
* onto the image
*/
void rasterize_circle_bresenham(Image *image, const Circle *circle,
const Pixel *pixel);
// Method to draw an arc. Uses a lot of floating point math
void rasterize_arc_simple(Image *image, const Arc *arc, const Pixel *pixel,
const radians step_size);
void print_line(const Line *line);
void print_circle(const Circle *circle);