-
Notifications
You must be signed in to change notification settings - Fork 2
/
Line.cpp
64 lines (57 loc) · 1.47 KB
/
Line.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
#include "Line.h"
Line::Line()
{
this->start = NULL;
this->end = NULL;
this->type = LINE;
this->length = 0;
}
Line::Line(QPoint *start, QPoint *end, FIGURE_TYPE type)
{
this->start = start;
this->end = end;
this->type = LINE;
this->length = 0;
}
void Line::setStartPoint(Point p)
{
this->startPoint = p;
int newCx = (startPoint.x+endPoint.x)/2;
int newCy = (startPoint.y+endPoint.y)/2;
Point cp(newCx,newCy);
this->centerPoint = cp;
//接下来处理旋转点
int newPx = (newCx+endPoint.x)/2;
int newPy = (newCy+endPoint.y)/2;
Point rp(newPx,newPy);
this->rotatePoint =rp;
//setLength();
}
void Line::setEndPoint(Point p)
{
this->endPoint = p;
int newCx = (startPoint.x+endPoint.x)/2;
int newCy = (startPoint.y+endPoint.y)/2;
Point cp(newCx,newCy);
this->centerPoint = cp;
//接下来处理旋转点
int newPx = (newCx+endPoint.x)/2;
int newPy = (newCy+endPoint.y)/2;
Point rp(newPx,newPy);
this->rotatePoint =rp;
//setLength();
}
void Line::setLength()
{
this->length = startPoint.distanceToPoint(endPoint.getQPoint());
}
double Line::getLength()
{
// if(fabs(this->length)<1e-6){
// this->length = startPoint.distanceToPoint(endPoint.getQPoint());
// }else{
// this->length = (this->length+(startPoint.distanceToPoint(endPoint.getQPoint())))/2;
// }
this->length = startPoint.distanceToPoint(endPoint.getQPoint());
return this->length;
}