* @brief Returns the ideal zoom level for the plot. */
| 261 | * @brief Returns the ideal zoom level for the plot. |
| 262 | */ |
| 263 | double Widgets::Plot3D::idealWorldScale() const |
| 264 | { |
| 265 | const double dx = m_maxPoint.x() - m_minPoint.x(); |
| 266 | const double dy = m_maxPoint.y() - m_minPoint.y(); |
| 267 | const double dz = m_maxPoint.z() - m_minPoint.z(); |
| 268 | |
| 269 | const double maxExtent = qMax(dz, qMax(dx, dy)); |
| 270 | if (maxExtent < 1e-9) |
| 271 | return m_worldScale; |
| 272 | |
| 273 | constexpr double kInv6 = 1.0 / 6.0; |
| 274 | const double targetStep = (maxExtent * 1.2) * kInv6; |
| 275 | const double exponent = std::floor(std::log10(targetStep)); |
| 276 | const double base = fastPow10(exponent); |
| 277 | double snappedStep; |
| 278 | if (targetStep <= base) |
| 279 | snappedStep = base; |
| 280 | else if (targetStep <= base * 2.0) |
| 281 | snappedStep = base * 2.0; |
| 282 | else if (targetStep <= base * 5.0) |
| 283 | snappedStep = base * 5.0; |
| 284 | else |
| 285 | snappedStep = base * 10.0; |
| 286 | |
| 287 | return qBound(1e-9, 1.0 / snappedStep, 1e9); |
| 288 | } |
| 289 | |
| 290 | //-------------------------------------------------------------------------------------------------- |
| 291 | // Display option getters |