| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <private/polardomain_p.h> |
| 5 | #include <private/qabstractaxis_p.h> |
| 6 | #include <QtCore/QtMath> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | PolarDomain::PolarDomain(QObject *parent) |
| 11 | : AbstractDomain(parent) |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | PolarDomain::~PolarDomain() |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | void PolarDomain::setSize(const QSizeF &size) |
| 20 | { |
| 21 | Q_ASSERT(size.width() == size.height()); |
| 22 | m_radius = size.height() / 2.0; |
| 23 | m_center = QPointF(m_radius, m_radius); |
| 24 | AbstractDomain::setSize(size); |
| 25 | } |
| 26 | |
| 27 | QPointF PolarDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const |
| 28 | { |
| 29 | qreal r = 0.0; |
| 30 | qreal a = toAngularCoordinate(value: point.x(), ok); |
| 31 | if (ok) |
| 32 | r = toRadialCoordinate(value: point.y(), ok); |
| 33 | if (ok) { |
| 34 | return m_center + polarCoordinateToPoint(angularCoordinate: a, radialCoordinate: r); |
| 35 | } else { |
| 36 | qWarning() << "Logarithm of negative value is undefined. Empty layout returned." ; |
| 37 | return QPointF(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | QList<QPointF> PolarDomain::calculateGeometryPoints(const QList<QPointF> &list) const |
| 42 | { |
| 43 | QList<QPointF> result; |
| 44 | result.resize(size: list.size()); |
| 45 | bool ok; |
| 46 | qreal r = 0.0; |
| 47 | qreal a = 0.0; |
| 48 | |
| 49 | for (int i = 0; i < list.size(); ++i) { |
| 50 | a = toAngularCoordinate(value: list[i].x(), ok); |
| 51 | if (ok) |
| 52 | r = toRadialCoordinate(value: list[i].y(), ok); |
| 53 | if (ok) { |
| 54 | result[i] = m_center + polarCoordinateToPoint(angularCoordinate: a, radialCoordinate: r); |
| 55 | } else { |
| 56 | qWarning() << "Logarithm of negative value is undefined. Empty layout returned." ; |
| 57 | return QList<QPointF>(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return result; |
| 62 | } |
| 63 | |
| 64 | QPointF PolarDomain::polarCoordinateToPoint(qreal angularCoordinate, qreal radialCoordinate) const |
| 65 | { |
| 66 | qreal dx = qSin(v: qDegreesToRadians(degrees: angularCoordinate)) * radialCoordinate; |
| 67 | qreal dy = qCos(v: qDegreesToRadians(degrees: angularCoordinate)) * radialCoordinate; |
| 68 | |
| 69 | return QPointF(dx, -dy); |
| 70 | } |
| 71 | |
| 72 | QT_END_NAMESPACE |
| 73 | |
| 74 | #include "moc_polardomain_p.cpp" |
| 75 | |