MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / ellipse

Method ellipse

app/src/UI/Widgets/PainterContext.cpp:1113–1147  ·  view source on GitHub ↗

* @brief Adds an axis-rotated elliptical arc (Canvas2D semantics). */

Source from the content-addressed store, hash-verified

1111 * @brief Adds an axis-rotated elliptical arc (Canvas2D semantics).
1112 */
1113void Widgets::PainterContext::ellipse(qreal x,
1114 qreal y,
1115 qreal rx,
1116 qreal ry,
1117 qreal rotation,
1118 qreal startRad,
1119 qreal endRad,
1120 bool counterClockwise)
1121{
1122 if (rx <= 0.0 || ry <= 0.0)
1123 return;
1124
1125 constexpr qreal kTau = 2.0 * M_PI;
1126 const qreal raw = endRad - startRad;
1127 qreal sweepRad;
1128 if (std::abs(raw) >= kTau)
1129 sweepRad = counterClockwise ? -kTau : kTau;
1130 else {
1131 sweepRad = std::fmod(raw, kTau);
1132 if (!counterClockwise && sweepRad < 0.0)
1133 sweepRad += kTau;
1134 else if (counterClockwise && sweepRad > 0.0)
1135 sweepRad -= kTau;
1136 }
1137
1138 QPainterPath sub;
1139 const QRectF box(-rx, -ry, 2.0 * rx, 2.0 * ry);
1140 sub.arcMoveTo(box, -qRadiansToDegrees(startRad));
1141 sub.arcTo(box, -qRadiansToDegrees(startRad), -qRadiansToDegrees(sweepRad));
1142
1143 QTransform t;
1144 t.translate(x, y);
1145 t.rotateRadians(rotation);
1146 m_path.connectPath(t.map(sub));
1147}
1148
1149/**
1150 * @brief Adds a quadratic Bezier segment from the cursor.

Callers 1

EeFunction · 0.80

Calls 4

absFunction · 0.85
fmodFunction · 0.85
arcToMethod · 0.80
translateMethod · 0.80

Tested by

no test coverage detected