static int dispatch (const char *cmnd, const char *args) { if (T.skip) return SKIP; if (0==strcmp (cmnd, "operation")) return operation ((char *) args); if (T.skip_test) { if (0==strcmp (cmnd, "expect")) return another_skip(); return 0; } if (0==strcmp (cmnd, "accept")) return accept (args); if (0==strcmp (cmnd, "expect")) return expect (args); if (0==strcmp (cmnd, "roundtrip")) return roundtrip (args); if (0==strcmp (cmnd, "banner")) return banner (args); if (0==strcmp (cmnd, "verbose")) return verbose (args); if (0==strcmp (cmnd, "direction")) return direction (args); if (0==strcmp (cmnd, "tolerance")) return tolerance (args); if (0==strcmp (cmnd, "ignore")) return ignore (args); if (0==strcmp (cmnd, "require_grid")) return require_grid (args); if (0==strcmp (cmnd, "echo")) return echo (args); if (0==strcmp (cmnd, "skip")) return skip (args); if (0==strcmp (cmnd, "use_proj4_init_rules")) return use_proj4_init_rules (args); return 0; }
// =================================================== // Inline conversion methods // =================================================== inline Real OneDFSIPhysics::fromPToA( const Real& P, const Real& timeStep, const UInt& iNode, const bool& elasticExternalNodes ) const { if ( !M_dataPtr->viscoelasticWall() || ( ( iNode == 0 || iNode == M_dataPtr->numberOfNodes() - 1 ) && elasticExternalNodes ) ) return ( M_dataPtr->area0( iNode ) * OneDFSI::pow20( ( P - externalPressure() ) / M_dataPtr->beta0( iNode ) + 1, 1 / M_dataPtr->beta1( iNode ) ) ); else { // Newton method to solve the non linear equation Real tolerance(1e-6); Real maxIT(100); UInt i(0); Real A( M_dataPtr->area0( iNode ) ); Real newtonUpdate(0); for ( ; i < maxIT ; ++i ) { if ( std::abs( pressure( A, timeStep, iNode, elasticExternalNodes ) - P ) < tolerance ) break; newtonUpdate = ( pressure( A, timeStep, iNode, elasticExternalNodes ) - P ) / dPdA( A, timeStep, iNode, elasticExternalNodes ); if ( A - newtonUpdate <= 0 ) A /= 2.0; // Bisection else A -= newtonUpdate; // Newton } if ( i == maxIT ) { std::cout << "!!! Warning: conversion fromPToA below tolerance !!! " << std::endl; std::cout << "Tolerance: " << tolerance << "; Residual: " << std::abs( pressure( A, timeStep, iNode, elasticExternalNodes ) - P ) << std::endl; } return A; } }
//****************************************************************************** // Main //****************************************************************************** int main(int argc, char **argv) { args::ArgumentParser parser("Checks if images are different within a tolerance.\n" "Intended for use with library tests.\n" "http://github.com/spinicist/QUIT"); args::HelpFlag help(parser, "HELP", "Show this help message", {'h', "help"}); args::Flag verbose(parser, "VERBOSE", "Print more information", {'v', "verbose"}); args::ValueFlag<std::string> input_path(parser, "INPUT", "Input file for difference", {"input"}); args::ValueFlag<std::string> baseline_path(parser, "BASELINE", "Baseline file for difference", {"baseline"}); args::ValueFlag<double> tolerance(parser, "TOLERANCE", "Tolerance (mean percent difference)", {"tolerance"}, 0); args::ValueFlag<double> noise(parser, "NOISE", "Added noise level, tolerance is relative to this", {"noise"}, 0); args::Flag absolute(parser, "ABSOLUTE", "Use absolute difference, not relative (avoids 0/0 problems)", {'a', "abs"}); QI::ParseArgs(parser, argc, argv, verbose); auto input = QI::ReadImage(QI::CheckValue(input_path), verbose); auto baseline = QI::ReadImage(QI::CheckValue(baseline_path), verbose); auto diff = itk::SubtractImageFilter<QI::VolumeF>::New(); diff->SetInput1(input); diff->SetInput2(baseline); auto sqr_norm = itk::SquareImageFilter<QI::VolumeF, QI::VolumeF>::New(); if (absolute) { sqr_norm->SetInput(diff->GetOutput()); } else { auto diff_norm = itk::DivideImageFilter<QI::VolumeF, QI::VolumeF, QI::VolumeF>::New(); diff_norm->SetInput1(diff->GetOutput()); diff_norm->SetInput2(baseline); diff_norm->Update(); sqr_norm->SetInput(diff_norm->GetOutput()); } auto stats = itk::StatisticsImageFilter<QI::VolumeF>::New(); stats->SetInput(sqr_norm->GetOutput()); stats->Update(); const double mean_sqr_diff = stats->GetMean(); const double root_mean_sqr_diff = sqrt(mean_sqr_diff); const double rel_diff = (noise.Get() > 0) ? root_mean_sqr_diff / noise.Get() : root_mean_sqr_diff; const bool passed = rel_diff <= tolerance.Get(); QI::Log(verbose, "Mean Square Diff: {}\nRelative noise: {}\nSquare-root mean square diff: {}\nRelative Diff: {}\nTolerance: {}\nResult: ", mean_sqr_diff ,noise.Get() , root_mean_sqr_diff , rel_diff , tolerance.Get() , (passed ? "Passed" : "Failed")); if (passed) { return EXIT_SUCCESS; } else { return EXIT_FAILURE; } }
QVi RegionService::calcTolerance(const MatSet& matSet, QLP region, QVi averages) { QVis histograms = createHistogram(matSet, region); QVi tolerance(9,0); for(int i=0; i<9; i++) { tolerance[i] = findTolerance(averages[i], histograms[i], region.size()); } return tolerance; }
// --- Internal Methods ---------------------------------------------------- // // Returns \c true if the atoms could feasibly be bonded. bool BondPredictor::couldBeBonded(Atom *a, Atom *b) const { Real distance = a->distance(b); if(distance > minimumBondLength() && distance < maximumBondLength() && std::abs((a->covalentRadius() + b->covalentRadius()) - distance) < tolerance()) return true; else return false; }
int rootSearch(double a, double b, double c, double d, double rootfloor, double rootceil) { static double midpoint; double x; double roots[3] = {0, 0, 0}; int j = 0, k = 0; midpoint = (rootceil + rootfloor) / 2.0; x = midpoint; if( tolerance(a * pow(x, 3) + b * pow(x, 2) + c * x + d) < TOLERANCE ) roots[0] = x; x = rootfloor; do { if( tolerance(a * pow(x, 3) + b * pow(x, 2) + c * x + d) < TOLERANCE ) { roots[j] = x; j++; } x += TOLERANCE; } while(x <= midpoint); x = rootceil; do { if( tolerance(a * pow(x, 3) + b * pow(x, 2) + c * x + d) < TOLERANCE ) { roots[j] = x; j++; } x -= TOLERANCE; } while(midpoint <= x); if(roots[0] == 0 && roots[1] == 0 && roots[2] == 0) { printf("Roots not found between %.0f and %.0f. Please try again\n", rootfloor, rootceil); } else { printf("The roots of the equation (%.2fx^3) + (%.2fx^2) + (%.2fx) + (%.2f) = 0 is/are \n", a, b, c, d); for(k = 0; k < j; k++) printf("%.4f ", roots[k]); } return 0; }
/***** * *****/ bool iAnt_controller::east() { cout << "Moving east" << '\n'; bool amIGoingEast = true; CRadians heading = GetHeading().UnsignedNormalize(); CRadians tolerance(0.09); CRadians threePIHalves = (CRadians::PI*3/2); // CRadians negPI = (CRadians::PI)*-1; if(heading < threePIHalves-tolerance) { motorActuator->SetLinearVelocity(RobotTurningSpeed,0.0); amIGoingEast = false; }else if(heading > threePIHalves+tolerance) { motorActuator->SetLinearVelocity(RobotTurningSpeed,0.0); amIGoingEast = false; }else { motorActuator->SetLinearVelocity(0.0, 0.0); amIGoingEast = true; } return amIGoingEast; } // /***** // * // *****/ bool iAnt_controller::west() { cout << "Moving west" << '\n'; bool amIGoingWest = true; CRadians heading = GetHeading().UnsignedNormalize(); CRadians tolerance(0.09); if(heading < CRadians::PI/2- tolerance) { motorActuator->SetLinearVelocity(0.0, RobotTurningSpeed); amIGoingWest = false; } else if(heading > CRadians::PI/2 + tolerance) { motorActuator->SetLinearVelocity(0.0, RobotTurningSpeed); amIGoingWest = false; }else { motorActuator->SetLinearVelocity(0.0, 0.0); amIGoingWest = true; } return amIGoingWest; }
bool iAnt_controller::east() { cout << "Moving east" << '\n'; bool amIGoingEast = true; CRadians heading = GetHeading().UnsignedNormalize(); CRadians tolerance(0.09); CRadians threePIHalves = (CRadians::PI*3/2); // CRadians negPI = (CRadians::PI)*-1; if(heading < threePIHalves-tolerance) { motorActuator->SetLinearVelocity(RobotTurningSpeed,0.0); amIGoingEast = false; }else if(heading > threePIHalves+tolerance) { motorActuator->SetLinearVelocity(RobotTurningSpeed,0.0); amIGoingEast = false; }else { motorActuator->SetLinearVelocity(0.0, 0.0); amIGoingEast = true; } return amIGoingEast; }
static int operation (char *args) { /***************************************************************************** Define the operation to apply to the input data (in ISO 19100 lingo, an operation is the general term describing something that can be either a conversion or a transformation) ******************************************************************************/ T.op_id++; T.operation_lineno = F->lineno; strncpy (&(T.operation[0]), F->args, MAX_OPERATION); T.operation[MAX_OPERATION] = '\0'; if (T.verbosity > 1) { finish_previous_operation (F->args); banner (args); } T.op_ok = 0; T.op_ko = 0; T.op_skip = 0; T.skip_test = 0; direction ("forward"); tolerance ("0.5 mm"); ignore ("pjd_err_dont_skip"); proj_errno_reset (T.P); if (T.P) proj_destroy (T.P); proj_errno_reset (nullptr); proj_context_use_proj4_init_rules(nullptr, T.use_proj4_init_rules); T.P = proj_create (nullptr, F->args); /* Checking that proj_create succeeds is first done at "expect" time, */ /* since we want to support "expect"ing specific error codes */ return 0; }
void Grnn::Trainer::trainHillClimb(Grnn& grnn) { double h = grnn.bandwidth(); double dh; if(error(grnn, 0.8*h) < error(grnn, 1.5*h)) dh = -tolerance_; else dh = tolerance(); double oldErr = error(grnn, grnn.bandwidth()); double iter = 0; while(iter < maxIter_ && h < maxBandwidth_ && h > (minBandwidth_ + dh)) { double err = error(grnn, h + dh); if(err >= oldErr) break; h += dh; oldErr = err; } }
bool iAnt_controller::south() { cout << "Moving south" << '\n'; bool amIGoingSouth = true; CRadians heading = GetHeading().UnsignedNormalize(); CRadians tolerance(0.09); if(heading < CRadians::PI - tolerance) { motorActuator->SetLinearVelocity(-RobotTurningSpeed, RobotTurningSpeed); amIGoingSouth = false; } else if(heading > CRadians::PI + tolerance) { motorActuator->SetLinearVelocity(RobotTurningSpeed, -RobotTurningSpeed); amIGoingSouth = false; } else { motorActuator->SetLinearVelocity(0.0, 0.0); amIGoingSouth = true; } return amIGoingSouth; }
TEST_F(UnitConversion, NewtonToOunce) { test_conversion_no_throw("N", "oz", 0.0, (16.0/4.4482216152605), tolerance(-7)); }
TEST_F(UnitConversion, RadToArcSec) { test_conversion_no_throw("r", "as", 0.0, (180.0*60.0*60.0/PI), tolerance(-9)); }
void test_areal() { ut_settings ignore_validity; ignore_validity.test_validity = false; ut_settings sym_settings; #if defined(BOOST_GEOMETRY_NO_ROBUSTNESS) sym_settings.sym_difference = false; #endif test_one<Polygon, MultiPolygon, MultiPolygon>("simplex_multi", case_multi_simplex[0], case_multi_simplex[1], 5, 21, 5.58, 4, 17, 2.58); test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_no_ip", case_multi_no_ip[0], case_multi_no_ip[1], 2, 12, 24.0, 2, 12, 34.0); test_one<Polygon, MultiPolygon, MultiPolygon>("case_multi_2", case_multi_2[0], case_multi_2[1], 2, 15, 19.6, 2, 13, 33.6); test_one<Polygon, MultiPolygon, Polygon>("simplex_multi_mp_p", case_multi_simplex[0], case_single_simplex, 5, 21, 5.58, 4, 17, 2.58); test_one<Polygon, Ring, MultiPolygon>("simplex_multi_r_mp", case_single_simplex, case_multi_simplex[0], 4, 17, 2.58, 5, 21, 5.58); test_one<Polygon, MultiPolygon, Ring>("simplex_multi_mp_r", case_multi_simplex[0], case_single_simplex, 5, 21, 5.58, 4, 17, 2.58); // Constructed cases for multi/touch/equal/etc test_one<Polygon, MultiPolygon, MultiPolygon>("case_61_multi", case_61_multi[0], case_61_multi[1], 2, 10, 2, 2, 10, 2, 1, 10, 4); test_one<Polygon, MultiPolygon, MultiPolygon>("case_62_multi", case_62_multi[0], case_62_multi[1], 0, 0, 0, 1, 5, 1); test_one<Polygon, MultiPolygon, MultiPolygon>("case_63_multi", case_63_multi[0], case_63_multi[1], 0, 0, 0, 1, 5, 1); test_one<Polygon, MultiPolygon, MultiPolygon>("case_64_multi", case_64_multi[0], case_64_multi[1], 1, 5, 1, 1, 5, 1, 1, 7, 2); test_one<Polygon, MultiPolygon, MultiPolygon>("case_65_multi", case_65_multi[0], case_65_multi[1], 0, 0, 0, 2, 10, 3); test_one<Polygon, MultiPolygon, MultiPolygon>("case_72_multi", case_72_multi[0], case_72_multi[1], 3, 13, 1.65, 3, 17, 6.15, ignore_validity); test_one<Polygon, MultiPolygon, MultiPolygon>("case_77_multi", case_77_multi[0], case_77_multi[1], 6, 31, 7.0, 5, 36, 13.0, 5, 43, 7.0 + 13.0); test_one<Polygon, MultiPolygon, MultiPolygon>("case_78_multi", case_78_multi[0], case_78_multi[1], 1, 5, 1.0, 1, 5, 1.0); TEST_DIFFERENCE(case_123_multi, 1, 4, 0.25, 2, 9, 0.625); TEST_DIFFERENCE(case_124_multi, 1, 4, 0.25, 2, 9, 0.4375); { ut_settings settings; #if !defined(BOOST_GEOMETRY_NO_ROBUSTNESS) settings.sym_difference = false; #endif test_one<Polygon, MultiPolygon, MultiPolygon>("case_108_multi", case_108_multi[0], case_108_multi[1], 7, 32, 5.5, 4, 28, 9.75, 7, 45, 15.25, settings); } // Ticket on GGL list 2011/10/25 // to mix polygon/multipolygon in call to difference test_one<Polygon, Polygon, Polygon>("ggl_list_20111025_vd_pp", ggl_list_20111025_vd[0], ggl_list_20111025_vd[1], 1, 4, 8.0, 1, 4, 12.5); test_one<Polygon, Polygon, MultiPolygon>("ggl_list_20111025_vd_pm", ggl_list_20111025_vd[0], ggl_list_20111025_vd[3], 1, 4, 8.0, 1, 4, 12.5); test_one<Polygon, MultiPolygon, Polygon>("ggl_list_20111025_vd_mp", ggl_list_20111025_vd[2], ggl_list_20111025_vd[1], 1, 4, 8.0, 1, 4, 12.5); test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20111025_vd_mm", ggl_list_20111025_vd[2], ggl_list_20111025_vd[3], 1, 4, 8.0, 1, 4, 12.5); test_one<Polygon, Polygon, MultiPolygon>("ggl_list_20111025_vd_2", ggl_list_20111025_vd_2[0], ggl_list_20111025_vd_2[1], 1, 7, 10.0, 2, 10, 6.0); test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_a", ggl_list_20120915_h2[0], ggl_list_20120915_h2[1], 2, 13, 17.0, 0, 0, 0.0); test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120915_h2_b", ggl_list_20120915_h2[0], ggl_list_20120915_h2[2], 2, 13, 17.0, 0, 0, 0.0); { ut_settings settings; settings.percentage = 0.001; settings.test_validity = false; test_one<Polygon, MultiPolygon, MultiPolygon>("ggl_list_20120221_volker", ggl_list_20120221_volker[0], ggl_list_20120221_volker[1], 2, 12, 7962.66, 1, 18, 2775258.93, settings); } #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) test_one<Polygon, MultiPolygon, MultiPolygon>("ticket_9081", ticket_9081[0], ticket_9081[1], 2, 28, 0.0907392476356186, 4, 25, 0.126018011439877, 4, 42, 0.0907392476356186 + 0.126018011439877, tolerance(0.001)); // POSTGIS areas: 3.75893745345145, 2.5810000723917e-15 test_one<Polygon, MultiPolygon, MultiPolygon>("bug_21155501", bug_21155501[0], bug_21155501[1], 1, 9, 3.758937, 0, 0, 0.0, ignore_validity); #endif // Areas and #clips correspond with POSTGIS (except sym case) test_one<Polygon, MultiPolygon, MultiPolygon>("case_101_multi", case_101_multi[0], case_101_multi[1], 5, 23, 4.75, 5, 40, 12.75, 5, 48, 4.75 + 12.75); // Areas and #clips correspond with POSTGIS test_one<Polygon, MultiPolygon, MultiPolygon>("case_102_multi", case_102_multi[0], case_102_multi[1], 2, 8, 0.75, 6, 25, 3.75, 6, 27, 0.75 + 3.75); // Areas and #clips correspond with POSTGIS test_one<Polygon, MultiPolygon, MultiPolygon>("case_107_multi", case_107_multi[0], case_107_multi[1], 2, 11, 2.25, 3, 14, 3.0, 4, 21, 5.25); // Areas correspond with POSTGIS, // #clips in PostGIS is 11,11,5 but should most probably be be 12,12,6 test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_1", case_recursive_boxes_1[0], case_recursive_boxes_1[1], 11, 75, 26.0, 12, 77, 24.0, 5, 98, 50.0, ignore_validity); // Areas and #clips correspond with POSTGIS test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_2", case_recursive_boxes_2[0], case_recursive_boxes_2[1], 3, 15, 3.0, 7, 33, 7.0, 10, 48, 10.0); // Areas and #clips by POSTGIS (except sym case) test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_3", case_recursive_boxes_3[0], case_recursive_boxes_3[1], 24, -1, 21.5, 25, -1, 22.5, 37, -1, 44.0); // 4, input is not valid test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_5", case_recursive_boxes_5[0], case_recursive_boxes_5[1], 15, -1, 22.0, // #clips should be 16 11, -1, 27.0, // #clips should be 12 8, -1, 49.0, ignore_validity); test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_6", case_recursive_boxes_6[0], case_recursive_boxes_6[1], 6, -1, 3.5, 3, -1, 1.5, 8, -1, 5.0, ignore_validity); test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_7", case_recursive_boxes_7[0], case_recursive_boxes_7[1], 3, 15, 2.75, 4, 19, 2.75, 3, 22, 5.5); test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_8", case_recursive_boxes_8[0], case_recursive_boxes_8[1], 2, -1, 2.50, 4, -1, 5.75, 4, -1, 8.25); test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_9", case_recursive_boxes_9[0], case_recursive_boxes_9[1], 3, -1, 1.5, 4, -1, 2.5, 6, -1, 4.0); test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_10", case_recursive_boxes_10[0], case_recursive_boxes_10[1], 2, -1, 1.25, 2, -1, 0.75, 4, -1, 2.00); test_one<Polygon, MultiPolygon, MultiPolygon>("case_recursive_boxes_11", case_recursive_boxes_11[0], case_recursive_boxes_11[1], 3, -1, 2.5, 3, -1, 4.5, 3, -1, 7.0); test_one<Polygon, MultiPolygon, MultiPolygon>("mysql_21965285_b", mysql_21965285_b[0], mysql_21965285_b[1], 2, -1, 183.71376870369406, 2, -1, 131.21376870369406, sym_settings); }
forAll(regionsAddressing, regionI) { scalar oldTol = treeType::perturbTol(); treeType::perturbTol() = tolerance(); indirectRegionPatches_.set ( regionI, new indirectTriSurface ( IndirectList<labelledTri> ( surface(), regionsAddressing[regionI] ), surface().points() ) ); // Calculate bb without constructing local point numbering. treeBoundBox bb(Zero, Zero); if (indirectRegionPatches_[regionI].size()) { label nPoints; PatchTools::calcBounds ( indirectRegionPatches_[regionI], bb, nPoints ); // if (nPoints != surface().points().size()) // { // WarningInFunction // << "Surface does not have compact point numbering. " // << "Of " << surface().points().size() // << " only " << nPoints // << " are used." // << " This might give problems in some routines." // << endl; // } // Random number generator. Bit dodgy since not exactly // random ;-) Random rndGen(65431); // Slightly extended bb. Slightly off-centred just so // on symmetric geometry there are fewer face/edge // aligned items. bb = bb.extend(rndGen, 1e-4); bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); } treeByRegion_.set ( regionI, new treeType ( treeDataIndirectTriSurface ( true, indirectRegionPatches_[regionI], tolerance() ), bb, maxTreeDepth(), // maxLevel 10, // leafsize 3.0 // duplicity ) ); treeType::perturbTol() = oldTol; }
bool Foam::chemPointISAT<CompType, ThermoType>::checkSolution ( const scalarField& phiq, const scalarField& Rphiq ) { scalar eps2 = 0; scalarField dR(Rphiq - Rphi()); scalarField dphi(phiq - phi()); const scalarField& scaleFactorV(scaleFactor()); const scalarSquareMatrix& Avar(A()); bool isMechRedActive = chemistry_.mechRed()->active(); scalar dRl = 0; label dim = completeSpaceSize()-2; if (isMechRedActive) { dim = nActiveSpecies_; } // Since we build only the solution for the species, T and p are not // included for (label i=0; i<completeSpaceSize()-nAdditionalEqns_; i++) { dRl = 0; if (isMechRedActive) { label si = completeToSimplifiedIndex_[i]; // If this species is active if (si != -1) { for (label j=0; j<dim; j++) { label sj=simplifiedToCompleteIndex_[j]; dRl += Avar(si, j)*dphi[sj]; } dRl += Avar(si, nActiveSpecies_)*dphi[idT_]; dRl += Avar(si, nActiveSpecies_+1)*dphi[idp_]; if (variableTimeStep()) { dRl += Avar(si, nActiveSpecies_+2)*dphi[iddeltaT_]; } } else { dRl = dphi[i]; } } else { for (label j=0; j<completeSpaceSize(); j++) { dRl += Avar(i, j)*dphi[j]; } } eps2 += sqr((dR[i]-dRl)/scaleFactorV[i]); } eps2 = sqrt(eps2); if (eps2 > tolerance()) { return false; } else { // if the solution is in the ellipsoid of accuracy return true; } }
void Grnn::Trainer::trainBrent(Grnn& grnn) { double a = tolerance(); double b = grnn.bandwidth(); double x = 0.5*(a + b); bracket(grnn, a, b, x); if (a > b) SWP(a, b); double fx = error(grnn, x); double w = x, fw = fx; double v = x, fv = fx; double d = 0.0, u, e = 0.0; for(unsigned iter = 1; iter <= maxIter(); ++iter) { double xm = 0.5*(a + b); double tol1 = tolerance()*fabs(x) + ZEPS; double tol2 = 2.0*(tol1); if (fabs(x - xm) <= (tol2 - 0.5*(b - a))) break; if (fabs(e) > tol1) { double p = (x-v)*(x-v)*(fx-fw) - (x-w)*(x-w)*(fx-fv); double q = 2.0*((x-v)*(fx-fw) - (x-w)*(fx-fv)); if (q > 0.0) p = -p; q = fabs(q); double etemp = e; e = d; if (fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a - x) || p >= q*(b - x)) { if (x >= xm) e = a - x; else e = b - x; d = CGOLD*(e); } else { d = p/q; u = x + d; if (u - a < tol2 || b - u < tol2) d = SIGN(tol1, xm - x); } } else { if (x >= xm) e = a - x; else e = b - x; d = CGOLD *(e); } double u; if(fabs(d) >= tol1) u = x + d; else u = x + SIGN(tol1, d); double fu = error(grnn, u); if (fu <= fx) { if (u >= x) a = x; else b = x; SHFT(v, w, x, u); SHFT(fv, fw, fx, fu); } else { if (u < x) a = u; else b = u; if (fu <= fw || w == x) { v = w; w = u; fv = fw; fw = fu; } else if (fu <= fv || v == x || v == w) { v = u; fv = fu; } } } grnn.setBandwidth(x); }
bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri, QString theExpectedKey, QString theExpectedUri ) { bool ok = true; mReport += "\n\n"; //QgsRasterDataProvider* verifiedProvider = QgsRasterLayer::loadProvider( theVerifiedKey, theVerifiedUri ); QgsRasterDataProvider* verifiedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theVerifiedKey, theVerifiedUri ); if ( !verifiedProvider || !verifiedProvider->isValid() ) { error( QString( "Cannot load provider %1 with URI: %2" ).arg( theVerifiedKey ).arg( theVerifiedUri ), mReport ); ok = false; } //QgsRasterDataProvider* expectedProvider = QgsRasterLayer::loadProvider( theExpectedKey, theExpectedUri ); QgsRasterDataProvider* expectedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theExpectedKey, theExpectedUri ); if ( !expectedProvider || !expectedProvider->isValid() ) { error( QString( "Cannot load provider %1 with URI: %2" ).arg( theExpectedKey ).arg( theExpectedUri ), mReport ); ok = false; } if ( !ok ) return false; mReport += QString( "Verified URI: %1<br>" ).arg( theVerifiedUri.replace( "&", "&" ) ); mReport += QString( "Expected URI: %1<br>" ).arg( theExpectedUri.replace( "&", "&" ) ); mReport += "<br>"; mReport += QString( "<table style='%1'>\n" ).arg( mTabStyle ); mReport += compareHead(); compare( "Band count", verifiedProvider->bandCount(), expectedProvider->bandCount(), mReport, ok ); compare( "Width", verifiedProvider->xSize(), expectedProvider->xSize(), mReport, ok ); compare( "Height", verifiedProvider->ySize(), expectedProvider->ySize(), mReport, ok ); compareRow( "Extent", verifiedProvider->extent().toString(), expectedProvider->extent().toString(), mReport, verifiedProvider->extent() == expectedProvider->extent() ); if ( verifiedProvider->extent() != expectedProvider->extent() ) ok = false; mReport += "</table>\n"; if ( !ok ) return false; bool allOk = true; for ( int band = 1; band <= expectedProvider->bandCount(); band++ ) { bool bandOk = true; mReport += QString( "<h3>Band %1</h3>\n" ).arg( band ); mReport += QString( "<table style='%1'>\n" ).arg( mTabStyle ); mReport += compareHead(); // Data types may differ (?) bool typesOk = true; compare( "Source data type", verifiedProvider->srcDataType( band ), expectedProvider->srcDataType( band ), mReport, typesOk ); compare( "Data type", verifiedProvider->dataType( band ), expectedProvider->dataType( band ), mReport, typesOk ) ; // TODO: not yet sure if noDataValue() should exist at all //compare( "No data (NULL) value", verifiedProvider->noDataValue( band ), expectedProvider->noDataValue( band ), mReport, typesOk ); bool statsOk = true; QgsRasterBandStats verifiedStats = verifiedProvider->bandStatistics( band ); QgsRasterBandStats expectedStats = expectedProvider->bandStatistics( band ); // Min/max may 'slightly' differ, for big numbers however, the difference may // be quite big, for example for Float32 with max -3.332e+38, the difference is 1.47338e+24 double tol = tolerance( expectedStats.minimumValue ); compare( "Minimum value", verifiedStats.minimumValue, expectedStats.minimumValue, mReport, statsOk, tol ); tol = tolerance( expectedStats.maximumValue ); compare( "Maximum value", verifiedStats.maximumValue, expectedStats.maximumValue, mReport, statsOk, tol ); // TODO: enable once fixed (WCS excludes nulls but GDAL does not) //compare( "Cells count", verifiedStats.elementCount, expectedStats.elementCount, mReport, statsOk ); tol = tolerance( expectedStats.mean ); compare( "Mean", verifiedStats.mean, expectedStats.mean, mReport, statsOk, tol ); // stdDev usually differ significantly tol = tolerance( expectedStats.stdDev, 1 ); compare( "Standard deviation", verifiedStats.stdDev, expectedStats.stdDev, mReport, statsOk, tol ); mReport += "</table>"; mReport += "<br>"; if ( !bandOk ) { allOk = false; continue; } if ( !statsOk || !typesOk ) { allOk = false; // create values table anyway so that values are available } mReport += "<table><tr>"; mReport += "<td>Data comparison</td>"; mReport += QString( "<td style='%1 %2 border: 1px solid'>correct value</td>" ).arg( mCellStyle ).arg( mOkStyle ); mReport += "<td></td>"; mReport += QString( "<td style='%1 %2 border: 1px solid'>wrong value<br>expected value</td></tr>" ).arg( mCellStyle ).arg( mErrStyle ); mReport += "</tr></table>"; mReport += "<br>"; int width = expectedProvider->xSize(); int height = expectedProvider->ySize(); QgsRasterBlock *expectedBlock = expectedProvider->block( band, expectedProvider->extent(), width, height ); QgsRasterBlock *verifiedBlock = verifiedProvider->block( band, expectedProvider->extent(), width, height ); if ( !expectedBlock || !expectedBlock->isValid() || !verifiedBlock || !verifiedBlock->isValid() ) { allOk = false; mReport += "cannot read raster block"; continue; } // compare data values QString htmlTable = QString( "<table style='%1'>" ).arg( mTabStyle ); for ( int row = 0; row < height; row ++ ) { htmlTable += "<tr>"; for ( int col = 0; col < width; col ++ ) { bool cellOk = true; double verifiedVal = verifiedBlock->value( row, col ); double expectedVal = expectedBlock->value( row, col ); QString valStr; if ( compare( verifiedVal, expectedVal, 0 ) ) { valStr = QString( "%1" ).arg( verifiedVal ); } else { cellOk = false; allOk = false; valStr = QString( "%1<br>%2" ).arg( verifiedVal ).arg( expectedVal ); } htmlTable += QString( "<td style='%1 %2'>%3</td>" ).arg( mCellStyle ).arg( cellOk ? mOkStyle : mErrStyle ).arg( valStr ); } htmlTable += "</tr>"; } htmlTable += "</table>"; mReport += htmlTable; delete expectedBlock; delete verifiedBlock; } delete verifiedProvider; delete expectedProvider; return allOk; }
void test_all() { typedef bg::model::box<P> box; typedef bg::model::polygon<P> polygon; typedef bg::model::ring<P> ring; typedef typename bg::coordinate_type<P>::type ct; test_one<polygon, polygon, polygon>("simplex_normal", simplex_normal[0], simplex_normal[1], 3, 12, 2.52636706856656, 3, 12, 3.52636706856656); test_one<polygon, polygon, polygon>("simplex_with_empty", simplex_normal[0], polygon_empty, 1, 4, 8.0, 0, 0, 0.0); test_one<polygon, polygon, polygon>( "star_ring", example_star, example_ring, 5, 22, 1.1901714, 5, 27, 1.6701714); test_one<polygon, polygon, polygon>("two_bends", two_bends[0], two_bends[1], 1, 5, 8.0, 1, 5, 8.0); #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) test_one<polygon, polygon, polygon>("star_comb_15", star_comb_15[0], star_comb_15[1], 30, 160, 227.658275102812, 30, 198, 480.485775259312); #endif test_one<polygon, polygon, polygon>("new_hole", new_hole[0], new_hole[1], 1, 9, 7.0, 1, 13, 14.0); test_one<polygon, polygon, polygon>("crossed", crossed[0], crossed[1], 1, 18, 19.5, 1, 7, 2.5); test_one<polygon, polygon, polygon>("disjoint", disjoint[0], disjoint[1], 1, 5, 1.0, 1, 5, 1.0); // The too small one might be discarded (depending on point-type / compiler) // We check area only test_one<polygon, polygon, polygon>("distance_zero", distance_zero[0], distance_zero[1], -1, -1, 8.7048386, -1, -1, 0.0098387, tolerance(0.001)); test_one<polygon, polygon, polygon>("equal_holes_disjoint", equal_holes_disjoint[0], equal_holes_disjoint[1], 1, 5, 9.0, 1, 5, 9.0); test_one<polygon, polygon, polygon>("only_hole_intersections1", only_hole_intersections[0], only_hole_intersections[1], 2, 10, 1.9090909, 4, 16, 10.9090909); test_one<polygon, polygon, polygon>("only_hole_intersection2", only_hole_intersections[0], only_hole_intersections[2], 3, 20, 30.9090909, 4, 16, 10.9090909); test_one<polygon, polygon, polygon>("first_within_second", first_within_second[1], first_within_second[0], 1, 10, 24, 0, 0, 0); test_one<polygon, polygon, polygon>("fitting", fitting[0], fitting[1], 1, 9, 21.0, 1, 4, 4.0, 1, 5, 25.0); test_one<polygon, polygon, polygon>("identical", identical[0], identical[1], 0, 0, 0.0, 0, 0, 0.0); test_one<polygon, polygon, polygon>("intersect_exterior_and_interiors_winded", intersect_exterior_and_interiors_winded[0], intersect_exterior_and_interiors_winded[1], 4, 20, 11.533333, 5, 26, 29.783333); test_one<polygon, polygon, polygon>("intersect_holes_intersect_and_disjoint", intersect_holes_intersect_and_disjoint[0], intersect_holes_intersect_and_disjoint[1], 2, 16, 15.75, 3, 17, 6.75); test_one<polygon, polygon, polygon>("intersect_holes_intersect_and_touch", intersect_holes_intersect_and_touch[0], intersect_holes_intersect_and_touch[1], 3, 21, 16.25, 3, 17, 6.25); test_one<polygon, polygon, polygon>("intersect_holes_new_ring", intersect_holes_new_ring[0], intersect_holes_new_ring[1], 3, 15, 9.8961, 4, 25, 121.8961, tolerance(0.01)); test_one<polygon, polygon, polygon>("first_within_hole_of_second", first_within_hole_of_second[0], first_within_hole_of_second[1], 1, 5, 1, 1, 10, 16); test_one<polygon, polygon, polygon>("intersect_holes_disjoint", intersect_holes_disjoint[0], intersect_holes_disjoint[1], 2, 14, 16.0, 2, 10, 6.0); test_one<polygon, polygon, polygon>("intersect_holes_intersect", intersect_holes_intersect[0], intersect_holes_intersect[1], 2, 16, 15.75, 2, 12, 5.75); test_one<polygon, polygon, polygon>( "case4", case_4[0], case_4[1], 6, 28, 2.77878787878788, 4, 22, 4.77878787878788); test_one<polygon, polygon, polygon>( "case5", case_5[0], case_5[1], 8, 36, 2.43452380952381, 7, 33, 3.18452380952381); #ifdef BOOST_GEOMETRY_TEST_INCLUDE_FAILING_TESTS // Fails, a-b is partly generated, b-a does not have any output // It failed already in 1.59 test_one<polygon, polygon, polygon>("case_58_iet", case_58[0], case_58[2], 3, 12, 0.6666666667, 1, -1, 11.1666666667); #endif test_one<polygon, polygon, polygon>("case_80", case_80[0], case_80[1], 1, 9, 44.5, 1, 10, 84.5); #ifdef BOOST_GEOMETRY_TEST_INCLUDE_FAILING_TESTS // Fails, holes are not subtracted test_one<polygon, polygon, polygon>("case_81", case_81[0], case_81[1], 1, 8, 80.5, 1, 8, 83.0, 1, 12, 80.5 + 83.0); #endif test_one<polygon, polygon, polygon>("winded", winded[0], winded[1], 3, 37, 61, 1, 15, 13); test_one<polygon, polygon, polygon>("within_holes_disjoint", within_holes_disjoint[0], within_holes_disjoint[1], 2, 15, 25, 1, 5, 1); test_one<polygon, polygon, polygon>("side_side", side_side[0], side_side[1], 1, 5, 1, 1, 5, 1, 1, 7, 2); #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) test_one<polygon, polygon, polygon>("buffer_mp1", buffer_mp1[0], buffer_mp1[1], 1, 61, 10.2717, 1, 61, 10.2717); if ( BOOST_GEOMETRY_CONDITION((boost::is_same<ct, double>::value)) ) { test_one<polygon, polygon, polygon>("buffer_mp2", buffer_mp2[0], buffer_mp2[1], 1, 91, 12.09857, 1, 155, 24.19714); } #endif /*** TODO: self-tangencies for difference test_one<polygon, polygon, polygon>("wrapped_a", wrapped[0], wrapped[1], 3, 1, 61, 1, 0, 13); test_one<polygon, polygon, polygon>("wrapped_b", wrapped[0], wrapped[2], 3, 1, 61, 1, 0, 13); ***/ // Isovist - the # output polygons differ per compiler/pointtype, (very) small // rings might be discarded. We check area only test_one<polygon, polygon, polygon>("isovist", isovist1[0], isovist1[1], -1, -1, 0.279132, -1, -1, 224.8892, #if defined(BOOST_GEOMETRY_NO_ROBUSTNESS) tolerance(0.1)); #else tolerance(0.001)); #endif // SQL Server gives: 0.279121891701124 and 224.889211358929 // PostGIS gives: 0.279121991127244 and 224.889205853156 // No robustness gives: 0.279121991127106 and 224.825363749290 #ifdef BOOST_GEOMETRY_TEST_INCLUDE_FAILING_TESTS test_one<polygon, polygon, polygon>("geos_1", geos_1[0], geos_1[1], 21, -1, 0.31640625, 9, -1, 0.01953125); // Excluded this test in the normal suite, it is OK like this for many clang/gcc/msvc // versions, but NOT OK for many other clang/gcc/msvc versions on other platforms // It might depend on partition (order) // 10, -1, 0.02148439); // change in partition might give these results // SQL Server gives: 0.28937764436705 and 0.000786406897532288 with 44/35 rings // PostGIS gives: 0.30859375 and 0.033203125 with 35/35 rings #endif #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) test_one<polygon, polygon, polygon>("geos_2", geos_2[0], geos_2[1], 1, -1, 138.6923828, 1, -1, 211.859375, tolerance(0.01)); // MSVC 14 expects 138.69214 and 211.85913 test_one<polygon, polygon, polygon>("geos_3", geos_3[0], geos_3[1], 1, -1, 16211128.5, 1, -1, 13180420.0, 1, -1, 16211128.5 + 13180420.0); #endif test_one<polygon, polygon, polygon>("geos_4", geos_4[0], geos_4[1], 1, -1, 971.9163115, 1, -1, 1332.4163115); test_one<polygon, polygon, polygon>("ggl_list_20110306_javier", ggl_list_20110306_javier[0], ggl_list_20110306_javier[1], 1, -1, 71495.3331, 2, -1, 8960.49049, 2, -1, 71495.3331 + 8960.49049); test_one<polygon, polygon, polygon>("ggl_list_20110307_javier", ggl_list_20110307_javier[0], ggl_list_20110307_javier[1], 1, if_typed<ct, float>(14, 13), 16815.6, 1, 4, 3200.4, tolerance(0.01)); if ( BOOST_GEOMETRY_CONDITION((! boost::is_same<ct, float>::value)) ) { test_one<polygon, polygon, polygon>("ggl_list_20110716_enrico", ggl_list_20110716_enrico[0], ggl_list_20110716_enrico[1], 3, -1, 35723.8506317139, 1, -1, 58456.4964294434, 1, -1, 35723.8506317139 + 58456.4964294434); } #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) test_one<polygon, polygon, polygon>("ggl_list_20110820_christophe", ggl_list_20110820_christophe[0], ggl_list_20110820_christophe[1], 1, -1, 2.8570121719168924, 1, -1, 64.498061986388564); #endif test_one<polygon, polygon, polygon>("ggl_list_20120717_volker", ggl_list_20120717_volker[0], ggl_list_20120717_volker[1], 1, 11, 3370866.2295081965, 1, 5, 384.2295081964694, tolerance(0.01)); #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) // 2011-07-02 / 2014-06-19 // Interesting FP-precision case. // sql server gives: 6.62295817619452E-05 // PostGIS gives: 0.0 (no output) // Boost.Geometry gave results depending on FP-type, and compiler, and operating system. // Since rescaling to integer results are equal w.r.t. compiler/FP type, // however, some long spikes are still generated in the resulting difference test_one<polygon, polygon, polygon>("ggl_list_20110627_phillip", ggl_list_20110627_phillip[0], ggl_list_20110627_phillip[1], if_typed_tt<ct>(1, 1), -1, if_typed_tt<ct>(0.0000000000001105367, 0.000125137888971949), 1, -1, 3577.40960816756, tolerance(0.01) ); #endif // Ticket 8310, one should be completely subtracted from the other. test_one<polygon, polygon, polygon>("ticket_8310a", ticket_8310a[0], ticket_8310a[1], 1, 10, 10.11562724, 0, 0, 0); test_one<polygon, polygon, polygon>("ticket_8310b", ticket_8310b[0], ticket_8310b[1], 1, 10, 10.12655608, 0, 0, 0); test_one<polygon, polygon, polygon>("ticket_8310c", ticket_8310c[0], ticket_8310c[1], 1, 10, 10.03103292, 0, 0, 0); #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) test_one<polygon, polygon, polygon>("ticket_9081_15", ticket_9081_15[0], ticket_9081_15[1], 2, 10, 0.0334529710902111, 1, 4, 5.3469555172380723e-010); #endif test_one<polygon, polygon, polygon>("ticket_9081_314", ticket_9081_314[0], ticket_9081_314[1], 2, 12, 0.0451236449624935, 0, 0, 0); #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) test_one<polygon, polygon, polygon>("ticket_9563", ticket_9563[0], ticket_9563[1], 0, 0, 0, 6, 24, 20.096189); test_one<polygon, polygon, polygon>("ticket_10108_a", ticket_10108_a[0], ticket_10108_a[1], 1, 4, 0.0145037, 1, 4, 0.029019232); test_one<polygon, polygon, polygon>("ticket_10108_b", ticket_10108_b[0], ticket_10108_b[1], 1, 5, 1081.68697, 1, 5, 1342.65795); #endif // From assemble-test, with a u/u case test_one<polygon, polygon, polygon>("assemble_0210", "POLYGON((0 0,0 10,10 10,10 0,0 0),(8.5 1,9.5 1,9.5 2,8.5 2,8.5 1))", "POLYGON((2 0.5,0.5 2,0.5 8,2 9.5,6 9.5,8.5 8,8.5 2,7 0.5,2 0.5),(2 2,7 2,7 8,2 8,2 2))", 2, 23, 62.25, 0, 0, 0.0); // Other combi's { test_one<polygon, polygon, ring>( "star_ring_ring", example_star, example_ring, 5, 22, 1.1901714, 5, 27, 1.6701714); test_one<polygon, ring, polygon>( "ring_star_ring", example_ring, example_star, 5, 27, 1.6701714, 5, 22, 1.1901714); static std::string const clip = "POLYGON((2.5 0.5,5.5 2.5))"; test_one<polygon, box, ring>("star_box", clip, example_star, 4, 20, 2.833333, 4, 16, 0.833333); test_one<polygon, ring, box>("box_star", example_star, clip, 4, 16, 0.833333, 4, 20, 2.833333); } // Counter clockwise { typedef bg::model::polygon<P, false> polygon_ccw; test_one<polygon, polygon_ccw, polygon_ccw>( "star_ring_ccw", example_star, example_ring, 5, 22, 1.1901714, 5, 27, 1.6701714); test_one<polygon, polygon, polygon_ccw>( "star_ring_ccw1", example_star, example_ring, 5, 22, 1.1901714, 5, 27, 1.6701714); test_one<polygon, polygon_ccw, polygon>( "star_ring_ccw2", example_star, example_ring, 5, 22, 1.1901714, 5, 27, 1.6701714); } // Multi/box (should be moved to multi) { typedef bg::model::multi_polygon<polygon> mp; static std::string const clip = "POLYGON((2 2,4 4))"; test_one<polygon, box, mp>("simplex_multi_box_mp", clip, case_multi_simplex[0], 2, -1, 0.53333333333, 3, -1, 8.53333333333); test_one<polygon, mp, box>("simplex_multi_mp_box", case_multi_simplex[0], clip, 3, -1, 8.53333333333, 2, -1, 0.53333333333); } /*** Experimental (cut), does not work: test_one<polygon, polygon, polygon>( "polygon_pseudo_line", "POLYGON((0 0,0 4,4 4,4 0,0 0))", "POLYGON((2 -2,2 -1,2 6,2 -2))", 5, 22, 1.1901714, 5, 27, 1.6701714); ***/ #ifdef BOOST_GEOMETRY_TEST_INCLUDE_FAILING_TESTS test_one<polygon, polygon, polygon>("ticket_11725_2", ticket_11725_2[0], ticket_11725_2[1], 2, -1, 7.5, 0, -1, 0.0); test_one<polygon, polygon, polygon>("mysql_21977775", mysql_21977775[0], mysql_21977775[1], 2, -1, 160.856568913, 2, -1, 92.3565689126); #endif test_one<polygon, polygon, polygon>("mysql_21965285", mysql_21965285[0], mysql_21965285[1], 1, -1, 92.0, 1, -1, 14.0, 1, -1, 92.0 + 14.0); }