简体   繁体   English

qwt中的幻数

[英]magic numbers in qwt

Qwt seems to be using a lot of magic numbers. Qwt似乎使用了很多魔术数字。 Could anyone please explain what 90 and 16 from the following code 任何人都可以从以下代码中解释90和16

void QwtRoundScaleDraw::drawBackbone( QPainter *painter ) const
{
    const double a1 = qMin( scaleMap().p1(), scaleMap().p2() ) - 90 * 16;
    const double a2 = qMax( scaleMap().p1(), scaleMap().p2() ) - 90 * 16;

    const double radius = d_data->radius;
    const double x = d_data->center.x() - radius;
    const double y = d_data->center.y() - radius;

    painter->drawArc( x, y, 2 * radius, 2 * radius,
        -a2, a2 - a1 + 1 );          // counterclockwise
}

Steps to figure it out: 解决问题的步骤:

  1. Doc of drawArc drawArc文件
  2. a1 and a2 is used to calculate the startAngle and spanAngle parameter of that function a1和a2用于计算该函数的startAngle和spanAngle参数
  3. the measure of these parameters is the 1/16th of a degree (see #1) 这些参数的度量是度的1/16(请参阅#1)
  4. you can guess that those numbers will rotate the original arc with a quadrant (90 degree) 您可以猜测这些数字将以一个象限(90度)旋转原始弧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM