|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | + |
| 19 | +#include "itkBresenhamLine.h" |
| 20 | +#include "itkGTest.h" |
| 21 | + |
| 22 | +#include <iostream> |
| 23 | + |
| 24 | +TEST(BresenhamLine, BuildLineFromVector) |
| 25 | +{ |
| 26 | + // Test BuildLine(Vector, distance) |
| 27 | + itk::Vector<float, 2> v; |
| 28 | + v[0] = 1; |
| 29 | + v[1] = 1; |
| 30 | + |
| 31 | + itk::BresenhamLine<2> line; |
| 32 | + std::vector<itk::Offset<2>> offsets = line.BuildLine(v, 4); |
| 33 | + |
| 34 | + EXPECT_EQ(offsets.size(), 4u); |
| 35 | + |
| 36 | + for (int i = 0; i < 4; ++i) |
| 37 | + { |
| 38 | + const itk::Offset<2> expectedOffset{ { i, i } }; |
| 39 | + ITK_EXPECT_VECTOR_NEAR(offsets[i], expectedOffset, 0); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +TEST(BresenhamLine, BuildLineFromIndices) |
| 44 | +{ |
| 45 | + // Test BuildLine(Index, Index) |
| 46 | + itk::Index<2> p0; |
| 47 | + p0[0] = 0; |
| 48 | + p0[1] = 0; |
| 49 | + |
| 50 | + itk::Index<2> p1; |
| 51 | + p1[0] = 39; |
| 52 | + p1[1] = 39; |
| 53 | + |
| 54 | + itk::BresenhamLine<2> line; |
| 55 | + std::vector<itk::Index<2>> indices = line.BuildLine(p0, p1); |
| 56 | + |
| 57 | + EXPECT_EQ(indices.size(), 40u); |
| 58 | + |
| 59 | + for (int i = 0; i < 40; ++i) |
| 60 | + { |
| 61 | + const itk::Index<2> expectedIndex{ { i, i } }; |
| 62 | + ITK_EXPECT_VECTOR_NEAR(indices[i], expectedIndex, 0); |
| 63 | + } |
| 64 | + |
| 65 | + std::cout << "Test Passed !" << std::endl; |
| 66 | +} |
0 commit comments