-
Notifications
You must be signed in to change notification settings - Fork 1
/
cylinder.cpp
42 lines (36 loc) · 1.1 KB
/
cylinder.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
#include "cylinder.h"
#include "scene3d.h"
Cylinder::Cylinder(int cx, int cy, int cz, int r, int h, Scene3D *scene, QGraphicsItem *parent)
:QGraphicsItem(parent), cx(cx), cy(cy), cz(cz), r(r), h(h), scene(scene)
{
}
QPainterPath Cylinder::shape() const
{
return path;
}
QRectF Cylinder::boundingRect() const
{
return QRectF(0, 0, scene->width(), scene->height());
}
void Cylinder::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
path = QPainterPath();
drawCylinder();
painter->fillPath(path, brush);
}
void Cylinder::drawPixel(const QPoint &point)
{
const QPoint scenePos = scene->toScenePos(point);
const int thickness = this->scene->getThickness();
if (scenePos.x() < 0 || scenePos.x() > this->scene->width() ||
scenePos.y() < 0 || scenePos.y() > this->scene->height()) return;
path.addRect(QRect(scenePos, QSize(thickness, thickness)));
}
void Cylinder::drawCylinder()
{
for(const auto &point : Drawer::drawCylinder(cx, cy, cz, r, h, scene->to2D)){
drawPixel(point);
}
}