-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDDAline1.cpp
64 lines (54 loc) · 1.17 KB
/
DDAline1.cpp
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
// DDAline.cpp: implementation of the CDDAline class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DJQGeoExe.h"
#include "DDAline1.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDDAline1::CDDAline1()
{
}
CDDAline1::~CDDAline1()
{
}
void CDDAline1::setCoords(int x1,int y1,int x2,int y2)
{
this->x1 = x1;
this->y1 = y1;
this->x2 = x2;
this->y2 = y2;
}
void CDDAline1::Draw(CDC *pDC)
{
float x, y, xincre, yincre;
int k = abs(x2 - x1); //|dx|
if (abs(y2 - y1) > k) //|dy|
{
k = abs(y2 - y1);
} //k=max(|dx|,|dy|) ->²½³¤
if(x1<x2)
{
xincre = (float)(x2 - x1)/k;
yincre = (float)(y2 - y1)/k;
}
else
{
xincre = -(float)(x2 - x1)/k;
yincre = -(float)(y2 - y1)/k;
}
x = x1;
y = y1;
for (int i = 1; i <= k; i++)
{
pDC->SetPixel(x, y, RGB(255, 0, 0));
x = x + xincre;
y = y + yincre;
}
}