Example #1
0
bool QLandmarkFileHandlerLmx::writeCoordinates(const QLandmark &landmark)
{
    m_writer->writeStartElement(m_ns, "coordinates");

    double lat = landmark.coordinate().latitude();
    double lon = landmark.coordinate().longitude();
    double alt = landmark.coordinate().altitude();

    if (qIsNaN(lat))
        m_writer->writeTextElement(m_ns, "latitude", "NaN");
    else
        m_writer->writeTextElement(m_ns, "latitude", QString::number(lat));

    if (qIsNaN(lon))
        m_writer->writeTextElement(m_ns, "longitude", "NaN");
    else
        m_writer->writeTextElement(m_ns, "longitude", QString::number(lon));

    if (!qIsNaN(alt))
        m_writer->writeTextElement(m_ns, "altitude", QString::number(alt));

    m_writer->writeEndElement();

    return true;
}
Example #2
0
int OsmAnd::Utilities::javaDoubleCompare(double l, double r)
{
    const auto lNaN = qIsNaN(l);
    const auto rNaN = qIsNaN(r);
    const auto& li64 = *reinterpret_cast<uint64_t*>(&l);
    const auto& ri64 = *reinterpret_cast<uint64_t*>(&r);
    const auto lPos = (li64 >> 63) == 0;
    const auto rPos = (ri64 >> 63) == 0;
    const auto lZero = (li64 << 1) == 0;
    const auto rZero = (ri64 << 1) == 0;

    // NaN is considered by this method to be equal to itself and greater than all other double values (including +inf).
    if (lNaN && rNaN)
        return 0;
    if (lNaN)
        return +1;
    if (rNaN)
        return -1;

    // 0.0 is considered by this method to be greater than -0.0
    if (lZero && rZero)
    {
        if (lPos && !rPos)
            return -1;
        if (!lPos && rPos)
            return +1;
    }

    // All other cases
    return qCeil(l) - qCeil(r);
}
Example #3
0
PointSegment *GcodeParser::processCommand(const QStringList &args)
{
    QList<float> gCodes;
    PointSegment *ps = NULL;

    // Handle F code
    double speed = GcodePreprocessorUtils::parseCoord(args, 'F');
    if (!qIsNaN(speed)) this->m_lastSpeed = this->m_isMetric ? speed : speed * 25.4;

    // Handle S code
    double spindleSpeed = GcodePreprocessorUtils::parseCoord(args, 'S');
    if (!qIsNaN(spindleSpeed)) this->m_lastSpindleSpeed = spindleSpeed;

    // Handle P code
    double dwell = GcodePreprocessorUtils::parseCoord(args, 'P');
    if (!qIsNaN(dwell)) this->m_points.last()->setDwell(dwell);

    // handle G codes.
    gCodes = GcodePreprocessorUtils::parseCodes(args, 'G');

    // If there was no command, add the implicit one to the party.
    if (gCodes.isEmpty() && m_lastGcodeCommand != -1) {
        gCodes.append(m_lastGcodeCommand);
    }

    foreach (float code, gCodes) {
        ps = handleGCode(code, args);
    }
Example #4
0
void SearchReply::start()
{
    if (request().searchArea().type() == QGeoShape::RectangleType) {
        QGeoRectangle box(request().searchArea());
        if (!box.isValid()) {
            triggerDone(QPlaceReply::BadArgumentError,
                        QString::fromLatin1("Bounding box search area is invalid"));
            return;
        }
    } else if (request().searchArea().type() == QGeoShape::CircleType) {
        QGeoCircle circle(request().searchArea());
        if (!circle.center().isValid() || qIsNaN(circle.center().latitude()) || qIsNaN(circle.center().longitude())) {
            triggerDone(QPlaceReply::BadArgumentError,
                        QString::fromLatin1("The center of the search area is an invalid coordinate"));
            return;
        }
        if (circle.contains(QGeoCoordinate(90,0)) || circle.contains(QGeoCoordinate(-90,0))) {
            triggerDone(QPlaceReply::BadArgumentError,
                        QString::fromLatin1("The search area contains the north or south pole"));
            return;
        }
    }

    if (!request().categories().isEmpty()) {
        foreach (const QPlaceCategory &category, request().categories()) {
            m_catSearchIds.append(categorySearchIds(category.categoryId()));
            db()->searchForPlaces(request(), this, SLOT(searchFinished()), m_catSearchIds);
        }
    } else {
Example #5
0
void tst_QNumeric::qNan()
{
#if defined __FAST_MATH__ && (__GNUC__ * 100 + __GNUC_MINOR__ < 404)
    QSKIP("Non-conformant fast math mode is enabled, cannot run test");
#endif
    double nan = qQNaN();
    QVERIFY(!(0 > nan));
    QVERIFY(!(0 < nan));
    QVERIFY(qIsNaN(nan));
    QVERIFY(qIsNaN(nan + 1));
    QVERIFY(qIsNaN(-nan));
    double inf = qInf();
    QVERIFY(inf > 0);
    QVERIFY(-inf < 0);
    QVERIFY(qIsInf(inf));
    QVERIFY(qIsInf(-inf));
    QVERIFY(qIsInf(2*inf));
    QCOMPARE(1/inf, 0.0);
#ifdef Q_CC_INTEL
    QEXPECT_FAIL("", "ICC optimizes zero * anything to zero", Continue);
#endif
    QVERIFY(qIsNaN(0*nan));
#ifdef Q_CC_INTEL
    QEXPECT_FAIL("", "ICC optimizes zero * anything to zero", Continue);
#endif
    QVERIFY(qIsNaN(0*inf));
    QVERIFY(qFuzzyCompare(1/inf, 0.0));
}
void QgsSingleBandGrayRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax )
{
  Q_UNUSED( theBandNo );

  QgsDebugMsg( QString( "theBandNo = %1 theMin = %2 theMax = %3" ).arg( theBandNo ).arg( theMin ).arg( theMax ) );

  mDisableMinMaxWidgetRefresh = true;
  if ( qIsNaN( theMin ) )
  {
    mMinLineEdit->clear();
  }
  else
  {
    mMinLineEdit->setText( QString::number( theMin ) );
  }

  if ( qIsNaN( theMax ) )
  {
    mMaxLineEdit->clear();
  }
  else
  {
    mMaxLineEdit->setText( QString::number( theMax ) );
  }
  mDisableMinMaxWidgetRefresh = false;
}
Example #7
0
/*!
    \qmlmethod point QtLocation::Map::from_coordinate(coordinate coordinate, bool clipToViewPort)

    Returns the position relative to the map item which corresponds to the \a coordinate.

    If \a cliptoViewPort is \c true, or not supplied then returns an invalid QPointF if
    \a coordinate is not within the current viewport.
*/
QcVectorDouble
QcViewport::coordinate_to_screen(const QcVectorDouble & projected_coordinate, bool clip_to_viewport) const
{
  // qInfo() << coordinate << clip_to_viewport
  //         << (int)projected_coordinate.x() << (int)projected_coordinate.y();

  const QcViewportPart * part = find_part(projected_coordinate);
  if (!part) {
    qWarning() << "out of domain";
    return QcVectorDouble(qQNaN(), qQNaN());
  }

  QcVectorDouble screen_position = to_px(part->map_vector(projected_coordinate));

  // Fixme: purpose
  if (clip_to_viewport) {
    int w = width();
    int h = height();
    double x = screen_position.x();
    double y = screen_position.y();
    if ((x < 0.0) || (x > w) || (y < 0) || (y > h) || qIsNaN(x) || qIsNaN(y))
      return QcVectorDouble(qQNaN(), qQNaN());
  }

  // qInfo() << screen_position;

  return screen_position;
}
Example #8
0
void tst_QNumeric::qNan()
{
    double nan = qQNaN();
#if defined( __INTEL_COMPILER)
    QCOMPARE((0 > nan), false);
    QCOMPARE((0 < nan), false);
    QSKIP("This fails due to a bug in the Intel Compiler", SkipAll);
#else
    if (0 > nan)
        QFAIL("compiler thinks 0 > nan");

#  if defined(Q_CC_DIAB)
    QWARN("!(0 < nan) would fail due to a bug in dcc");
#  else
    if (0 < nan)
        QFAIL("compiler thinks 0 < nan");
#  endif
#endif
    QVERIFY(qIsNaN(nan));
    QVERIFY(qIsNaN(nan + 1));
    QVERIFY(qIsNaN(-nan));
    double inf = qInf();
    QVERIFY(inf > 0);
    QVERIFY(-inf < 0);
    QVERIFY(qIsInf(inf));
    QVERIFY(qIsInf(-inf));
    QVERIFY(qIsInf(2*inf));
    QCOMPARE(1/inf, 0.0);
    QVERIFY(qIsNaN(0*nan));
    QVERIFY(qIsNaN(0*inf));
    QVERIFY(qFuzzyCompare(1/inf, 0.0));
}
Example #9
0
void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin )
{
  Q_UNUSED( theBandNo );
  QgsDebugMsg( QString( "theBandNo = %1 theMin = %2 theMax = %3" ).arg( theBandNo ).arg( theMin ).arg( theMax ) );

  if ( qIsNaN( theMin ) )
  {
    mMinLineEdit->clear();
  }
  else
  {
    mMinLineEdit->setText( QString::number( theMin ) );
  }

  if ( qIsNaN( theMax ) )
  {
    mMaxLineEdit->clear();
  }
  else
  {
    mMaxLineEdit->setText( QString::number( theMax ) );
  }

  mMinMaxOrigin = theOrigin;
  showMinMaxOrigin();
}
Example #10
0
/**
  Searches through the transparency list, if a match is found, the global transparency value is scaled
  by the stored transparency value.
  @param theRedValue the red portion of the needle to search for in the transparency hay stack
  @param theGreenValue  the green portion of the needle to search for in the transparency hay stack
  @param theBlueValue the green portion of the needle to search for in the transparency hay stack
  @param theGlobalTransparency  the overal transparency level for the layer
*/
int QgsRasterTransparency::alphaValue( double theRedValue, double theGreenValue, double theBlueValue, int theGlobalTransparency ) const
{
  //if NaN return 0, transparent
  if ( qIsNaN( theRedValue ) || qIsNaN( theGreenValue ) || qIsNaN( theBlueValue ) )
  {
    return 0;
  }

  //Search through the transparency list looking for a match
  bool myTransparentPixelFound = false;
  TransparentThreeValuePixel myTransparentPixel = {0, 0, 0, 100};
  for ( int myListRunner = 0; myListRunner < mTransparentThreeValuePixelList.count(); myListRunner++ )
  {
    myTransparentPixel = mTransparentThreeValuePixelList[myListRunner];
    if ( myTransparentPixel.red == theRedValue )
    {
      if ( myTransparentPixel.green == theGreenValue )
      {
        if ( myTransparentPixel.blue == theBlueValue )
        {
          myTransparentPixelFound = true;
          break;
        }
      }
    }
  }

  //if a match was found use the stored transparency percentage
  if ( myTransparentPixelFound )
  {
    return ( int )(( float )theGlobalTransparency *( 1.0 - ( myTransparentPixel.percentTransparent / 100.0 ) ) );
  }

  return theGlobalTransparency;
}
Example #11
0
static bool _q_equal(const QScriptValue &v1, const QScriptValue &v2)
{
    if (v1.strictlyEquals(v2))
        return true;
    if (v1.isNumber() && v2.isNumber() && qIsNaN(v1.toNumber()) && qIsNaN(v2.toNumber()))
        return true;
    return false;
}
Example #12
0
bool QPlaceResultPrivate::compare(const QPlaceSearchResultPrivate *other) const
{
    const QPlaceResultPrivate *od = static_cast<const QPlaceResultPrivate *>(other);
    return QPlaceSearchResultPrivate::compare(other)
           && ((qIsNaN(distance) && qIsNaN(od->distance))
                || qFuzzyCompare(distance, od->distance))
           && place == od->place
           && sponsored == od->sponsored;
}
Example #13
0
void GeoReverseGeocode::reload()
{
    if (qIsNaN(latitude())) return;
    if (qIsNaN(longitude())) return;
    if (qFuzzyCompare(latitude(), 0.0)) return;
    if (qFuzzyCompare(longitude(), 0.0)) return;

    AbstractTwitterModel::reload();
}
Example #14
0
void UBWidgetUniboardAPI::eraseLineTo(const qreal x, const qreal y, const qreal pWidth)
{
    if (qIsNaN(x) || qIsNaN(y) || qIsNaN(pWidth)
       || qIsInf(x) || qIsInf(y) || qIsInf(pWidth))
       return;

    if (mScene)
    mScene->eraseLineTo(QPointF(x, y), pWidth);
}
Example #15
0
void UBWidgetUniboardAPI::moveTo(const qreal x, const qreal y)
{
    if (qIsNaN(x) || qIsNaN(y)
        || qIsInf(x) || qIsInf(y))
        return;

    if (mScene)
    mScene->moveTo(QPointF(x, y));
}
Example #16
0
void QgsSingleBandPseudoColorRendererWidget::resetClassifyButton()
{
  mClassifyButton->setEnabled( true );
  double min = lineEditValue( mMinLineEdit );
  double max = lineEditValue( mMaxLineEdit );
  if ( qIsNaN( min ) || qIsNaN( max ) || min >= max )
  {
    mClassifyButton->setEnabled( false );
  }
}
void Test_ATCAbstractFix::test_constructObject_incorrectLat()
{
    Mock_ATCAbstractFix fix(-91, 50);
    QVERIFY(qIsNaN(fix.latitude()));
    QVERIFY(qIsNaN(fix.longitude()));

    fix = Mock_ATCAbstractFix(91, 50);
    QVERIFY(qIsNaN(fix.latitude()));
    QVERIFY(qIsNaN(fix.longitude()));
}
Example #18
0
void UBWidgetUniboardAPI::drawLineTo(const qreal x, const qreal y, const qreal pWidth)
{
    if (qIsNaN(x) || qIsNaN(y) || qIsNaN(pWidth)
        || qIsInf(x) || qIsInf(y) || qIsInf(pWidth))
        return;

    if (mScene)
    mScene->drawLineTo(QPointF(x, y), pWidth,
        UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line);
}
void Test_ATCAbstractFix::test_constructObject_incorrectLon()
{
    Mock_ATCAbstractFix fix(20, -181);
    QVERIFY(qIsNaN(fix.latitude()));
    QVERIFY(qIsNaN(fix.longitude()));

    fix = Mock_ATCAbstractFix(20, 181);
    QVERIFY(qIsNaN(fix.latitude()));
    QVERIFY(qIsNaN(fix.longitude()));
}
Example #20
0
void UBWidgetUniboardAPI::resize(qreal width, qreal height)
{
    if (qIsNaN(width) || qIsNaN(height)
        || qIsInf(width) || qIsInf(height))
        return;

    if (mGraphicsWidget)
    {
        mGraphicsWidget->resize(width, height);
    }
}
Example #21
0
void UBWidgetUniboardAPI::move(const qreal x, const qreal y)
{
    if (qIsNaN(x) || qIsNaN(y)
        || qIsInf(x) || qIsInf(y))
        return;

    if (UBApplication::boardController->activeScene() != mScene)
        return;

    UBApplication::boardController->handScroll(x, y);
}
Example #22
0
void UBWidgetUniboardAPI::centerOn(const qreal x, const qreal y)
{
   if (qIsNaN(x) || qIsNaN(y)
       || qIsInf(x) || qIsInf(y))
       return;

    if (UBApplication::boardController->activeScene() != mScene)
        return;

    UBApplication::boardController->centerOn(QPointF(x, y));
}
Example #23
0
void QScatterDataProxyPrivate::limitValues(QVector3D &minValues, QVector3D &maxValues,
                                           QAbstract3DAxis *axisX, QAbstract3DAxis *axisY,
                                           QAbstract3DAxis *axisZ) const
{
    if (m_dataArray->isEmpty())
        return;

    const QVector3D &firstPos = m_dataArray->at(0).position();

    float minX = firstPos.x();
    float maxX = minX;
    float minY = firstPos.y();
    float maxY = minY;
    float minZ = firstPos.z();
    float maxZ = minZ;

    if (m_dataArray->size() > 1) {
        for (int i = 1; i < m_dataArray->size(); i++) {
            const QVector3D &pos = m_dataArray->at(i).position();

            float value = pos.x();
            if (qIsNaN(value) || qIsInf(value))
                continue;
            if (isValidValue(minX, value, axisX))
                minX = value;
            if (maxX < value)
                maxX = value;

            value = pos.y();
            if (qIsNaN(value) || qIsInf(value))
                continue;
            if (isValidValue(minY, value, axisY))
                minY = value;
            if (maxY < value)
                maxY = value;

            value = pos.z();
            if (qIsNaN(value) || qIsInf(value))
                continue;
            if (isValidValue(minZ, value, axisZ))
                minZ = value;
            if (maxZ < value)
                maxZ = value;
        }
    }

    minValues.setX(minX);
    minValues.setY(minY);
    minValues.setZ(minZ);

    maxValues.setX(maxX);
    maxValues.setY(maxY);
    maxValues.setZ(maxZ);
}
Example #24
0
void UBWidgetUniboardAPI::zoom(const qreal factor, const qreal x, const qreal y)
{
   if (qIsNaN(factor) || qIsNaN(x) || qIsNaN(y)
       || qIsInf(factor) || qIsInf(x) || qIsInf(y))
       return;


    if (UBApplication::boardController->activeScene() != mScene)
        return;

    UBApplication::boardController->zoom(factor, QPointF(x, y));
}
Example #25
0
bool QLandmarkFileHandlerGpx::writeWaypoint(const QLandmark &landmark, const QString &elementName)
{
    double lat = landmark.coordinate().latitude();
    double lon = landmark.coordinate().longitude();

    QString latString;
    QString lonString;
    bool isInvalid = false;

    if (!qIsNaN(lat)) {
        if ((lat > 90.0 )| (lat < -90.0))
            isInvalid = true;
        latString = QString::number(lat);
    } else {
        latString = "NaN";
        isInvalid = true;
    }

    if (!qIsNaN(lon)) {
        if ((lon > 180.0) | (lon < -180.0))
            isInvalid = true;
        lonString = QString::number(lon);
    } else {
        lonString = "NaN";
        isInvalid = true;
    }

    if (isInvalid) {
        if(m_behavior == QLandmarkFileHandlerGpx::ExportAll){
            m_errorString = QString("Landmarks cannot be exported with invalid coordinates (latitude is %1, longitude is %2)").arg(latString).arg(lonString);
            m_errorCode = QLandmarkManager::BadArgumentError; //TODO: should be invalid error code?
            return false;
        } else { //m_behavior == QLandmarkFileHandlerGpx::ExportSome
            return true;//ignore landmarks with invalid coordinates.
        }
    }

    m_writer->writeStartElement(m_ns, elementName);

    m_writer->writeAttribute("lat", latString);
    m_writer->writeAttribute("lon", lonString);

    if (!qIsNaN(landmark.coordinate().altitude()))
        m_writer->writeTextElement(m_ns, "ele", QString::number(landmark.coordinate().altitude()));

    if (!landmark.name().isEmpty())
        m_writer->writeTextElement(m_ns, "name", landmark.name());

    if (!landmark.description().isEmpty())
        m_writer->writeTextElement(m_ns, "desc", landmark.description());
    m_writer->writeEndElement();
    return true;
}
Example #26
0
bool QgsRectangle::isFinite() const
{
  if ( qIsInf( xmin ) || qIsInf( ymin ) || qIsInf( xmax ) || qIsInf( ymax ) )
  {
    return false;
  }
  if ( qIsNaN( xmin ) || qIsNaN( ymin ) || qIsNaN( xmax ) || qIsNaN( ymax ) )
  {
    return false;
  }
  return true;
}
Example #27
0
void UBWidgetUniboardAPI::addText(const QString& text, const qreal x, const qreal y, const int size, const QString& font
        , bool bold, bool italic)
{
    if (qIsNaN(x) || qIsNaN(y)
        || qIsInf(x) || qIsInf(y))
        return;

    if (UBApplication::boardController->activeScene() != mScene)
        return;

    if (mScene)
        mScene->addTextWithFont(text, QPointF(x, y), size, font, bold, italic);

}
/*!
    Decelerate \a timeLineValue from the starting \a velocity to zero over the given
    \a distance.  This is like accel(), but the QQuickTimeLine calculates the exact
    deceleration to use.

    \a distance should be positive.
*/
int QQuickTimeLine::accelDistance(QQuickTimeLineValue &timeLineValue, qreal velocity, qreal distance)
{
    if (qFuzzyIsNull(distance) || qIsNaN(distance) || qFuzzyIsNull(velocity) || qIsNaN(velocity))
        return -1;

    Q_ASSERT((distance >= 0.0f) == (velocity >= 0.0f));

    int time = static_cast<int>(1000 * (2.0f * distance) / velocity);
    if (time <= 0) return -1;

    QQuickTimeLinePrivate::Op op(QQuickTimeLinePrivate::Op::AccelDistance, time, velocity, distance, d->order++);
    d->add(timeLineValue, op);

    return time;
}
void tst_QScriptValueGenerated::qscriptvalue_castqsreal_test(const char*, const QScriptValue& value)
{
    QFETCH(qsreal, expected);
    if (qIsNaN(expected)) {
        QVERIFY(qIsNaN(qscriptvalue_cast<qsreal>(value)));
        QVERIFY(qIsNaN(qscriptvalue_cast<qsreal>(value)));
        return;
    }
    if (qIsInf(expected)) {
        QVERIFY(qIsInf(qscriptvalue_cast<qsreal>(value)));
        QVERIFY(qIsInf(qscriptvalue_cast<qsreal>(value)));
        return;
    }
    QCOMPARE(qscriptvalue_cast<qsreal>(value), expected);
    QCOMPARE(qscriptvalue_cast<qsreal>(value), expected);
}
Example #30
0
void tst_QBrush::gradientStops()
{
    QLinearGradient gradient;
    gradient.setColorAt(0, Qt::red);
    gradient.setColorAt(1, Qt::blue);

    QCOMPARE(gradient.stops().size(), 2);

    QCOMPARE(gradient.stops().at(0), QGradientStop(0, QColor(Qt::red)));
    QCOMPARE(gradient.stops().at(1), QGradientStop(1, QColor(Qt::blue)));

    gradient.setColorAt(0, Qt::blue);
    gradient.setColorAt(1, Qt::red);

    QCOMPARE(gradient.stops().size(), 2);

    QCOMPARE(gradient.stops().at(0), QGradientStop(0, QColor(Qt::blue)));
    QCOMPARE(gradient.stops().at(1), QGradientStop(1, QColor(Qt::red)));

    gradient.setColorAt(0.5, Qt::green);

    QCOMPARE(gradient.stops().size(), 3);
    QCOMPARE(gradient.stops().at(1), QGradientStop(0.5, QColor(Qt::green)));

    // A hack in parseStopNode() in qsvghandler.cpp depends on inserting stops at NaN.
    gradient.setStops(QGradientStops() << QGradientStop(qQNaN(), QColor()));
    QCOMPARE(gradient.stops().size(), 1);
    QVERIFY(qIsNaN(gradient.stops().at(0).first));
    QCOMPARE(gradient.stops().at(0).second, QColor());
}