コード例 #1
0
ファイル: Checker.cpp プロジェクト: thurberdog/engauge6
void Checker::finishActiveSegment (const DocumentModelCoords &modelCoords,
                                   const QPointF &posStartScreen,
                                   const QPointF &posEndScreen,
                                   double yFrom,
                                   double yTo,
                                   const Transformation &transformation,
                                   SideSegments &sideSegments) const
{
  LOG4CPP_INFO_S ((*mainCat)) << "Checker::finishActiveSegment"
                              << " posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
                              << " posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
                              << " yFrom=" << yFrom
                              << " yTo=" << yTo;

  QGraphicsItem *item;
  if ((modelCoords.coordsType() == COORDS_TYPE_POLAR) &&
      (yFrom == yTo)) {

    // Linear cartesian radius
    double radiusLinearCartesian = yFrom;
    if (modelCoords.coordScaleYRadius() == COORD_SCALE_LOG) {
      radiusLinearCartesian = transformation.logToLinearRadius(yFrom,
                                                               modelCoords.originRadius());
    } else {
      radiusLinearCartesian -= modelCoords.originRadius();
    }

    // Draw along an arc since this is a side of constant radius, and we have polar coordinates
    item = ellipseItem (transformation,
                        radiusLinearCartesian,
                        posStartScreen,
                        posEndScreen);

  } else {

    // Draw straight line
    item = lineItem (posStartScreen,
                     posEndScreen);
  }

  sideSegments.push_back (item);
  bindItemToScene (item);
}
コード例 #2
0
void Checker::adjustPolarAngleRanges (const DocumentModelCoords &modelCoords,
                                      const Transformation &transformation,
                                      const QList<Point> &points,
                                      double &xMin,
                                      double &xMax,
                                      double &yMin) const
{
    LOG4CPP_INFO_S ((*mainCat)) << "Checker::adjustPolarAngleRanges transformation=" << transformation;

    const double UNIT_LENGTH = 1.0;

    QString path; // For logging
    if (modelCoords.coordsType() == COORDS_TYPE_POLAR) {

        // Range minimum is at origin
        yMin = modelCoords.originRadius();

        path = QString ("yMin=%1 ").arg (yMin); // For logging

        // Perform special processing to account for periodicity of polar coordinates. Start with unit vectors
        // in the directions of the three axis points
        double angle0 = points.at(0).posGraph().x();
        double angle1 = points.at(1).posGraph().x();
        double angle2 = points.at(2).posGraph().x();
        QPointF pos0 = transformation.cartesianFromCartesianOrPolar(modelCoords,
                       QPointF (angle0, UNIT_LENGTH));
        QPointF pos1 = transformation.cartesianFromCartesianOrPolar(modelCoords,
                       QPointF (angle1, UNIT_LENGTH));
        QPointF pos2 = transformation.cartesianFromCartesianOrPolar(modelCoords,
                       QPointF (angle2, UNIT_LENGTH));

        // Identify the axis point that is more in the center of the other two axis points. The arc is then drawn
        // from one of the other two points to the other. Center point has smaller angles with the other points
        double sumAngle0 = angleBetweenVectors(pos0, pos1) + angleBetweenVectors(pos0, pos2);
        double sumAngle1 = angleBetweenVectors(pos1, pos0) + angleBetweenVectors(pos1, pos2);
        double sumAngle2 = angleBetweenVectors(pos2, pos0) + angleBetweenVectors(pos2, pos1);
        if ((sumAngle0 <= sumAngle1) && (sumAngle0 <= sumAngle2)) {

            // Point 0 is in the middle. Either or neither of points 1 and 2 may be along point 0
            if ((angleFromVectorToVector (pos0, pos1) < 0) ||
                    (angleFromVectorToVector (pos0, pos2) > 0)) {
                path += QString ("from 1=%1 through 0 to 2=%2").arg (angle1).arg (angle2);
                xMin = angle1;
                xMax = angle2;
            } else {
                path += QString ("from 2=%1 through 0 to 1=%2").arg (angle2).arg (angle1);
                xMin = angle2;
                xMax = angle1;
            }
        } else if ((sumAngle1 <= sumAngle0) && (sumAngle1 <= sumAngle2)) {

            // Point 1 is in the middle. Either or neither of points 0 and 2 may be along point 1
            if ((angleFromVectorToVector (pos1, pos0) < 0) ||
                    (angleFromVectorToVector (pos1, pos2) > 0)) {
                path += QString ("from 0=%1 through 1 to 2=%2").arg (angle0).arg (angle2);
                xMin = angle0;
                xMax = angle2;
            } else {
                path += QString ("from 2=%1 through 1 to 0=%2").arg (angle2).arg (angle0);
                xMin = angle2;
                xMax = angle0;
            }
        } else {

            // Point 2 is in the middle. Either or neither of points 0 and 1 may be along point 2
            if ((angleFromVectorToVector (pos2, pos0) < 0) ||
                    (angleFromVectorToVector (pos2, pos1) > 0)) {
                path += QString ("from 0=%1 through 2 to 1=%2").arg (angle0).arg (angle1);
                xMin = angle0;
                xMax = angle1;
            } else {
                path += QString ("from 1=%1 through 2 to 0=%2").arg (angle1).arg (angle0);
                xMin = angle1;
                xMax = angle0;
            }
        }

        // Make sure theta is increasing
        while (xMax < xMin) {

            double thetaPeriod = modelCoords.thetaPeriod();

            path += QString (" xMax+=%1").arg (thetaPeriod);
            xMax += thetaPeriod;

        }
    }

    LOG4CPP_INFO_S ((*mainCat)) << "Checker::adjustPolarAngleRanges path=(" << path.toLatin1().data() << ")";
}