15 #include <gtest/gtest.h> 26 TEST(PositionFromIndex, Simple)
28 Length mapLength(3.0, 2.0);
30 double resolution = 1.0;
31 Size bufferSize(3, 2);
35 EXPECT_DOUBLE_EQ(1.0 + mapPosition.x(), position.x());
36 EXPECT_DOUBLE_EQ(0.5 + mapPosition.y(), position.y());
39 EXPECT_DOUBLE_EQ(0.0 + mapPosition.x(), position.x());
40 EXPECT_DOUBLE_EQ(0.5 + mapPosition.y(), position.y());
43 EXPECT_DOUBLE_EQ(0.0 + mapPosition.x(), position.x());
44 EXPECT_DOUBLE_EQ(-0.5 + mapPosition.y(), position.y());
47 EXPECT_DOUBLE_EQ(-1.0 + mapPosition.x(), position.x());
48 EXPECT_DOUBLE_EQ(-0.5 + mapPosition.y(), position.y());
53 TEST(PositionFromIndex, CircularBuffer)
55 Length mapLength(0.5, 0.4);
57 double resolution = 0.1;
58 Size bufferSize(5, 4);
59 Index bufferStartIndex(3, 1);
62 EXPECT_TRUE(
getPositionFromIndex(position,
Index(3, 1), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
63 EXPECT_DOUBLE_EQ(0.2 + mapPosition.x(), position.x());
64 EXPECT_DOUBLE_EQ(0.15 + mapPosition.y(), position.y());
66 EXPECT_TRUE(
getPositionFromIndex(position,
Index(4, 2), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
67 EXPECT_DOUBLE_EQ(0.1 + mapPosition.x(), position.x());
68 EXPECT_DOUBLE_EQ(0.05 + mapPosition.y(), position.y());
70 EXPECT_TRUE(
getPositionFromIndex(position,
Index(2, 0), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
71 EXPECT_DOUBLE_EQ(-0.2 + mapPosition.x(), position.x());
72 EXPECT_DOUBLE_EQ(-0.15 + mapPosition.y(), position.y());
74 EXPECT_TRUE(
getPositionFromIndex(position,
Index(0, 0), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
75 EXPECT_DOUBLE_EQ(0.0 + mapPosition.x(), position.x());
76 EXPECT_DOUBLE_EQ(-0.15 + mapPosition.y(), position.y());
78 EXPECT_TRUE(
getPositionFromIndex(position,
Index(4, 3), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
79 EXPECT_DOUBLE_EQ(0.1 + mapPosition.x(), position.x());
80 EXPECT_DOUBLE_EQ(-0.05 + mapPosition.y(), position.y());
82 EXPECT_FALSE(
getPositionFromIndex(position,
Index(5, 3), mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
85 TEST(IndexFromPosition, Simple)
87 Length mapLength(3.0, 2.0);
89 double resolution = 1.0;
90 Index bufferSize(3, 2);
94 EXPECT_EQ(0, index(0));
95 EXPECT_EQ(0, index(1));
98 EXPECT_EQ(2, index(0));
99 EXPECT_EQ(1, index(1));
102 EXPECT_EQ(0, index(0));
103 EXPECT_EQ(0, index(1));
106 EXPECT_EQ(1, index(0));
107 EXPECT_EQ(1, index(1));
110 EXPECT_EQ(1, index(0));
111 EXPECT_EQ(0, index(1));
116 TEST(IndexFromPosition, EdgeCases)
118 Length mapLength(3.0, 2.0);
120 double resolution = 1.0;
121 Size bufferSize(3, 2);
125 EXPECT_EQ(1, index(0));
126 EXPECT_EQ(0, index(1));
129 EXPECT_EQ(1, index(0));
130 EXPECT_EQ(1, index(1));
133 EXPECT_EQ(2, index(0));
134 EXPECT_EQ(1, index(1));
139 TEST(IndexFromPosition, CircularBuffer)
141 Length mapLength(0.5, 0.4);
143 double resolution = 0.1;
144 Size bufferSize(5, 4);
145 Index bufferStartIndex(3, 1);
148 EXPECT_TRUE(
getIndexFromPosition(index,
Position(0.2, 0.15) + mapPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
149 EXPECT_EQ(3, index(0));
150 EXPECT_EQ(1, index(1));
152 EXPECT_TRUE(
getIndexFromPosition(index,
Position(0.03, -0.17) + mapPosition, mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
153 EXPECT_EQ(0, index(0));
154 EXPECT_EQ(0, index(1));
159 Length mapLength(50.0, 25.0);
172 Length mapLength(10.0, 5.0);
184 Length mapLength(2.0, 3.0);
251 double resolution = 1.0;
255 EXPECT_EQ(0, indexShift(0));
256 EXPECT_EQ(0, indexShift(1));
259 EXPECT_EQ(0, indexShift(0));
260 EXPECT_EQ(0, indexShift(1));
263 EXPECT_EQ(-1, indexShift(0));
264 EXPECT_EQ(0, indexShift(1));
267 EXPECT_EQ(1, indexShift(0));
268 EXPECT_EQ(3, indexShift(1));
271 EXPECT_EQ(2, indexShift(0));
272 EXPECT_EQ(0, indexShift(1));
277 double resolution = 0.3;
281 EXPECT_DOUBLE_EQ(0.0, positionShift.x());
282 EXPECT_DOUBLE_EQ(0.0, positionShift.y());
285 EXPECT_DOUBLE_EQ(-0.3, positionShift.x());
286 EXPECT_DOUBLE_EQ(0.3, positionShift.y());
289 EXPECT_DOUBLE_EQ(-0.6, positionShift.x());
290 EXPECT_DOUBLE_EQ(-0.3, positionShift.y());
295 Size bufferSize(10, 15);
382 double epsilon = 11.0 * numeric_limits<double>::epsilon();
384 Length mapLength(30.0, 10.0);
388 position << 0.0, 0.0;
390 EXPECT_DOUBLE_EQ(0.0, position.x());
391 EXPECT_DOUBLE_EQ(0.0, position.y());
393 position << 15.0, 5.0;
395 EXPECT_NEAR(15.0, position.x(), 15.0 * epsilon);
396 EXPECT_GE(15.0, position.x());
397 EXPECT_NEAR(5.0, position.y(), 5.0 * epsilon);
398 EXPECT_GE(5.0, position.y());
400 position << -15.0, -5.0;
402 EXPECT_NEAR(-15.0, position.x(), 15.0 * epsilon);
403 EXPECT_LE(-15.0, position.x());
404 EXPECT_NEAR(-5.0, position.y(), 5.0 * epsilon);
405 EXPECT_LE(-5.0, position.y());
407 position << 16.0, 6.0;
409 EXPECT_NEAR(15.0, position.x(), 16.0 * epsilon);
410 EXPECT_GE(15.0, position.x());
411 EXPECT_NEAR(5.0, position.y(), 6.0 * epsilon);
412 EXPECT_GE(5.0, position.y());
414 position << -16.0, -6.0;
416 EXPECT_NEAR(-15.0, position.x(), 16.0 * epsilon);
417 EXPECT_LE(-15.0, position.x());
418 EXPECT_NEAR(-5.0, position.y(), 6.0 * epsilon);
419 EXPECT_LE(-5.0, position.y());
421 position << 1e6, 1e6;
423 EXPECT_NEAR(15.0, position.x(), 1e6 * epsilon);
424 EXPECT_GE(15.0, position.x());
425 EXPECT_NEAR(5.0, position.y(), 1e6 * epsilon);
426 EXPECT_GE(5.0, position.y());
428 position << -1e6, -1e6;
430 EXPECT_NEAR(-15.0, position.x(), 1e6 * epsilon);
431 EXPECT_LE(-15.0, position.x());
432 EXPECT_NEAR(-5.0, position.y(), 1e6 * epsilon);
433 EXPECT_LE(-5.0, position.y());
438 double epsilon = 11.0 * numeric_limits<double>::epsilon();
440 Length mapLength(30.0, 10.0);
444 position << 0.0, 0.0;
446 EXPECT_DOUBLE_EQ(0.0, position.x());
447 EXPECT_DOUBLE_EQ(0.0, position.y());
449 position << 16.0, 7.0;
451 EXPECT_NEAR(16.0, position.x(), 16.0 * epsilon);
452 EXPECT_GE(16.0, position.x());
453 EXPECT_NEAR(7.0, position.y(), 7.0 * epsilon);
454 EXPECT_GE(7.0, position.y());
456 position << -14.0, -3.0;
458 EXPECT_NEAR(-14.0, position.x(), 14.0 * epsilon);
459 EXPECT_LE(-14.0, position.x());
460 EXPECT_NEAR(-3.0, position.y(), 3.0 * epsilon);
461 EXPECT_LE(-3.0, position.y());
463 position << 17.0, 8.0;
465 EXPECT_NEAR(16.0, position.x(), 17.0 * epsilon);
466 EXPECT_GE(16.0, position.x());
467 EXPECT_NEAR(7.0, position.y(), 8.0 * epsilon);
468 EXPECT_GE(7.0, position.y());
470 position << -15.0, -4.0;
472 EXPECT_NEAR(-14.0, position.x(), 15.0 * epsilon);
473 EXPECT_LE(-14.0, position.x());
474 EXPECT_NEAR(-3.0, position.y(), 4.0 * epsilon);
475 EXPECT_LE(-3.0, position.y());
477 position << 1e6, 1e6;
479 EXPECT_NEAR(16.0, position.x(), 1e6 * epsilon);
480 EXPECT_GE(16.0, position.x());
481 EXPECT_NEAR(7.0, position.y(), 1e6 * epsilon);
482 EXPECT_GE(7.0, position.y());
484 position << -1e6, -1e6;
486 EXPECT_NEAR(-14.0, position.x(), 1e6 * epsilon);
487 EXPECT_LE(-14.0, position.x());
488 EXPECT_NEAR(-3.0, position.y(), 1e6 * epsilon);
489 EXPECT_LE(-3.0, position.y());
495 Length mapLength(5.0, 4.0);
497 double resolution = 1.0;
498 Size bufferSize(5, 4);
505 Index submapTopLeftIndex;
509 Index requestedIndexInSubmap;
511 requestedSubmapPosition << 0.0, 0.5;
512 requestedSubmapLength << 0.9, 2.9;
513 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
514 requestedSubmapPosition, requestedSubmapLength, mapLength, mapPosition, resolution, bufferSize));
515 EXPECT_EQ(2, submapTopLeftIndex(0));
516 EXPECT_EQ(0, submapTopLeftIndex(1));
517 EXPECT_EQ(1, submapSize(0));
518 EXPECT_EQ(3, submapSize(1));
519 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
520 EXPECT_DOUBLE_EQ(0.5, submapPosition.y());
521 EXPECT_DOUBLE_EQ(1.0, submapLength(0));
522 EXPECT_DOUBLE_EQ(3.0, submapLength(1));
523 EXPECT_EQ(0, requestedIndexInSubmap(0));
524 EXPECT_EQ(1, requestedIndexInSubmap(1));
530 Length mapLength(5.0, 4.0);
532 double resolution = 1.0;
533 Size bufferSize(5, 4);
537 Length requestedSubmapLength;
540 Index submapTopLeftIndex;
544 Index requestedIndexInSubmap;
546 requestedSubmapPosition << -1.0, -0.5;
547 requestedSubmapLength << 0.0, 0.0;
548 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
549 requestedSubmapPosition, requestedSubmapLength,
550 mapLength, mapPosition, resolution, bufferSize));
551 EXPECT_EQ(3, submapTopLeftIndex(0));
552 EXPECT_EQ(2, submapTopLeftIndex(1));
553 EXPECT_EQ(1, submapSize(0));
554 EXPECT_EQ(1, submapSize(1));
555 EXPECT_DOUBLE_EQ(requestedSubmapPosition.x(), submapPosition.x());
556 EXPECT_DOUBLE_EQ(requestedSubmapPosition.y(), submapPosition.y());
557 EXPECT_DOUBLE_EQ(resolution, submapLength(0));
558 EXPECT_DOUBLE_EQ(resolution, submapLength(1));
559 EXPECT_EQ(0, requestedIndexInSubmap(0));
560 EXPECT_EQ(0, requestedIndexInSubmap(1));
566 Length mapLength(5.0, 4.0);
568 double resolution = 1.0;
569 Size bufferSize(5, 4);
573 Length requestedSubmapLength;
576 Index submapTopLeftIndex;
580 Index requestedIndexInSubmap;
582 requestedSubmapPosition << 2.0, 1.5;
583 requestedSubmapLength << 2.9, 2.9;
584 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
585 requestedSubmapPosition, requestedSubmapLength,
586 mapLength, mapPosition, resolution, bufferSize));
587 EXPECT_EQ(0, submapTopLeftIndex(0));
588 EXPECT_EQ(0, submapTopLeftIndex(1));
589 EXPECT_EQ(2, submapSize(0));
590 EXPECT_EQ(2, submapSize(1));
591 EXPECT_DOUBLE_EQ(1.5, submapPosition.x());
592 EXPECT_DOUBLE_EQ(1.0, submapPosition.y());
593 EXPECT_DOUBLE_EQ(2.0, submapLength(0));
594 EXPECT_DOUBLE_EQ(2.0, submapLength(1));
595 EXPECT_EQ(0, requestedIndexInSubmap(0));
596 EXPECT_EQ(0, requestedIndexInSubmap(1));
598 requestedSubmapPosition << 0.0, 0.0;
599 requestedSubmapLength << 1e6, 1e6;
600 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
601 requestedSubmapPosition, requestedSubmapLength,
602 mapLength, mapPosition, resolution, bufferSize));
603 EXPECT_EQ(0, submapTopLeftIndex(0));
604 EXPECT_EQ(0, submapTopLeftIndex(1));
605 EXPECT_EQ(bufferSize(0), submapSize(0));
606 EXPECT_EQ(bufferSize(1), submapSize(1));
607 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
608 EXPECT_DOUBLE_EQ(0.0, submapPosition.y());
609 EXPECT_DOUBLE_EQ(mapLength(0), submapLength(0));
610 EXPECT_DOUBLE_EQ(mapLength(1), submapLength(1));
611 EXPECT_EQ(2, requestedIndexInSubmap(0));
612 EXPECT_LE(1, requestedIndexInSubmap(1));
613 EXPECT_GE(2, requestedIndexInSubmap(1));
619 Length mapLength(5.0, 4.0);
621 double resolution = 1.0;
622 Size bufferSize(5, 4);
623 Index bufferStartIndex(2, 1);
627 Length requestedSubmapLength;
630 Index submapTopLeftIndex;
634 Index requestedIndexInSubmap;
636 requestedSubmapPosition << 0.0, 0.5;
637 requestedSubmapLength << 0.9, 2.9;
638 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
639 requestedSubmapPosition, requestedSubmapLength,
640 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
641 EXPECT_EQ(4, submapTopLeftIndex(0));
642 EXPECT_EQ(1, submapTopLeftIndex(1));
643 EXPECT_EQ(1, submapSize(0));
644 EXPECT_EQ(3, submapSize(1));
645 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
646 EXPECT_DOUBLE_EQ(0.5, submapPosition.y());
647 EXPECT_DOUBLE_EQ(1.0, submapLength(0));
648 EXPECT_DOUBLE_EQ(3.0, submapLength(1));
649 EXPECT_EQ(0, requestedIndexInSubmap(0));
650 EXPECT_EQ(1, requestedIndexInSubmap(1));
652 requestedSubmapPosition << 2.0, 1.5;
653 requestedSubmapLength << 2.9, 2.9;
654 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
655 requestedSubmapPosition, requestedSubmapLength,
656 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
657 EXPECT_EQ(2, submapTopLeftIndex(0));
658 EXPECT_EQ(1, submapTopLeftIndex(1));
659 EXPECT_EQ(2, submapSize(0));
660 EXPECT_EQ(2, submapSize(1));
661 EXPECT_DOUBLE_EQ(1.5, submapPosition.x());
662 EXPECT_DOUBLE_EQ(1.0, submapPosition.y());
663 EXPECT_DOUBLE_EQ(2.0, submapLength(0));
664 EXPECT_DOUBLE_EQ(2.0, submapLength(1));
665 EXPECT_EQ(0, requestedIndexInSubmap(0));
666 EXPECT_EQ(0, requestedIndexInSubmap(1));
668 requestedSubmapPosition << 0.0, 0.0;
669 requestedSubmapLength << 1e6, 1e6;
670 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
671 requestedSubmapPosition, requestedSubmapLength,
672 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
673 EXPECT_EQ(2, submapTopLeftIndex(0));
674 EXPECT_EQ(1, submapTopLeftIndex(1));
675 EXPECT_EQ(bufferSize(0), submapSize(0));
676 EXPECT_EQ(bufferSize(1), submapSize(1));
677 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
678 EXPECT_DOUBLE_EQ(0.0, submapPosition.y());
679 EXPECT_DOUBLE_EQ(mapLength(0), submapLength(0));
680 EXPECT_DOUBLE_EQ(mapLength(1), submapLength(1));
681 EXPECT_EQ(2, requestedIndexInSubmap(0));
682 EXPECT_LE(1, requestedIndexInSubmap(1));
683 EXPECT_GE(2, requestedIndexInSubmap(1));
689 Length mapLength(4.98, 4.98);
691 double resolution = 0.06;
692 Size bufferSize(83, 83);
693 Index bufferStartIndex(0, 13);
696 Position requestedSubmapPosition(-7.44, -3.42);
697 Length requestedSubmapLength(0.12, 0.12);
700 Index submapTopLeftIndex;
704 Index requestedIndexInSubmap;
706 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
707 requestedSubmapPosition, requestedSubmapLength,
708 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
709 EXPECT_EQ(2, submapSize(0));
710 EXPECT_EQ(3, submapSize(1));
711 EXPECT_DOUBLE_EQ(0.12, submapLength(0));
712 EXPECT_DOUBLE_EQ(0.18, submapLength(1));
718 Length mapLength(4.98, 4.98);
720 double resolution = 0.06;
721 Size bufferSize(83, 83);
722 Index bufferStartIndex(42, 6);
725 Position requestedSubmapPosition(0.24, -26.82);
726 Length requestedSubmapLength(0.624614, 0.462276);
729 Index submapTopLeftIndex;
733 Index requestedIndexInSubmap;
735 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
736 requestedSubmapPosition, requestedSubmapLength,
737 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
738 EXPECT_LT(0, submapSize(0));
739 EXPECT_LT(0, submapSize(1));
740 EXPECT_LT(0.0, submapLength(0));
741 EXPECT_LT(0.0, submapLength(1));
746 Size bufferSize(5, 4);
747 Index submapIndex(0, 0);
748 Size submapSize(0, 0);
749 std::vector<BufferRegion> regions;
752 EXPECT_EQ(1, regions.size());
753 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
754 EXPECT_EQ(0, regions[0].getStartIndex()[0]);
755 EXPECT_EQ(0, regions[0].getStartIndex()[1]);
756 EXPECT_EQ(0, regions[0].getSize()[0]);
757 EXPECT_EQ(0, regions[0].getSize()[1]);
768 Size bufferSize(5, 4);
769 Index submapIndex(1, 2);
770 Size submapSize(3, 2);
771 std::vector<BufferRegion> regions;
774 EXPECT_EQ(1, regions.size());
775 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
776 EXPECT_EQ(1, regions[0].getStartIndex()[0]);
777 EXPECT_EQ(2, regions[0].getStartIndex()[1]);
778 EXPECT_EQ(3, regions[0].getSize()[0]);
779 EXPECT_EQ(2, regions[0].getSize()[1]);
784 Size bufferSize(5, 4);
787 Index bufferStartIndex(3, 1);
788 std::vector<BufferRegion> regions;
793 EXPECT_EQ(1, regions.size());
794 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
795 EXPECT_EQ(3, regions[0].getStartIndex()[0]);
796 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
797 EXPECT_EQ(2, regions[0].getSize()[0]);
798 EXPECT_EQ(3, regions[0].getSize()[1]);
803 EXPECT_EQ(2, regions.size());
804 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
805 EXPECT_EQ(4, regions[0].getStartIndex()[0]);
806 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
807 EXPECT_EQ(1, regions[0].getSize()[0]);
808 EXPECT_EQ(3, regions[0].getSize()[1]);
809 EXPECT_EQ(BufferRegion::Quadrant::BottomLeft, regions[1].
getQuadrant());
810 EXPECT_EQ(0, regions[1].getStartIndex()[0]);
811 EXPECT_EQ(1, regions[1].getStartIndex()[1]);
812 EXPECT_EQ(1, regions[1].getSize()[0]);
813 EXPECT_EQ(3, regions[1].getSize()[1]);
818 EXPECT_EQ(1, regions.size());
819 EXPECT_EQ(BufferRegion::Quadrant::BottomRight, regions[0].
getQuadrant());
820 EXPECT_EQ(1, regions[0].getStartIndex()[0]);
821 EXPECT_EQ(0, regions[0].getStartIndex()[1]);
822 EXPECT_EQ(2, regions[0].getSize()[0]);
823 EXPECT_EQ(1, regions[0].getSize()[1]);
828 EXPECT_EQ(4, regions.size());
829 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
830 EXPECT_EQ(3, regions[0].getStartIndex()[0]);
831 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
832 EXPECT_EQ(2, regions[0].getSize()[0]);
833 EXPECT_EQ(3, regions[0].getSize()[1]);
834 EXPECT_EQ(BufferRegion::Quadrant::TopRight, regions[1].
getQuadrant());
835 EXPECT_EQ(3, regions[1].getStartIndex()[0]);
836 EXPECT_EQ(0, regions[1].getStartIndex()[1]);
837 EXPECT_EQ(2, regions[1].getSize()[0]);
838 EXPECT_EQ(1, regions[1].getSize()[1]);
839 EXPECT_EQ(BufferRegion::Quadrant::BottomLeft, regions[2].
getQuadrant());
840 EXPECT_EQ(0, regions[2].getStartIndex()[0]);
841 EXPECT_EQ(1, regions[2].getStartIndex()[1]);
842 EXPECT_EQ(3, regions[2].getSize()[0]);
843 EXPECT_EQ(3, regions[2].getSize()[1]);
844 EXPECT_EQ(BufferRegion::Quadrant::BottomRight, regions[3].
getQuadrant());
845 EXPECT_EQ(0, regions[3].getStartIndex()[0]);
846 EXPECT_EQ(0, regions[3].getStartIndex()[1]);
847 EXPECT_EQ(3, regions[3].getSize()[0]);
848 EXPECT_EQ(1, regions[3].getSize()[1]);
851 TEST(checkIncrementIndex, Simple)
854 Size bufferSize(4, 3);
857 EXPECT_EQ(0, index[0]);
858 EXPECT_EQ(1, index[1]);
861 EXPECT_EQ(0, index[0]);
862 EXPECT_EQ(2, index[1]);
865 EXPECT_EQ(1, index[0]);
866 EXPECT_EQ(0, index[1]);
869 EXPECT_EQ(1, index[0]);
870 EXPECT_EQ(1, index[1]);
872 for (
int i = 0; i < 6; i++) {
875 EXPECT_EQ(3, index[0]);
876 EXPECT_EQ(1, index[1]);
879 EXPECT_EQ(3, index[0]);
880 EXPECT_EQ(2, index[1]);
883 EXPECT_EQ(index[0], index[0]);
884 EXPECT_EQ(index[1], index[1]);
887 TEST(checkIncrementIndex, CircularBuffer)
889 Size bufferSize(4, 3);
890 Index bufferStartIndex(2, 1);
891 Index index(bufferStartIndex);
894 EXPECT_EQ(2, index[0]);
895 EXPECT_EQ(2, index[1]);
898 EXPECT_EQ(2, index[0]);
899 EXPECT_EQ(0, index[1]);
902 EXPECT_EQ(3, index[0]);
903 EXPECT_EQ(1, index[1]);
906 EXPECT_EQ(3, index[0]);
907 EXPECT_EQ(2, index[1]);
910 EXPECT_EQ(3, index[0]);
911 EXPECT_EQ(0, index[1]);
914 EXPECT_EQ(0, index[0]);
915 EXPECT_EQ(1, index[1]);
918 EXPECT_EQ(0, index[0]);
919 EXPECT_EQ(2, index[1]);
922 EXPECT_EQ(0, index[0]);
923 EXPECT_EQ(0, index[1]);
926 EXPECT_EQ(1, index[0]);
927 EXPECT_EQ(1, index[1]);
930 EXPECT_EQ(1, index[0]);
931 EXPECT_EQ(2, index[1]);
934 EXPECT_EQ(1, index[0]);
935 EXPECT_EQ(0, index[1]);
937 EXPECT_FALSE(
incrementIndex(index, bufferSize, bufferStartIndex));
938 EXPECT_EQ(index[0], index[0]);
939 EXPECT_EQ(index[1], index[1]);
942 TEST(checkIncrementIndexForSubmap, Simple)
944 Index submapIndex(0, 0);
946 Index submapTopLeftIndex(3, 1);
947 Size submapBufferSize(2, 4);
948 Size bufferSize(8, 5);
951 EXPECT_EQ(0, submapIndex[0]);
952 EXPECT_EQ(1, submapIndex[1]);
953 EXPECT_EQ(3, index[0]);
954 EXPECT_EQ(2, index[1]);
957 EXPECT_EQ(0, submapIndex[0]);
958 EXPECT_EQ(2, submapIndex[1]);
959 EXPECT_EQ(3, index[0]);
960 EXPECT_EQ(3, index[1]);
963 EXPECT_EQ(0, submapIndex[0]);
964 EXPECT_EQ(3, submapIndex[1]);
965 EXPECT_EQ(3, index[0]);
966 EXPECT_EQ(4, index[1]);
969 EXPECT_EQ(1, submapIndex[0]);
970 EXPECT_EQ(0, submapIndex[1]);
971 EXPECT_EQ(4, index[0]);
972 EXPECT_EQ(1, index[1]);
976 EXPECT_EQ(1, submapIndex[0]);
977 EXPECT_EQ(3, submapIndex[1]);
978 EXPECT_EQ(4, index[0]);
979 EXPECT_EQ(4, index[1]);
987 TEST(checkIncrementIndexForSubmap, CircularBuffer)
989 Index submapIndex(0, 0);
991 Index submapTopLeftIndex(6, 3);
992 Size submapBufferSize(2, 4);
993 Size bufferSize(8, 5);
994 Index bufferStartIndex(3, 2);
996 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
997 EXPECT_EQ(0, submapIndex[0]);
998 EXPECT_EQ(1, submapIndex[1]);
999 EXPECT_EQ(6, index[0]);
1000 EXPECT_EQ(4, index[1]);
1002 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1003 EXPECT_EQ(0, submapIndex[0]);
1004 EXPECT_EQ(2, submapIndex[1]);
1005 EXPECT_EQ(6, index[0]);
1006 EXPECT_EQ(0, index[1]);
1008 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1009 EXPECT_EQ(0, submapIndex[0]);
1010 EXPECT_EQ(3, submapIndex[1]);
1011 EXPECT_EQ(6, index[0]);
1012 EXPECT_EQ(1, index[1]);
1014 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1015 EXPECT_EQ(1, submapIndex[0]);
1016 EXPECT_EQ(0, submapIndex[1]);
1017 EXPECT_EQ(7, index[0]);
1018 EXPECT_EQ(3, index[1]);
1020 submapIndex << 1, 2;
1021 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1022 EXPECT_EQ(1, submapIndex[0]);
1023 EXPECT_EQ(3, submapIndex[1]);
1024 EXPECT_EQ(7, index[0]);
1025 EXPECT_EQ(1, index[1]);
1027 EXPECT_FALSE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
1029 submapIndex << 2, 0;
1030 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())
TEST(PositionFromIndex, Simple)
Index getIndexFromLinearIndex(const size_t linearIndex, const Size &bufferSize, const bool rowMajor=false)
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)