MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / lineToPolygon

Method lineToPolygon

src/frameworks/UBGeometryUtils.cpp:52–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidth)
53{
54 qreal x1 = pLine.x1();
55 qreal y1 = pLine.y1();
56
57 qreal x2 = pLine.x2();
58 qreal y2 = pLine.y2();
59
60 qreal alpha = (90.0 - pLine.angle()) * PI / 180.0;
61 qreal hypothenuse = pWidth / 2;
62
63 // TODO UB 4.x PERF cache sin/cos table
64 qreal opposite = sin(alpha) * hypothenuse;
65 qreal adjacent = cos(alpha) * hypothenuse;
66
67 QPointF p1a(x1 - adjacent, y1 - opposite);
68 QPointF p1b(x1 + adjacent, y1 + opposite);
69
70 QPointF p2a(x2 - adjacent, y2 - opposite);
71 QPointF p2b(x2 + adjacent, y2 + opposite);
72
73 QPainterPath painterPath;
74
75 painterPath.moveTo(p1a);
76 painterPath.lineTo(p2a);
77
78 painterPath.arcTo(x2 - hypothenuse, y2 - hypothenuse, pWidth, pWidth, (90.0 + pLine.angle()), -180.0);
79
80 //painterPath.lineTo(p2b);
81 painterPath.lineTo(p1b);
82
83 painterPath.arcTo(x1 - hypothenuse, y1 - hypothenuse, pWidth, pWidth, -1 * (90.0 - pLine.angle()), -180.0);
84
85 painterPath.closeSubpath();
86
87 return painterPath.toFillPolygon();
88}
89
90
91

Callers

nothing calls this directly

Calls 4

sinFunction · 0.50
cosFunction · 0.50
angleMethod · 0.45
moveToMethod · 0.45

Tested by

no test coverage detected