-
Notifications
You must be signed in to change notification settings - Fork 16
/
poly.cpp
44 lines (36 loc) · 856 Bytes
/
poly.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
#include "poly.h"
Poly::Poly()
{
}
void Poly::drawPoly(QImage& target, Poly& poly)
{
static QBrush brush(Qt::SolidPattern);
QPainter painter(&target);
painter.setPen(QPen(Qt::NoPen));
brush.setColor(poly.color);
painter.setBrush(brush);
painter.drawPolygon(poly.points.data(), poly.points.size());
}
bool Poly::operator==(const Poly& other)
{
return color == other.color && points == other.points;
}
QDataStream& operator<< (QDataStream& stream, const Poly& poly)
{
stream << poly.color;
stream << poly.points;
return stream;
}
QDataStream& operator>> (QDataStream& stream, Poly& poly)
{
stream >> poly.color;
stream >> poly.points;
return stream;
}
bool Poly::hasPointIn(QRect rect)
{
for (QPoint& point:points)
if (rect.contains(point))
return true;
return false;
}