How to Draw a Continuous Line

How to Draw a Continuous Line - functionality is by unit...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
How to Draw a Continuous Line. .. A continuous line is drawn if neither the delta x nor delta y is greater than 1 pixel. In the following example, the x value always increments by 1 while the y value only decrements by 1 when needed to conform to the "ideal" line: Of course, this only works if the slope of the line is less than (or equal to) 1. So, if the line slop is great than 1, the y value always increments by 1 while the x value only increments/decrements by 1 when needed: Both of these algorithms assume a left to right line draw. If the line is from right to left, just reverse the algorithm.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Unit Testing How do you test your line drawing algorithm? Certainly, the least productive and incomplete way would be in the final application. A much better way to test
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: functionality is by unit testing with test cases - a method by which individual units of source code are tested before introducing other development factors. Ideally, each test case is independent of other functions. By using method stubs and test harnesses, module functionality can be validated to ensure that code meets its design goals and behaves as intended. The following C code might be used to unit test your line draw implementation: #include <math.h> #define PI 3.1415926 lcd_backlight(ON); { float i; for (i = 0; i < PI*2; i += PI/16) { int x = cos(i) * 45; int y = sin(i) * 45; draw_line(80, 50, 80 + x, 50 + y, 1); } }...
View Full Document

This document was uploaded on 02/08/2012.

Page1 / 2

How to Draw a Continuous Line - functionality is by unit...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online