How to Draw a Continuous Line

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

Info icon This 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.
Image of page 1

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

View Full Document Right 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
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern