MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / changePathBoundsTest

Method changePathBoundsTest

test/path_object_t.cpp:493–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491}
492
493void PathObjectTest::changePathBoundsTest()
494{
495 QFETCH(int, part_index);
496 QFETCH(float, start_len);
497 QFETCH(float, end_len);
498 QFETCH(int, expected_size_fwd);
499 QFETCH(int, expected_size_rev);
500
501 // For 0.0 or 1.0, products are not precise enough.
502 auto exact_length = [](float factor, float length) -> float {
503 if (factor == 0.0f)
504 return 0.0f;
505 if (factor == 1.0f)
506 return length;
507 return factor * length;
508 };
509
510 // This path is 4+3+4+4+5 = 20 units long.
511 PathObject proto{Map::getCoveringRedLine()};
512 proto.addCoordinate({0.0, 4.0});
513 proto.addCoordinate({0.0, 8.0});
514 proto.addCoordinate({3.0, 8.0});
515 proto.addCoordinate({3.0, 4.0});
516 proto.addCoordinate({3.0, 0.0});
517 proto.addCoordinate({0.0, 4.0, MapCoord::HolePoint});
518 proto.updatePathCoords();
519 auto orig_len = proto.parts().front().length();
520 QCOMPARE(orig_len, 20.0f);
521
522 // open path
523 if (start_len < end_len)
524 {
525 PathObject path{Map::getCoveringRedLine()};
526 path.copyFrom(proto);
527 path.changePathBounds(std::size_t(part_index), exact_length(start_len, orig_len), exact_length(end_len, orig_len));
528 path.updatePathCoords();
529
530 QVERIFY(!path.parts().front().isClosed());
531 QCOMPARE(int(path.getCoordinateCount()), expected_size_fwd);
532 if (end_len == start_len)
533 QCOMPARE(path.parts().front().length(), exact_length(1.0, orig_len));
534 else
535 QCOMPARE(path.parts().front().length(), exact_length(end_len - start_len, orig_len));
536
537 // First and last new coord may differ, but the sequence in between must match.
538 if (expected_size_fwd > 2)
539 {
540 auto first = begin(path.getRawCoordinateVector()) + 1;
541 auto last = end(path.getRawCoordinateVector()) - 1;
542 auto seq = std::find_end(
543 begin(proto.getRawCoordinateVector()), end(proto.getRawCoordinateVector()),
544 first, last );
545 QVERIFY(seq != end(proto.getRawCoordinateVector()));
546 }
547 }
548
549 // closed path
550 proto.getCoordinateRef(5).setClosePoint(true);

Callers

nothing calls this directly

Calls 8

updatePathCoordsMethod · 0.80
changePathBoundsMethod · 0.80
getCoordinateCountMethod · 0.80
setClosePointMethod · 0.80
addCoordinateMethod · 0.45
lengthMethod · 0.45
copyFromMethod · 0.45
isClosedMethod · 0.45

Tested by

no test coverage detected