Newer
Older
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
#include <math.h>
#include <iostream>
#include "line.h"
#include "scene.h"
Line::Line(Point startIn, Scene *s) : Shape(startIn, s->getDefaultColour()) {
}
void Line::setEnd(Point endIn) {
end = Point(endIn.x - start.x, endIn.y - start.y);
}
void Line::display(QPainter *qp) {
qp->setPen(QPen(colour, 2, Qt::SolidLine));
qp->drawLine(QPoint(start.x, start.y), QPoint(start.x + end.x, start.y + end.y));
}
void Line::displayHighlight(QPainter *qp, QColor colourIn) {
qp->setPen(QPen(colourIn, 2, Qt::DashLine));
qp->drawLine(QPoint(start.x, start.y), QPoint(start.x + end.x, start.y + end.y));
}
void Line::update(Point in, Scene *parent) {
setEnd(in);
}
float Line::innerDistance() {
return distanceBetweenPoints(start, end);
}
bool Line::pointInShape(Point in) {
AlgLine selfLine(start, start + end);
Point meet;
try {
meet = linesIntersect(selfLine, orthogonalLine(selfLine, in));
} catch (AlgError e) {
return false;
}
//std::cout << meet.x << " " << meet.y << "\n";
//std::cout << in.x << " " << in.y << "\n";
//std::cout << distanceBetweenPoints(in, meet) << "\n\n\n";
Point delta = in - start;
if (delta.x < min(0, end.x) || delta.y < min(0, end.y) || delta.x > max(0, end.x) || delta.y > max(0, end.y)) {
return false;
}
if (distanceBetweenPoints(in, meet) <= 3) {
return true;
}
return false;
}