4
#include "LineSegment.h"
6
#include "libdisplay/libdisplay.h"
8
LineSegment::LineSegment(const unsigned char color[3],
9
const double X0, const double Y0,
10
const double X1, const double Y1)
11
: Annotation(color), X0_(X0), Y0_(Y0), X1_(X1), Y1_(Y1)
15
LineSegment::~LineSegment()
20
LineSegment::Draw(DisplayBase *display)
22
const double width = display->Width();
23
const double height = display->Height();
25
if ((X0_ < 0 && X1_ < 0)
26
|| (X0_ >= width && X1_ >= width)
27
|| (Y0_ < 0 && Y1_ < 0)
28
|| (Y0_ >= height && Y1_ >= height)) return;
32
for (double y = Y0_; y < Y1_; y++)
33
display->setPixel(X0_, y, color_);
37
const double slope = (Y1_ - Y0_) / (X1_ - X0_);
55
if (x1 >= width) x1 = width - 1;
56
for (double x = x0; x < x1; x++)
58
display->setPixel(x, y, color_);
78
if (y1 >= height) y1 = height - 1;
79
for (double y = y0; y < y1; y++)
81
display->setPixel(x, y, color_);