Skip to content

Commit

Permalink
added Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzburger committed Dec 5, 2024
1 parent d2e0450 commit a3f9746
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Core/include/Acts/Visualization/Interpolation3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Definitions/Algebra.hpp"

#include <unsupported/Eigen/Splines>

namespace Acts::Interpolation3D {
Expand All @@ -20,8 +23,8 @@ namespace Acts::Interpolation3D {
///
/// @return std::vector<Acts::Vector3> interpolated points
template <typename input_vector_type>
std::vector<Acts::Vector3> spline(
const std::vector<input_vector_type>& inputs, std::size_t nPoints) {
std::vector<Acts::Vector3> spline(const std::vector<input_vector_type>& inputs,
std::size_t nPoints) {
std::vector<Acts::Vector3> output;

if (nPoints < 2) {
Expand All @@ -47,4 +50,4 @@ std::vector<Acts::Vector3> spline(
return output;
}

} // namespace Acts::Interpolation3D
} // namespace Acts::Interpolation3D
1 change: 1 addition & 0 deletions Tests/UnitTests/Core/Visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_unittest(Visualization3D Visualization3DTests.cpp)
add_unittest(EventDataView3D EventDataView3DTests.cpp)
add_unittest(Interpolation3D Interpolation3DTests.cpp)
add_unittest(PrimitivesView3D PrimitivesView3DTests.cpp)
add_unittest(SurfaceView3D SurfaceView3DTests.cpp)
add_unittest(TrackingGeometryView3D TrackingGeometryView3DTests.cpp)
Expand Down
51 changes: 51 additions & 0 deletions Tests/UnitTests/Core/Visualization/Interpolation3DTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include <boost/test/unit_test.hpp>
#include <numbers>

#include "Acts/Visualization/Interpolation3D.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"

namespace Acts::Test {

BOOST_AUTO_TEST_SUITE(Visualization)

BOOST_AUTO_TEST_CASE(SplineInterpolation) {

/// Define the input vector
double R = 10.;
std::vector<Acts::Vector3> inputs;
for (double phi = 0; phi < 2 * std::numbers::pi; phi += std::numbers::pi / 4) {
inputs.push_back(Acts::Vector3(R * cos(phi), R * sin(phi), 0.));
}

// Interpolate the points options
std::vector<Acts::Vector3> trajectory;

// (0) - nothing happens
trajectory = Acts::Interpolation3D::spline(inputs, 1);
// Check input and output size are the same
BOOST_CHECK_EQUAL(trajectory.size(), inputs.size());

// (1) - interpolate between the points with 12 points in total
trajectory = Acts::Interpolation3D::spline(inputs, 12);
// Check the output size is correct
BOOST_CHECK_EQUAL(trajectory.size(), 12);

for (const auto& point : trajectory) {
// Check the interpolated points are on the circle
// with a tolerance of course
CHECK_CLOSE_ABS(point.norm(), R, 0.1);
}

}

BOOST_AUTO_TEST_SUITE_END()

} // namespace Acts::Test

0 comments on commit a3f9746

Please sign in to comment.