Add quad drawing utilities
This commit is contained in:
		@@ -10,6 +10,7 @@
 | 
				
			|||||||
typedef struct point point_t;
 | 
					typedef struct point point_t;
 | 
				
			||||||
typedef struct line line_t;
 | 
					typedef struct line line_t;
 | 
				
			||||||
typedef struct triangle triangle_t;
 | 
					typedef struct triangle triangle_t;
 | 
				
			||||||
 | 
					typedef struct gquad gquad_t;
 | 
				
			||||||
typedef struct rect rect_t;
 | 
					typedef struct rect rect_t;
 | 
				
			||||||
typedef struct window window_t;
 | 
					typedef struct window window_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -29,6 +30,13 @@ struct triangle {
 | 
				
			|||||||
  point_t p2;
 | 
					  point_t p2;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct gquad {
 | 
				
			||||||
 | 
					  point_t p0;
 | 
				
			||||||
 | 
					  point_t p1;
 | 
				
			||||||
 | 
					  point_t p2;
 | 
				
			||||||
 | 
					  point_t p3;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct rect {
 | 
					struct rect {
 | 
				
			||||||
  point_t topleft;
 | 
					  point_t topleft;
 | 
				
			||||||
  i32 w;
 | 
					  i32 w;
 | 
				
			||||||
@@ -63,6 +71,8 @@ void draw_point(const window_t *wnd, point_t p, colour_t colour);
 | 
				
			|||||||
void draw_line(const window_t *wnd, const line_t *ln, colour_t colour);
 | 
					void draw_line(const window_t *wnd, const line_t *ln, colour_t colour);
 | 
				
			||||||
void draw_triangle(const window_t *wnd, triangle_t triangle, colour_t colour);
 | 
					void draw_triangle(const window_t *wnd, triangle_t triangle, colour_t colour);
 | 
				
			||||||
void fill_triangle(const window_t *wnd, triangle_t triangle, colour_t colour);
 | 
					void fill_triangle(const window_t *wnd, triangle_t triangle, colour_t colour);
 | 
				
			||||||
 | 
					void draw_gquad(const window_t *wnd, gquad_t gquad, colour_t colour);
 | 
				
			||||||
 | 
					void fill_gquad(const window_t *wnd, gquad_t gquad, colour_t colour);
 | 
				
			||||||
void draw_rect(const window_t *wnd, rect_t rect, colour_t colour);
 | 
					void draw_rect(const window_t *wnd, rect_t rect, colour_t colour);
 | 
				
			||||||
void fill_rect(const window_t *wnd, rect_t rect, colour_t colour);
 | 
					void fill_rect(const window_t *wnd, rect_t rect, colour_t colour);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								src/window.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								src/window.c
									
									
									
									
									
								
							@@ -122,15 +122,35 @@ void fill_triangle(const window_t *wnd, triangle_t triangle, colour_t colour) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  for (i32 y = min_y; y < max_y; ++y) {
 | 
					  for (i32 y = min_y; y < max_y; ++y) {
 | 
				
			||||||
    for (i32 x = min_x; x < max_x; ++x) {
 | 
					    for (i32 x = min_x; x < max_x; ++x) {
 | 
				
			||||||
      if (half_space(x2, x1, y2, y1, x, y) > 0 &&
 | 
					      if (half_space(x2, x1, y2, y1, x, y) >= 0 &&
 | 
				
			||||||
          half_space(x3, x2, y3, y2, x, y) > 0 &&
 | 
					          half_space(x3, x2, y3, y2, x, y) >= 0 &&
 | 
				
			||||||
          half_space(x1, x3, y1, y3, x, y) > 0) {
 | 
					          half_space(x1, x3, y1, y3, x, y) >= 0) {
 | 
				
			||||||
        draw_point(wnd, (point_t){x, y}, colour);
 | 
					        draw_point(wnd, (point_t){x, y}, colour);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void draw_gquad(const window_t *wnd, gquad_t gquad, colour_t colour) {
 | 
				
			||||||
 | 
					  line_t l0 = (line_t){gquad.p0, gquad.p1};
 | 
				
			||||||
 | 
					  line_t l1 = (line_t){gquad.p1, gquad.p3};
 | 
				
			||||||
 | 
					  line_t l2 = (line_t){gquad.p3, gquad.p2};
 | 
				
			||||||
 | 
					  line_t l3 = (line_t){gquad.p2, gquad.p0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  draw_line(wnd, &l0, colour);
 | 
				
			||||||
 | 
					  draw_line(wnd, &l1, colour);
 | 
				
			||||||
 | 
					  draw_line(wnd, &l2, colour);
 | 
				
			||||||
 | 
					  draw_line(wnd, &l3, colour);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void fill_gquad(const window_t *wnd, gquad_t gquad, colour_t colour) {
 | 
				
			||||||
 | 
					  triangle_t t0 = (triangle_t){gquad.p3, gquad.p1, gquad.p0};
 | 
				
			||||||
 | 
					  triangle_t t1 = (triangle_t){gquad.p0, gquad.p2, gquad.p3};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fill_triangle(wnd, t0, colour);
 | 
				
			||||||
 | 
					  fill_triangle(wnd, t1, colour);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void draw_rect(const window_t *wnd, rect_t rect, colour_t colour) {
 | 
					void draw_rect(const window_t *wnd, rect_t rect, colour_t colour) {
 | 
				
			||||||
  set_colour(wnd, colour);
 | 
					  set_colour(wnd, colour);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user