-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
piececrosssectionrender.cpp
46 lines (36 loc) · 1.09 KB
/
piececrosssectionrender.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 <QPainter>
#include <QColor>
#include "piece.h"
#include "piececrosssectionrender.h"
#include "constants.h"
namespace PieceCrossSectionRender
{
void render(QPainter* painter, int targetSize, Piece* piece)
{
painter->setRenderHint(QPainter::Antialiasing);
Spline spline = piece->spline();
// Drawing renders a viewSize x viewSize box centered at (0, 0)
// and scale to the input pixel dimension (int size).
float zoom = 12.0;
// set up style
QPen pen;
pen.setColor(QColor(0, 0, 0));
pen.setWidth(4);
pen.setCapStyle(Qt::RoundCap);
painter->setPen(pen);
// draw
float center = zoom / 2.0;
float blowup = targetSize / static_cast<float>(zoom);
Point2D p;
for (float t = 0.0; t < 1.0; t += 0.001)
{
p = spline.get(t);
painter->drawPoint((center + p.x) * blowup, (center - p.y) * blowup);
painter->drawPoint((center - p.x) * blowup, (center - p.y) * blowup);
}
// connect spline ends to give "volume" to the drawing
p = spline.controlPoints().back();
painter->drawLine((center + p.x) * blowup, (center - p.y) * blowup,
(center - p.x) * blowup, (center - p.y) * blowup);
}
}