12 #include <gtest/gtest.h> 20 using std::numeric_limits;
24 TEST(PositionFromIndex, Simple)
26 Length mapLength(3.0, 2.0);
28 double resolution = 1.0;
29 Size bufferSize(3, 2);
33 EXPECT_DOUBLE_EQ(1.0 + mapPosition.x(), position.x());
34 EXPECT_DOUBLE_EQ(0.5 + mapPosition.y(), position.y());
37 EXPECT_DOUBLE_EQ(0.0 + mapPosition.x(), position.x());
38 EXPECT_DOUBLE_EQ(0.5 + mapPosition.y(), position.y());
41 EXPECT_DOUBLE_EQ(0.0 + mapPosition.x(), position.x());
42 EXPECT_DOUBLE_EQ(-0.5 + mapPosition.y(), position.y());
45 EXPECT_DOUBLE_EQ(-1.0 + mapPosition.x(), position.x());
46 EXPECT_DOUBLE_EQ(-0.5 + mapPosition.y(), position.y());
51 TEST(PositionFromIndex, CircularBuffer)
53 Length mapLength(0.5, 0.4);
55 double resolution = 0.1;
56 Size bufferSize(5, 4);
57 Index bufferStartIndex(3, 1);
60 EXPECT_TRUE(
getPositionFromIndex(position,
Index(3, 1), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
61 EXPECT_DOUBLE_EQ(0.2 + mapPosition.x(), position.x());
62 EXPECT_DOUBLE_EQ(0.15 + mapPosition.y(), position.y());
64 EXPECT_TRUE(
getPositionFromIndex(position,
Index(4, 2), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
65 EXPECT_DOUBLE_EQ(0.1 + mapPosition.x(), position.x());
66 EXPECT_DOUBLE_EQ(0.05 + mapPosition.y(), position.y());
68 EXPECT_TRUE(
getPositionFromIndex(position,
Index(2, 0), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
69 EXPECT_DOUBLE_EQ(-0.2 + mapPosition.x(), position.x());
70 EXPECT_DOUBLE_EQ(-0.15 + mapPosition.y(), position.y());
72 EXPECT_TRUE(
getPositionFromIndex(position,
Index(0, 0), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
73 EXPECT_DOUBLE_EQ(0.0 + mapPosition.x(), position.x());
74 EXPECT_DOUBLE_EQ(-0.15 + mapPosition.y(), position.y());
76 EXPECT_TRUE(
getPositionFromIndex(position,
Index(4, 3), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
77 EXPECT_DOUBLE_EQ(0.1 + mapPosition.x(), position.x());
78 EXPECT_DOUBLE_EQ(-0.05 + mapPosition.y(), position.y());
80 EXPECT_FALSE(
getPositionFromIndex(position,
Index(5, 3), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
83 TEST(IndexFromPosition, Simple)
85 Length mapLength(3.0, 2.0);
87 double resolution = 1.0;
88 Index bufferSize(3, 2);
92 EXPECT_EQ(0, index(0));
93 EXPECT_EQ(0, index(1));
96 EXPECT_EQ(2, index(0));
97 EXPECT_EQ(1, index(1));
100 EXPECT_EQ(0, index(0));
101 EXPECT_EQ(0, index(1));
104 EXPECT_EQ(1, index(0));
105 EXPECT_EQ(1, index(1));
108 EXPECT_EQ(1, index(0));
109 EXPECT_EQ(0, index(1));
114 TEST(IndexFromPosition, EdgeCases)
116 Length mapLength(3.0, 2.0);
118 double resolution = 1.0;
119 Size bufferSize(3, 2);
123 EXPECT_EQ(1, index(0));
124 EXPECT_EQ(0, index(1));
127 EXPECT_EQ(1, index(0));
128 EXPECT_EQ(1, index(1));
131 EXPECT_EQ(2, index(0));
132 EXPECT_EQ(1, index(1));
137 TEST(IndexFromPosition, CircularBuffer)
139 Length mapLength(0.5, 0.4);
141 double resolution = 0.1;
142 Size bufferSize(5, 4);
143 Index bufferStartIndex(3, 1);
146 EXPECT_TRUE(
getIndexFromPosition(index,
Position(0.2, 0.15) + mapPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
147 EXPECT_EQ(3, index(0));
148 EXPECT_EQ(1, index(1));
150 EXPECT_TRUE(
getIndexFromPosition(index,
Position(0.03, -0.17) + mapPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
151 EXPECT_EQ(0, index(0));
152 EXPECT_EQ(0, index(1));
157 Length mapLength(50.0, 25.0);
170 Length mapLength(10.0, 5.0);
182 Length mapLength(2.0, 3.0);
249 double resolution = 1.0;
253 EXPECT_EQ(0, indexShift(0));
254 EXPECT_EQ(0, indexShift(1));
257 EXPECT_EQ(0, indexShift(0));
258 EXPECT_EQ(0, indexShift(1));
261 EXPECT_EQ(-1, indexShift(0));
262 EXPECT_EQ(0, indexShift(1));
265 EXPECT_EQ(1, indexShift(0));
266 EXPECT_EQ(3, indexShift(1));
269 EXPECT_EQ(2, indexShift(0));
270 EXPECT_EQ(0, indexShift(1));
275 double resolution = 0.3;
279 EXPECT_DOUBLE_EQ(0.0, positionShift.x());
280 EXPECT_DOUBLE_EQ(0.0, positionShift.y());
283 EXPECT_DOUBLE_EQ(-0.3, positionShift.x());
284 EXPECT_DOUBLE_EQ(0.3, positionShift.y());
287 EXPECT_DOUBLE_EQ(-0.6, positionShift.x());
288 EXPECT_DOUBLE_EQ(-0.3, positionShift.y());
293 Size bufferSize(10, 15);
378 double epsilon = 11.0 * numeric_limits<double>::epsilon();
380 Length mapLength(30.0, 10.0);
384 position << 0.0, 0.0;
386 EXPECT_DOUBLE_EQ(0.0, position.x());
387 EXPECT_DOUBLE_EQ(0.0, position.y());
389 position << 15.0, 5.0;
391 EXPECT_NEAR(15.0, position.x(), 15.0 * epsilon);
392 EXPECT_GE(15.0, position.x());
393 EXPECT_NEAR(5.0, position.y(), 5.0 * epsilon);
394 EXPECT_GE(5.0, position.y());
396 position << -15.0, -5.0;
398 EXPECT_NEAR(-15.0, position.x(), 15.0 * epsilon);
399 EXPECT_LE(-15.0, position.x());
400 EXPECT_NEAR(-5.0, position.y(), 5.0 * epsilon);
401 EXPECT_LE(-5.0, position.y());
403 position << 16.0, 6.0;
405 EXPECT_NEAR(15.0, position.x(), 16.0 * epsilon);
406 EXPECT_GE(15.0, position.x());
407 EXPECT_NEAR(5.0, position.y(), 6.0 * epsilon);
408 EXPECT_GE(5.0, position.y());
410 position << -16.0, -6.0;
412 EXPECT_NEAR(-15.0, position.x(), 16.0 * epsilon);
413 EXPECT_LE(-15.0, position.x());
414 EXPECT_NEAR(-5.0, position.y(), 6.0 * epsilon);
415 EXPECT_LE(-5.0, position.y());
417 position << 1e6, 1e6;
419 EXPECT_NEAR(15.0, position.x(), 1e6 * epsilon);
420 EXPECT_GE(15.0, position.x());
421 EXPECT_NEAR(5.0, position.y(), 1e6 * epsilon);
422 EXPECT_GE(5.0, position.y());
424 position << -1e6, -1e6;
426 EXPECT_NEAR(-15.0, position.x(), 1e6 * epsilon);
427 EXPECT_LE(-15.0, position.x());
428 EXPECT_NEAR(-5.0, position.y(), 1e6 * epsilon);
429 EXPECT_LE(-5.0, position.y());
434 double epsilon = 11.0 * numeric_limits<double>::epsilon();
436 Length mapLength(30.0, 10.0);
440 position << 0.0, 0.0;
442 EXPECT_DOUBLE_EQ(0.0, position.x());
443 EXPECT_DOUBLE_EQ(0.0, position.y());
445 position << 16.0, 7.0;
447 EXPECT_NEAR(16.0, position.x(), 16.0 * epsilon);
448 EXPECT_GE(16.0, position.x());
449 EXPECT_NEAR(7.0, position.y(), 7.0 * epsilon);
450 EXPECT_GE(7.0, position.y());
452 position << -14.0, -3.0;
454 EXPECT_NEAR(-14.0, position.x(), 14.0 * epsilon);
455 EXPECT_LE(-14.0, position.x());
456 EXPECT_NEAR(-3.0, position.y(), 3.0 * epsilon);
457 EXPECT_LE(-3.0, position.y());
459 position << 17.0, 8.0;
461 EXPECT_NEAR(16.0, position.x(), 17.0 * epsilon);
462 EXPECT_GE(16.0, position.x());
463 EXPECT_NEAR(7.0, position.y(), 8.0 * epsilon);
464 EXPECT_GE(7.0, position.y());
466 position << -15.0, -4.0;
468 EXPECT_NEAR(-14.0, position.x(), 15.0 * epsilon);
469 EXPECT_LE(-14.0, position.x());
470 EXPECT_NEAR(-3.0, position.y(), 4.0 * epsilon);
471 EXPECT_LE(-3.0, position.y());
473 position << 1e6, 1e6;
475 EXPECT_NEAR(16.0, position.x(), 1e6 * epsilon);
476 EXPECT_GE(16.0, position.x());
477 EXPECT_NEAR(7.0, position.y(), 1e6 * epsilon);
478 EXPECT_GE(7.0, position.y());
480 position << -1e6, -1e6;
482 EXPECT_NEAR(-14.0, position.x(), 1e6 * epsilon);
483 EXPECT_LE(-14.0, position.x());
484 EXPECT_NEAR(-3.0, position.y(), 1e6 * epsilon);
485 EXPECT_LE(-3.0, position.y());
491 Length mapLength(5.0, 4.0);
493 double resolution = 1.0;
494 Size bufferSize(5, 4);
501 Index submapTopLeftIndex;
505 Index requestedIndexInSubmap;
507 requestedSubmapPosition << 0.0, 0.5;
508 requestedSubmapLength << 0.9, 2.9;
509 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
510 requestedSubmapPosition, requestedSubmapLength, mapLength, mapPosition, resolution, bufferSize));
511 EXPECT_EQ(2, submapTopLeftIndex(0));
512 EXPECT_EQ(0, submapTopLeftIndex(1));
513 EXPECT_EQ(1, submapSize(0));
514 EXPECT_EQ(3, submapSize(1));
515 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
516 EXPECT_DOUBLE_EQ(0.5, submapPosition.y());
517 EXPECT_DOUBLE_EQ(1.0, submapLength(0));
518 EXPECT_DOUBLE_EQ(3.0, submapLength(1));
519 EXPECT_EQ(0, requestedIndexInSubmap(0));
520 EXPECT_EQ(1, requestedIndexInSubmap(1));
526 Length mapLength(5.0, 4.0);
528 double resolution = 1.0;
529 Size bufferSize(5, 4);
533 Length requestedSubmapLength;
536 Index submapTopLeftIndex;
540 Index requestedIndexInSubmap;
542 requestedSubmapPosition << -1.0, -0.5;
543 requestedSubmapLength << 0.0, 0.0;
544 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
545 requestedSubmapPosition, requestedSubmapLength,
546 mapLength, mapPosition, resolution, bufferSize));
547 EXPECT_EQ(3, submapTopLeftIndex(0));
548 EXPECT_EQ(2, submapTopLeftIndex(1));
549 EXPECT_EQ(1, submapSize(0));
550 EXPECT_EQ(1, submapSize(1));
551 EXPECT_DOUBLE_EQ(requestedSubmapPosition.x(), submapPosition.x());
552 EXPECT_DOUBLE_EQ(requestedSubmapPosition.y(), submapPosition.y());
553 EXPECT_DOUBLE_EQ(resolution, submapLength(0));
554 EXPECT_DOUBLE_EQ(resolution, submapLength(1));
555 EXPECT_EQ(0, requestedIndexInSubmap(0));
556 EXPECT_EQ(0, requestedIndexInSubmap(1));
562 Length mapLength(5.0, 4.0);
564 double resolution = 1.0;
565 Size bufferSize(5, 4);
569 Length requestedSubmapLength;
572 Index submapTopLeftIndex;
576 Index requestedIndexInSubmap;
578 requestedSubmapPosition << 2.0, 1.5;
579 requestedSubmapLength << 2.9, 2.9;
580 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
581 requestedSubmapPosition, requestedSubmapLength,
582 mapLength, mapPosition, resolution, bufferSize));
583 EXPECT_EQ(0, submapTopLeftIndex(0));
584 EXPECT_EQ(0, submapTopLeftIndex(1));
585 EXPECT_EQ(2, submapSize(0));
586 EXPECT_EQ(2, submapSize(1));
587 EXPECT_DOUBLE_EQ(1.5, submapPosition.x());
588 EXPECT_DOUBLE_EQ(1.0, submapPosition.y());
589 EXPECT_DOUBLE_EQ(2.0, submapLength(0));
590 EXPECT_DOUBLE_EQ(2.0, submapLength(1));
591 EXPECT_EQ(0, requestedIndexInSubmap(0));
592 EXPECT_EQ(0, requestedIndexInSubmap(1));
594 requestedSubmapPosition << 0.0, 0.0;
595 requestedSubmapLength << 1e6, 1e6;
596 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
597 requestedSubmapPosition, requestedSubmapLength,
598 mapLength, mapPosition, resolution, bufferSize));
599 EXPECT_EQ(0, submapTopLeftIndex(0));
600 EXPECT_EQ(0, submapTopLeftIndex(1));
601 EXPECT_EQ(bufferSize(0), submapSize(0));
602 EXPECT_EQ(bufferSize(1), submapSize(1));
603 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
604 EXPECT_DOUBLE_EQ(0.0, submapPosition.y());
605 EXPECT_DOUBLE_EQ(mapLength(0), submapLength(0));
606 EXPECT_DOUBLE_EQ(mapLength(1), submapLength(1));
607 EXPECT_EQ(2, requestedIndexInSubmap(0));
608 EXPECT_LE(1, requestedIndexInSubmap(1));
609 EXPECT_GE(2, requestedIndexInSubmap(1));
615 Length mapLength(5.0, 4.0);
617 double resolution = 1.0;
618 Size bufferSize(5, 4);
619 Index bufferStartIndex(2, 1);
623 Length requestedSubmapLength;
626 Index submapTopLeftIndex;
630 Index requestedIndexInSubmap;
632 requestedSubmapPosition << 0.0, 0.5;
633 requestedSubmapLength << 0.9, 2.9;
634 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
635 requestedSubmapPosition, requestedSubmapLength,
636 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
637 EXPECT_EQ(4, submapTopLeftIndex(0));
638 EXPECT_EQ(1, submapTopLeftIndex(1));
639 EXPECT_EQ(1, submapSize(0));
640 EXPECT_EQ(3, submapSize(1));
641 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
642 EXPECT_DOUBLE_EQ(0.5, submapPosition.y());
643 EXPECT_DOUBLE_EQ(1.0, submapLength(0));
644 EXPECT_DOUBLE_EQ(3.0, submapLength(1));
645 EXPECT_EQ(0, requestedIndexInSubmap(0));
646 EXPECT_EQ(1, requestedIndexInSubmap(1));
648 requestedSubmapPosition << 2.0, 1.5;
649 requestedSubmapLength << 2.9, 2.9;
650 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
651 requestedSubmapPosition, requestedSubmapLength,
652 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
653 EXPECT_EQ(2, submapTopLeftIndex(0));
654 EXPECT_EQ(1, submapTopLeftIndex(1));
655 EXPECT_EQ(2, submapSize(0));
656 EXPECT_EQ(2, submapSize(1));
657 EXPECT_DOUBLE_EQ(1.5, submapPosition.x());
658 EXPECT_DOUBLE_EQ(1.0, submapPosition.y());
659 EXPECT_DOUBLE_EQ(2.0, submapLength(0));
660 EXPECT_DOUBLE_EQ(2.0, submapLength(1));
661 EXPECT_EQ(0, requestedIndexInSubmap(0));
662 EXPECT_EQ(0, requestedIndexInSubmap(1));
664 requestedSubmapPosition << 0.0, 0.0;
665 requestedSubmapLength << 1e6, 1e6;
666 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
667 requestedSubmapPosition, requestedSubmapLength,
668 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
669 EXPECT_EQ(2, submapTopLeftIndex(0));
670 EXPECT_EQ(1, submapTopLeftIndex(1));
671 EXPECT_EQ(bufferSize(0), submapSize(0));
672 EXPECT_EQ(bufferSize(1), submapSize(1));
673 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
674 EXPECT_DOUBLE_EQ(0.0, submapPosition.y());
675 EXPECT_DOUBLE_EQ(mapLength(0), submapLength(0));
676 EXPECT_DOUBLE_EQ(mapLength(1), submapLength(1));
677 EXPECT_EQ(2, requestedIndexInSubmap(0));
678 EXPECT_LE(1, requestedIndexInSubmap(1));
679 EXPECT_GE(2, requestedIndexInSubmap(1));
685 Length mapLength(4.98, 4.98);
687 double resolution = 0.06;
688 Size bufferSize(83, 83);
689 Index bufferStartIndex(0, 13);
692 Position requestedSubmapPosition(-7.44, -3.42);
693 Length requestedSubmapLength(0.12, 0.12);
696 Index submapTopLeftIndex;
700 Index requestedIndexInSubmap;
702 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
703 requestedSubmapPosition, requestedSubmapLength,
704 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
705 EXPECT_EQ(2, submapSize(0));
706 EXPECT_EQ(3, submapSize(1));
707 EXPECT_DOUBLE_EQ(0.12, submapLength(0));
708 EXPECT_DOUBLE_EQ(0.18, submapLength(1));
714 Length mapLength(4.98, 4.98);
716 double resolution = 0.06;
717 Size bufferSize(83, 83);
718 Index bufferStartIndex(42, 6);
721 Position requestedSubmapPosition(0.24, -26.82);
722 Length requestedSubmapLength(0.624614, 0.462276);
725 Index submapTopLeftIndex;
729 Index requestedIndexInSubmap;
731 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
732 requestedSubmapPosition, requestedSubmapLength,
733 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
734 EXPECT_LT(0, submapSize(0));
735 EXPECT_LT(0, submapSize(1));
736 EXPECT_LT(0.0, submapLength(0));
737 EXPECT_LT(0.0, submapLength(1));
742 Size bufferSize(5, 4);
743 Index submapIndex(0, 0);
744 Size submapSize(0, 0);
745 std::vector<BufferRegion> regions;
748 EXPECT_EQ(1, regions.size());
750 EXPECT_EQ(0, regions[0].getStartIndex()[0]);
751 EXPECT_EQ(0, regions[0].getStartIndex()[1]);
752 EXPECT_EQ(0, regions[0].getSize()[0]);
753 EXPECT_EQ(0, regions[0].getSize()[1]);
764 Size bufferSize(5, 4);
765 Index submapIndex(1, 2);
766 Size submapSize(3, 2);
767 std::vector<BufferRegion> regions;
770 EXPECT_EQ(1, regions.size());
772 EXPECT_EQ(1, regions[0].getStartIndex()[0]);
773 EXPECT_EQ(2, regions[0].getStartIndex()[1]);
774 EXPECT_EQ(3, regions[0].getSize()[0]);
775 EXPECT_EQ(2, regions[0].getSize()[1]);
780 Size bufferSize(5, 4);
783 Index bufferStartIndex(3, 1);
784 std::vector<BufferRegion> regions;
789 EXPECT_EQ(1, regions.size());
791 EXPECT_EQ(3, regions[0].getStartIndex()[0]);
792 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
793 EXPECT_EQ(2, regions[0].getSize()[0]);
794 EXPECT_EQ(3, regions[0].getSize()[1]);
799 EXPECT_EQ(2, regions.size());
801 EXPECT_EQ(4, regions[0].getStartIndex()[0]);
802 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
803 EXPECT_EQ(1, regions[0].getSize()[0]);
804 EXPECT_EQ(3, regions[0].getSize()[1]);
806 EXPECT_EQ(0, regions[1].getStartIndex()[0]);
807 EXPECT_EQ(1, regions[1].getStartIndex()[1]);
808 EXPECT_EQ(1, regions[1].getSize()[0]);
809 EXPECT_EQ(3, regions[1].getSize()[1]);
814 EXPECT_EQ(1, regions.size());
816 EXPECT_EQ(1, regions[0].getStartIndex()[0]);
817 EXPECT_EQ(0, regions[0].getStartIndex()[1]);
818 EXPECT_EQ(2, regions[0].getSize()[0]);
819 EXPECT_EQ(1, regions[0].getSize()[1]);
824 EXPECT_EQ(4, regions.size());
826 EXPECT_EQ(3, regions[0].getStartIndex()[0]);
827 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
828 EXPECT_EQ(2, regions[0].getSize()[0]);
829 EXPECT_EQ(3, regions[0].getSize()[1]);
831 EXPECT_EQ(3, regions[1].getStartIndex()[0]);
832 EXPECT_EQ(0, regions[1].getStartIndex()[1]);
833 EXPECT_EQ(2, regions[1].getSize()[0]);
834 EXPECT_EQ(1, regions[1].getSize()[1]);
836 EXPECT_EQ(0, regions[2].getStartIndex()[0]);
837 EXPECT_EQ(1, regions[2].getStartIndex()[1]);
838 EXPECT_EQ(3, regions[2].getSize()[0]);
839 EXPECT_EQ(3, regions[2].getSize()[1]);
841 EXPECT_EQ(0, regions[3].getStartIndex()[0]);
842 EXPECT_EQ(0, regions[3].getStartIndex()[1]);
843 EXPECT_EQ(3, regions[3].getSize()[0]);
844 EXPECT_EQ(1, regions[3].getSize()[1]);
847 TEST(checkIncrementIndex, Simple)
850 Size bufferSize(4, 3);
853 EXPECT_EQ(0, index[0]);
854 EXPECT_EQ(1, index[1]);
857 EXPECT_EQ(0, index[0]);
858 EXPECT_EQ(2, index[1]);
861 EXPECT_EQ(1, index[0]);
862 EXPECT_EQ(0, index[1]);
865 EXPECT_EQ(1, index[0]);
866 EXPECT_EQ(1, index[1]);
868 for (
int i = 0; i < 6; i++) {
871 EXPECT_EQ(3, index[0]);
872 EXPECT_EQ(1, index[1]);
875 EXPECT_EQ(3, index[0]);
876 EXPECT_EQ(2, index[1]);
879 EXPECT_EQ(index[0], index[0]);
880 EXPECT_EQ(index[1], index[1]);
883 TEST(checkIncrementIndex, CircularBuffer)
885 Size bufferSize(4, 3);
886 Index bufferStartIndex(2, 1);
887 Index index(bufferStartIndex);
890 EXPECT_EQ(2, index[0]);
891 EXPECT_EQ(2, index[1]);
894 EXPECT_EQ(2, index[0]);
895 EXPECT_EQ(0, index[1]);
898 EXPECT_EQ(3, index[0]);
899 EXPECT_EQ(1, index[1]);
902 EXPECT_EQ(3, index[0]);
903 EXPECT_EQ(2, index[1]);
906 EXPECT_EQ(3, index[0]);
907 EXPECT_EQ(0, index[1]);
910 EXPECT_EQ(0, index[0]);
911 EXPECT_EQ(1, index[1]);
914 EXPECT_EQ(0, index[0]);
915 EXPECT_EQ(2, index[1]);
918 EXPECT_EQ(0, index[0]);
919 EXPECT_EQ(0, index[1]);
922 EXPECT_EQ(1, index[0]);
923 EXPECT_EQ(1, index[1]);
926 EXPECT_EQ(1, index[0]);
927 EXPECT_EQ(2, index[1]);
930 EXPECT_EQ(1, index[0]);
931 EXPECT_EQ(0, index[1]);
933 EXPECT_FALSE(
incrementIndex(index, bufferSize, bufferStartIndex));
934 EXPECT_EQ(index[0], index[0]);
935 EXPECT_EQ(index[1], index[1]);
938 TEST(checkIncrementIndexForSubmap, Simple)
940 Index submapIndex(0, 0);
942 Index submapTopLeftIndex(3, 1);
943 Size submapBufferSize(2, 4);
944 Size bufferSize(8, 5);
947 EXPECT_EQ(0, submapIndex[0]);
948 EXPECT_EQ(1, submapIndex[1]);
949 EXPECT_EQ(3, index[0]);
950 EXPECT_EQ(2, index[1]);
953 EXPECT_EQ(0, submapIndex[0]);
954 EXPECT_EQ(2, submapIndex[1]);
955 EXPECT_EQ(3, index[0]);
956 EXPECT_EQ(3, index[1]);
959 EXPECT_EQ(0, submapIndex[0]);
960 EXPECT_EQ(3, submapIndex[1]);
961 EXPECT_EQ(3, index[0]);
962 EXPECT_EQ(4, index[1]);
965 EXPECT_EQ(1, submapIndex[0]);
966 EXPECT_EQ(0, submapIndex[1]);
967 EXPECT_EQ(4, index[0]);
968 EXPECT_EQ(1, index[1]);
972 EXPECT_EQ(1, submapIndex[0]);
973 EXPECT_EQ(3, submapIndex[1]);
974 EXPECT_EQ(4, index[0]);
975 EXPECT_EQ(4, index[1]);
983 TEST(checkIncrementIndexForSubmap, CircularBuffer)
985 Index submapIndex(0, 0);
987 Index submapTopLeftIndex(6, 3);
988 Size submapBufferSize(2, 4);
989 Size bufferSize(8, 5);
990 Index bufferStartIndex(3, 2);
992 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
993 EXPECT_EQ(0, submapIndex[0]);
994 EXPECT_EQ(1, submapIndex[1]);
995 EXPECT_EQ(6, index[0]);
996 EXPECT_EQ(4, index[1]);
998 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
999 EXPECT_EQ(0, submapIndex[0]);
1000 EXPECT_EQ(2, submapIndex[1]);
1001 EXPECT_EQ(6, index[0]);
1002 EXPECT_EQ(0, index[1]);
1004 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1005 EXPECT_EQ(0, submapIndex[0]);
1006 EXPECT_EQ(3, submapIndex[1]);
1007 EXPECT_EQ(6, index[0]);
1008 EXPECT_EQ(1, index[1]);
1010 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1011 EXPECT_EQ(1, submapIndex[0]);
1012 EXPECT_EQ(0, submapIndex[1]);
1013 EXPECT_EQ(7, index[0]);
1014 EXPECT_EQ(3, index[1]);
1016 submapIndex << 1, 2;
1017 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1018 EXPECT_EQ(1, submapIndex[0]);
1019 EXPECT_EQ(3, submapIndex[1]);
1020 EXPECT_EQ(7, index[0]);
1021 EXPECT_EQ(1, index[1]);
1023 EXPECT_FALSE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1025 submapIndex << 2, 0;
1026 EXPECT_FALSE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
bool incrementIndexForSubmap(Index &submapIndex, Index &index, const Index &submapTopLeftIndex, const Size &submapBufferSize, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
void wrapIndexToRange(Index &index, const Size &bufferSize)
bool getBufferRegionsForSubmap(std::vector< BufferRegion > &submapBufferRegions, const Index &submapIndex, const Size &submapBufferSize, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
bool getSubmapInformation(Index &submapTopLeftIndex, Size &submapBufferSize, Position &submapPosition, Length &submapLength, Index &requestedIndexInSubmap, const Position &requestedSubmapPosition, const Length &requestedSubmapLength, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
bool getIndexFromPosition(Index &index, const Position &position, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
bool checkIfPositionWithinMap(const Position &position, const Length &mapLength, const Position &mapPosition)
bool getPositionShiftFromIndexShift(Vector &positionShift, const Index &indexShift, const double &resolution)
bool incrementIndex(Index &index, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
BufferRegion::Quadrant getQuadrant(const Index &index, const Index &bufferStartIndex)
void boundIndexToRange(Index &index, const Size &bufferSize)
bool checkIfIndexInRange(const Index &index, const Size &bufferSize)
bool getPositionFromIndex(Position &position, const Index &index, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
void boundPositionToRange(Position &position, const Length &mapLength, const Position &mapPosition)
bool getIndexShiftFromPositionShift(Index &indexShift, const Vector &positionShift, const double &resolution)
TEST(PositionFromIndex, Simple)
Index getIndexFromLinearIndex(size_t linearIndex, const Size &bufferSize, bool rowMajor=false)