MCPcopy Create free account
hub / github.com/AngusJohnson/Clipper2 / main

Function main

CPP/BenchMark/GetIntersectPtBenchmark.cpp:487–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485/////////////////////////////////////////////////////////
486
487int main(int argc, char** argv)
488{
489 //setup benchmarking ...
490 benchmark::Initialize(0, nullptr);
491 BENCHMARK(BM_GIP)->Apply(CustomArguments);
492
493 // the closer test segments are to collinear, the less accurate
494 // calculations will be in determining their intersection points.
495 const double min_angle_degrees = 0.5;
496 const double sine_min_angle = std::sin(min_angle_degrees *PI / 180.0);
497
498 bool first_pass = true;
499 for (int current_pow10 = 12; current_pow10 <= 18; ++current_pow10)
500 {
501 // using random coordinates that are restricted to the specified
502 // power of 10 range, create multiple TestRecords containing
503 // segment pairs that intersect at their midpoints
504 int64_t max_coord = static_cast<int64_t>(pow(10, current_pow10));
505 for (int64_t i = 0; i < 100000; ++i)
506 {
507 Point64 ip1 = MakeRandomPoint(-max_coord, max_coord);
508 Point64 ip2 = MakeRandomPoint(-max_coord, max_coord);
509 Point64 actual = MidPoint(ip1, ip2);
510 Point64 ip3 = MakeRandomPoint(-max_coord, max_coord);
511 Point64 ip4 = ReflectPoint(ip3, actual);
512
513 // Exclude segments that are **almost** collinear.
514 if (std::abs(GetSineFrom3Points(ip1, actual, ip3)) < sine_min_angle) continue;
515 // Alternatively, just exclude segments that are collinear
516 //if (!CrossProduct(ip1, actual, ip3)) continue;
517
518 tests.push_back(TestRecord(actual, ip1, ip2, ip3, ip4));
519 }
520
521 if (first_pass)
522 {
523 // only benchmark the GetIntersectPoint functions once because changing
524 // the maximum range of coordinates won't affect function performance.
525 first_pass = false;
526 std::cout << std::endl << SetConsoleTextColor(green_bold) <<
527 "Benchmark GetIntersectPoint performance ... " << SetConsoleTextColor(reset) <<
528 std::endl << std::endl;
529 benchmark::RunSpecifiedBenchmarks();
530
531 std::cout << std::endl << std::endl << SetConsoleTextColor(green_bold) <<
532 "Compare function accuracy ..." << SetConsoleTextColor(reset) << std::endl <<
533 "and show how it deteriorates when using very large coordinate ranges." << std::endl <<
534 "Distance error is the distance between the calculated and actual intersection points." << std::endl <<
535 "(The largest errors will occur whenever the segments are close to collinear.)" << std::endl;
536 }
537 else
538 {
539 for (int i = 0; i < number_of_test_functions; ++i)
540 {
541 // although we're not benchmarking, we still need to collect the calculated
542 // intersect points of each TestRecord for each participating function.
543 // (In first_pass above, benchmark::RunSpecifiedBenchmarks() does this internally.)
544 Point64 ip;

Callers

nothing calls this directly

Calls 11

MakeRandomPointFunction · 0.85
ReflectPointFunction · 0.85
GetSineFrom3PointsFunction · 0.85
TestRecordClass · 0.85
GetGipFuncFunction · 0.85
DistanceFunction · 0.85
GetGipFuncNameFunction · 0.85
SetConsoleTextColorClass · 0.70
MidPointFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected