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);
197 double resolution = 1.0;
201 EXPECT_EQ(0, indexShift(0));
202 EXPECT_EQ(0, indexShift(1));
205 EXPECT_EQ(0, indexShift(0));
206 EXPECT_EQ(0, indexShift(1));
209 EXPECT_EQ(-1, indexShift(0));
210 EXPECT_EQ(0, indexShift(1));
213 EXPECT_EQ(1, indexShift(0));
214 EXPECT_EQ(3, indexShift(1));
217 EXPECT_EQ(2, indexShift(0));
218 EXPECT_EQ(0, indexShift(1));
223 double resolution = 0.3;
227 EXPECT_DOUBLE_EQ(0.0, positionShift.x());
228 EXPECT_DOUBLE_EQ(0.0, positionShift.y());
231 EXPECT_DOUBLE_EQ(-0.3, positionShift.x());
232 EXPECT_DOUBLE_EQ(0.3, positionShift.y());
235 EXPECT_DOUBLE_EQ(-0.6, positionShift.x());
236 EXPECT_DOUBLE_EQ(-0.3, positionShift.y());
241 Size bufferSize(10, 15);
328 double epsilon = 11.0 * numeric_limits<double>::epsilon();
330 Length mapLength(30.0, 10.0);
334 position << 0.0, 0.0;
336 EXPECT_DOUBLE_EQ(0.0, position.x());
337 EXPECT_DOUBLE_EQ(0.0, position.y());
339 position << 15.0, 5.0;
341 EXPECT_NEAR(15.0, position.x(), 15.0 * epsilon);
342 EXPECT_GE(15.0, position.x());
343 EXPECT_NEAR(5.0, position.y(), 5.0 * epsilon);
344 EXPECT_GE(5.0, position.y());
346 position << -15.0, -5.0;
348 EXPECT_NEAR(-15.0, position.x(), 15.0 * epsilon);
349 EXPECT_LE(-15.0, position.x());
350 EXPECT_NEAR(-5.0, position.y(), 5.0 * epsilon);
351 EXPECT_LE(-5.0, position.y());
353 position << 16.0, 6.0;
355 EXPECT_NEAR(15.0, position.x(), 16.0 * epsilon);
356 EXPECT_GE(15.0, position.x());
357 EXPECT_NEAR(5.0, position.y(), 6.0 * epsilon);
358 EXPECT_GE(5.0, position.y());
360 position << -16.0, -6.0;
362 EXPECT_NEAR(-15.0, position.x(), 16.0 * epsilon);
363 EXPECT_LE(-15.0, position.x());
364 EXPECT_NEAR(-5.0, position.y(), 6.0 * epsilon);
365 EXPECT_LE(-5.0, position.y());
367 position << 1e6, 1e6;
369 EXPECT_NEAR(15.0, position.x(), 1e6 * epsilon);
370 EXPECT_GE(15.0, position.x());
371 EXPECT_NEAR(5.0, position.y(), 1e6 * epsilon);
372 EXPECT_GE(5.0, position.y());
374 position << -1e6, -1e6;
376 EXPECT_NEAR(-15.0, position.x(), 1e6 * epsilon);
377 EXPECT_LE(-15.0, position.x());
378 EXPECT_NEAR(-5.0, position.y(), 1e6 * epsilon);
379 EXPECT_LE(-5.0, position.y());
384 double epsilon = 11.0 * numeric_limits<double>::epsilon();
386 Length mapLength(30.0, 10.0);
390 position << 0.0, 0.0;
392 EXPECT_DOUBLE_EQ(0.0, position.x());
393 EXPECT_DOUBLE_EQ(0.0, position.y());
395 position << 16.0, 7.0;
397 EXPECT_NEAR(16.0, position.x(), 16.0 * epsilon);
398 EXPECT_GE(16.0, position.x());
399 EXPECT_NEAR(7.0, position.y(), 7.0 * epsilon);
400 EXPECT_GE(7.0, position.y());
402 position << -14.0, -3.0;
404 EXPECT_NEAR(-14.0, position.x(), 14.0 * epsilon);
405 EXPECT_LE(-14.0, position.x());
406 EXPECT_NEAR(-3.0, position.y(), 3.0 * epsilon);
407 EXPECT_LE(-3.0, position.y());
409 position << 17.0, 8.0;
411 EXPECT_NEAR(16.0, position.x(), 17.0 * epsilon);
412 EXPECT_GE(16.0, position.x());
413 EXPECT_NEAR(7.0, position.y(), 8.0 * epsilon);
414 EXPECT_GE(7.0, position.y());
416 position << -15.0, -4.0;
418 EXPECT_NEAR(-14.0, position.x(), 15.0 * epsilon);
419 EXPECT_LE(-14.0, position.x());
420 EXPECT_NEAR(-3.0, position.y(), 4.0 * epsilon);
421 EXPECT_LE(-3.0, position.y());
423 position << 1e6, 1e6;
425 EXPECT_NEAR(16.0, position.x(), 1e6 * epsilon);
426 EXPECT_GE(16.0, position.x());
427 EXPECT_NEAR(7.0, position.y(), 1e6 * epsilon);
428 EXPECT_GE(7.0, position.y());
430 position << -1e6, -1e6;
432 EXPECT_NEAR(-14.0, position.x(), 1e6 * epsilon);
433 EXPECT_LE(-14.0, position.x());
434 EXPECT_NEAR(-3.0, position.y(), 1e6 * epsilon);
435 EXPECT_LE(-3.0, position.y());
441 Length mapLength(5.0, 4.0);
443 double resolution = 1.0;
444 Size bufferSize(5, 4);
451 Index submapTopLeftIndex;
455 Index requestedIndexInSubmap;
457 requestedSubmapPosition << 0.0, 0.5;
458 requestedSubmapLength << 0.9, 2.9;
459 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
460 requestedSubmapPosition, requestedSubmapLength, mapLength, mapPosition, resolution, bufferSize));
461 EXPECT_EQ(2, submapTopLeftIndex(0));
462 EXPECT_EQ(0, submapTopLeftIndex(1));
463 EXPECT_EQ(1, submapSize(0));
464 EXPECT_EQ(3, submapSize(1));
465 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
466 EXPECT_DOUBLE_EQ(0.5, submapPosition.y());
467 EXPECT_DOUBLE_EQ(1.0, submapLength(0));
468 EXPECT_DOUBLE_EQ(3.0, submapLength(1));
469 EXPECT_EQ(0, requestedIndexInSubmap(0));
470 EXPECT_EQ(1, requestedIndexInSubmap(1));
476 Length mapLength(5.0, 4.0);
478 double resolution = 1.0;
479 Size bufferSize(5, 4);
483 Length requestedSubmapLength;
486 Index submapTopLeftIndex;
490 Index requestedIndexInSubmap;
492 requestedSubmapPosition << -1.0, -0.5;
493 requestedSubmapLength << 0.0, 0.0;
494 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
495 requestedSubmapPosition, requestedSubmapLength,
496 mapLength, mapPosition, resolution, bufferSize));
497 EXPECT_EQ(3, submapTopLeftIndex(0));
498 EXPECT_EQ(2, submapTopLeftIndex(1));
499 EXPECT_EQ(1, submapSize(0));
500 EXPECT_EQ(1, submapSize(1));
501 EXPECT_DOUBLE_EQ(requestedSubmapPosition.x(), submapPosition.x());
502 EXPECT_DOUBLE_EQ(requestedSubmapPosition.y(), submapPosition.y());
503 EXPECT_DOUBLE_EQ(resolution, submapLength(0));
504 EXPECT_DOUBLE_EQ(resolution, submapLength(1));
505 EXPECT_EQ(0, requestedIndexInSubmap(0));
506 EXPECT_EQ(0, requestedIndexInSubmap(1));
512 Length mapLength(5.0, 4.0);
514 double resolution = 1.0;
515 Size bufferSize(5, 4);
519 Length requestedSubmapLength;
522 Index submapTopLeftIndex;
526 Index requestedIndexInSubmap;
528 requestedSubmapPosition << 2.0, 1.5;
529 requestedSubmapLength << 2.9, 2.9;
530 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
531 requestedSubmapPosition, requestedSubmapLength,
532 mapLength, mapPosition, resolution, bufferSize));
533 EXPECT_EQ(0, submapTopLeftIndex(0));
534 EXPECT_EQ(0, submapTopLeftIndex(1));
535 EXPECT_EQ(2, submapSize(0));
536 EXPECT_EQ(2, submapSize(1));
537 EXPECT_DOUBLE_EQ(1.5, submapPosition.x());
538 EXPECT_DOUBLE_EQ(1.0, submapPosition.y());
539 EXPECT_DOUBLE_EQ(2.0, submapLength(0));
540 EXPECT_DOUBLE_EQ(2.0, submapLength(1));
541 EXPECT_EQ(0, requestedIndexInSubmap(0));
542 EXPECT_EQ(0, requestedIndexInSubmap(1));
544 requestedSubmapPosition << 0.0, 0.0;
545 requestedSubmapLength << 1e6, 1e6;
546 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
547 requestedSubmapPosition, requestedSubmapLength,
548 mapLength, mapPosition, resolution, bufferSize));
549 EXPECT_EQ(0, submapTopLeftIndex(0));
550 EXPECT_EQ(0, submapTopLeftIndex(1));
551 EXPECT_EQ(bufferSize(0), submapSize(0));
552 EXPECT_EQ(bufferSize(1), submapSize(1));
553 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
554 EXPECT_DOUBLE_EQ(0.0, submapPosition.y());
555 EXPECT_DOUBLE_EQ(mapLength(0), submapLength(0));
556 EXPECT_DOUBLE_EQ(mapLength(1), submapLength(1));
557 EXPECT_EQ(2, requestedIndexInSubmap(0));
558 EXPECT_LE(1, requestedIndexInSubmap(1));
559 EXPECT_GE(2, requestedIndexInSubmap(1));
565 Length mapLength(5.0, 4.0);
567 double resolution = 1.0;
568 Size bufferSize(5, 4);
569 Index bufferStartIndex(2, 1);
573 Length requestedSubmapLength;
576 Index submapTopLeftIndex;
580 Index requestedIndexInSubmap;
582 requestedSubmapPosition << 0.0, 0.5;
583 requestedSubmapLength << 0.9, 2.9;
584 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
585 requestedSubmapPosition, requestedSubmapLength,
586 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
587 EXPECT_EQ(4, submapTopLeftIndex(0));
588 EXPECT_EQ(1, submapTopLeftIndex(1));
589 EXPECT_EQ(1, submapSize(0));
590 EXPECT_EQ(3, submapSize(1));
591 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
592 EXPECT_DOUBLE_EQ(0.5, submapPosition.y());
593 EXPECT_DOUBLE_EQ(1.0, submapLength(0));
594 EXPECT_DOUBLE_EQ(3.0, submapLength(1));
595 EXPECT_EQ(0, requestedIndexInSubmap(0));
596 EXPECT_EQ(1, requestedIndexInSubmap(1));
598 requestedSubmapPosition << 2.0, 1.5;
599 requestedSubmapLength << 2.9, 2.9;
600 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
601 requestedSubmapPosition, requestedSubmapLength,
602 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
603 EXPECT_EQ(2, submapTopLeftIndex(0));
604 EXPECT_EQ(1, submapTopLeftIndex(1));
605 EXPECT_EQ(2, submapSize(0));
606 EXPECT_EQ(2, submapSize(1));
607 EXPECT_DOUBLE_EQ(1.5, submapPosition.x());
608 EXPECT_DOUBLE_EQ(1.0, submapPosition.y());
609 EXPECT_DOUBLE_EQ(2.0, submapLength(0));
610 EXPECT_DOUBLE_EQ(2.0, submapLength(1));
611 EXPECT_EQ(0, requestedIndexInSubmap(0));
612 EXPECT_EQ(0, requestedIndexInSubmap(1));
614 requestedSubmapPosition << 0.0, 0.0;
615 requestedSubmapLength << 1e6, 1e6;
616 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
617 requestedSubmapPosition, requestedSubmapLength,
618 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
619 EXPECT_EQ(2, submapTopLeftIndex(0));
620 EXPECT_EQ(1, submapTopLeftIndex(1));
621 EXPECT_EQ(bufferSize(0), submapSize(0));
622 EXPECT_EQ(bufferSize(1), submapSize(1));
623 EXPECT_DOUBLE_EQ(0.0, submapPosition.x());
624 EXPECT_DOUBLE_EQ(0.0, submapPosition.y());
625 EXPECT_DOUBLE_EQ(mapLength(0), submapLength(0));
626 EXPECT_DOUBLE_EQ(mapLength(1), submapLength(1));
627 EXPECT_EQ(2, requestedIndexInSubmap(0));
628 EXPECT_LE(1, requestedIndexInSubmap(1));
629 EXPECT_GE(2, requestedIndexInSubmap(1));
635 Length mapLength(4.98, 4.98);
637 double resolution = 0.06;
638 Size bufferSize(83, 83);
639 Index bufferStartIndex(0, 13);
642 Position requestedSubmapPosition(-7.44, -3.42);
643 Length requestedSubmapLength(0.12, 0.12);
646 Index submapTopLeftIndex;
650 Index requestedIndexInSubmap;
652 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
653 requestedSubmapPosition, requestedSubmapLength,
654 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
655 EXPECT_EQ(2, submapSize(0));
656 EXPECT_EQ(3, submapSize(1));
657 EXPECT_DOUBLE_EQ(0.12, submapLength(0));
658 EXPECT_DOUBLE_EQ(0.18, submapLength(1));
664 Length mapLength(4.98, 4.98);
666 double resolution = 0.06;
667 Size bufferSize(83, 83);
668 Index bufferStartIndex(42, 6);
671 Position requestedSubmapPosition(0.24, -26.82);
672 Length requestedSubmapLength(0.624614, 0.462276);
675 Index submapTopLeftIndex;
679 Index requestedIndexInSubmap;
681 EXPECT_TRUE(
getSubmapInformation(submapTopLeftIndex, submapSize, submapPosition, submapLength, requestedIndexInSubmap,
682 requestedSubmapPosition, requestedSubmapLength,
683 mapLength, mapPosition, resolution, bufferSize, bufferStartIndex));
684 EXPECT_LT(0, submapSize(0));
685 EXPECT_LT(0, submapSize(1));
686 EXPECT_LT(0.0, submapLength(0));
687 EXPECT_LT(0.0, submapLength(1));
692 Size bufferSize(5, 4);
693 Index submapIndex(0, 0);
694 Size submapSize(0, 0);
695 std::vector<BufferRegion> regions;
698 EXPECT_EQ(1, regions.size());
699 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
700 EXPECT_EQ(0, regions[0].getStartIndex()[0]);
701 EXPECT_EQ(0, regions[0].getStartIndex()[1]);
702 EXPECT_EQ(0, regions[0].getSize()[0]);
703 EXPECT_EQ(0, regions[0].getSize()[1]);
714 Size bufferSize(5, 4);
715 Index submapIndex(1, 2);
716 Size submapSize(3, 2);
717 std::vector<BufferRegion> regions;
720 EXPECT_EQ(1, regions.size());
721 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
722 EXPECT_EQ(1, regions[0].getStartIndex()[0]);
723 EXPECT_EQ(2, regions[0].getStartIndex()[1]);
724 EXPECT_EQ(3, regions[0].getSize()[0]);
725 EXPECT_EQ(2, regions[0].getSize()[1]);
730 Size bufferSize(5, 4);
733 Index bufferStartIndex(3, 1);
734 std::vector<BufferRegion> regions;
739 EXPECT_EQ(1, regions.size());
740 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
741 EXPECT_EQ(3, regions[0].getStartIndex()[0]);
742 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
743 EXPECT_EQ(2, regions[0].getSize()[0]);
744 EXPECT_EQ(3, regions[0].getSize()[1]);
749 EXPECT_EQ(2, regions.size());
750 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
751 EXPECT_EQ(4, regions[0].getStartIndex()[0]);
752 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
753 EXPECT_EQ(1, regions[0].getSize()[0]);
754 EXPECT_EQ(3, regions[0].getSize()[1]);
755 EXPECT_EQ(BufferRegion::Quadrant::BottomLeft, regions[1].
getQuadrant());
756 EXPECT_EQ(0, regions[1].getStartIndex()[0]);
757 EXPECT_EQ(1, regions[1].getStartIndex()[1]);
758 EXPECT_EQ(1, regions[1].getSize()[0]);
759 EXPECT_EQ(3, regions[1].getSize()[1]);
764 EXPECT_EQ(1, regions.size());
765 EXPECT_EQ(BufferRegion::Quadrant::BottomRight, regions[0].
getQuadrant());
766 EXPECT_EQ(1, regions[0].getStartIndex()[0]);
767 EXPECT_EQ(0, regions[0].getStartIndex()[1]);
768 EXPECT_EQ(2, regions[0].getSize()[0]);
769 EXPECT_EQ(1, regions[0].getSize()[1]);
774 EXPECT_EQ(4, regions.size());
775 EXPECT_EQ(BufferRegion::Quadrant::TopLeft, regions[0].
getQuadrant());
776 EXPECT_EQ(3, regions[0].getStartIndex()[0]);
777 EXPECT_EQ(1, regions[0].getStartIndex()[1]);
778 EXPECT_EQ(2, regions[0].getSize()[0]);
779 EXPECT_EQ(3, regions[0].getSize()[1]);
780 EXPECT_EQ(BufferRegion::Quadrant::TopRight, regions[1].
getQuadrant());
781 EXPECT_EQ(3, regions[1].getStartIndex()[0]);
782 EXPECT_EQ(0, regions[1].getStartIndex()[1]);
783 EXPECT_EQ(2, regions[1].getSize()[0]);
784 EXPECT_EQ(1, regions[1].getSize()[1]);
785 EXPECT_EQ(BufferRegion::Quadrant::BottomLeft, regions[2].
getQuadrant());
786 EXPECT_EQ(0, regions[2].getStartIndex()[0]);
787 EXPECT_EQ(1, regions[2].getStartIndex()[1]);
788 EXPECT_EQ(3, regions[2].getSize()[0]);
789 EXPECT_EQ(3, regions[2].getSize()[1]);
790 EXPECT_EQ(BufferRegion::Quadrant::BottomRight, regions[3].
getQuadrant());
791 EXPECT_EQ(0, regions[3].getStartIndex()[0]);
792 EXPECT_EQ(0, regions[3].getStartIndex()[1]);
793 EXPECT_EQ(3, regions[3].getSize()[0]);
794 EXPECT_EQ(1, regions[3].getSize()[1]);
797 TEST(checkIncrementIndex, Simple)
800 Size bufferSize(4, 3);
803 EXPECT_EQ(0, index[0]);
804 EXPECT_EQ(1, index[1]);
807 EXPECT_EQ(0, index[0]);
808 EXPECT_EQ(2, index[1]);
811 EXPECT_EQ(1, index[0]);
812 EXPECT_EQ(0, index[1]);
815 EXPECT_EQ(1, index[0]);
816 EXPECT_EQ(1, index[1]);
818 for (
int i = 0; i < 6; i++) {
821 EXPECT_EQ(3, index[0]);
822 EXPECT_EQ(1, index[1]);
825 EXPECT_EQ(3, index[0]);
826 EXPECT_EQ(2, index[1]);
829 EXPECT_EQ(index[0], index[0]);
830 EXPECT_EQ(index[1], index[1]);
833 TEST(checkIncrementIndex, CircularBuffer)
835 Size bufferSize(4, 3);
836 Index bufferStartIndex(2, 1);
837 Index index(bufferStartIndex);
840 EXPECT_EQ(2, index[0]);
841 EXPECT_EQ(2, index[1]);
844 EXPECT_EQ(2, index[0]);
845 EXPECT_EQ(0, index[1]);
848 EXPECT_EQ(3, index[0]);
849 EXPECT_EQ(1, index[1]);
852 EXPECT_EQ(3, index[0]);
853 EXPECT_EQ(2, index[1]);
856 EXPECT_EQ(3, index[0]);
857 EXPECT_EQ(0, index[1]);
860 EXPECT_EQ(0, index[0]);
861 EXPECT_EQ(1, index[1]);
864 EXPECT_EQ(0, index[0]);
865 EXPECT_EQ(2, index[1]);
868 EXPECT_EQ(0, index[0]);
869 EXPECT_EQ(0, index[1]);
872 EXPECT_EQ(1, index[0]);
873 EXPECT_EQ(1, index[1]);
876 EXPECT_EQ(1, index[0]);
877 EXPECT_EQ(2, index[1]);
880 EXPECT_EQ(1, index[0]);
881 EXPECT_EQ(0, index[1]);
883 EXPECT_FALSE(
incrementIndex(index, bufferSize, bufferStartIndex));
884 EXPECT_EQ(index[0], index[0]);
885 EXPECT_EQ(index[1], index[1]);
888 TEST(checkIncrementIndexForSubmap, Simple)
890 Index submapIndex(0, 0);
892 Index submapTopLeftIndex(3, 1);
893 Size submapBufferSize(2, 4);
894 Size bufferSize(8, 5);
897 EXPECT_EQ(0, submapIndex[0]);
898 EXPECT_EQ(1, submapIndex[1]);
899 EXPECT_EQ(3, index[0]);
900 EXPECT_EQ(2, index[1]);
903 EXPECT_EQ(0, submapIndex[0]);
904 EXPECT_EQ(2, submapIndex[1]);
905 EXPECT_EQ(3, index[0]);
906 EXPECT_EQ(3, index[1]);
909 EXPECT_EQ(0, submapIndex[0]);
910 EXPECT_EQ(3, submapIndex[1]);
911 EXPECT_EQ(3, index[0]);
912 EXPECT_EQ(4, index[1]);
915 EXPECT_EQ(1, submapIndex[0]);
916 EXPECT_EQ(0, submapIndex[1]);
917 EXPECT_EQ(4, index[0]);
918 EXPECT_EQ(1, index[1]);
922 EXPECT_EQ(1, submapIndex[0]);
923 EXPECT_EQ(3, submapIndex[1]);
924 EXPECT_EQ(4, index[0]);
925 EXPECT_EQ(4, index[1]);
933 TEST(checkIncrementIndexForSubmap, CircularBuffer)
935 Index submapIndex(0, 0);
937 Index submapTopLeftIndex(6, 3);
938 Size submapBufferSize(2, 4);
939 Size bufferSize(8, 5);
940 Index bufferStartIndex(3, 2);
942 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
943 EXPECT_EQ(0, submapIndex[0]);
944 EXPECT_EQ(1, submapIndex[1]);
945 EXPECT_EQ(6, index[0]);
946 EXPECT_EQ(4, index[1]);
948 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
949 EXPECT_EQ(0, submapIndex[0]);
950 EXPECT_EQ(2, submapIndex[1]);
951 EXPECT_EQ(6, index[0]);
952 EXPECT_EQ(0, index[1]);
954 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
955 EXPECT_EQ(0, submapIndex[0]);
956 EXPECT_EQ(3, submapIndex[1]);
957 EXPECT_EQ(6, index[0]);
958 EXPECT_EQ(1, index[1]);
960 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
961 EXPECT_EQ(1, submapIndex[0]);
962 EXPECT_EQ(0, submapIndex[1]);
963 EXPECT_EQ(7, index[0]);
964 EXPECT_EQ(3, index[1]);
967 EXPECT_TRUE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
968 EXPECT_EQ(1, submapIndex[0]);
969 EXPECT_EQ(3, submapIndex[1]);
970 EXPECT_EQ(7, index[0]);
971 EXPECT_EQ(1, index[1]);
973 EXPECT_FALSE(
incrementIndexForSubmap(submapIndex, index, submapTopLeftIndex, submapBufferSize, bufferSize, bufferStartIndex));
976 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)