Skip to content

Commit

Permalink
Remove the Vector2i since it is now unused
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Dec 18, 2024
1 parent b72809c commit 3fd0daf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
21 changes: 0 additions & 21 deletions edm4hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,6 @@ components:
return *( &x + i ) ; }\n
"


edm4hep::Vector2i:
Members:
- int32_t a
- int32_t b
ExtraCode:
includes: "#include <cstddef>"
declaration: "
constexpr Vector2i() : a(0),b(0) {}\n
constexpr Vector2i(int32_t aa, int32_t bb) : a(aa),b(bb) {}\n
constexpr Vector2i( const int32_t* v) : a(v[0]), b(v[1]) {}\n
constexpr bool operator==(const Vector2i& v) const { return (a==v.a&&b==v.b) ; }\n
constexpr bool operator!=(const Vector2i& v) const { return !(*this == v) ; }\n
constexpr int operator[](unsigned i) const {\n
static_assert(\n
offsetof(Vector2i,a)+sizeof(Vector2i::a) == offsetof(Vector2i,b),\n
\"operator[] requires no padding\");\n
return *( &a + i ) ; }\n
"


edm4hep::Vector2f:
Members:
- float a
Expand Down
27 changes: 8 additions & 19 deletions test/utils/test_vector_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
#include "edm4hep/utils/vector_utils.h"

#include "edm4hep/Vector2f.h"
#include "edm4hep/Vector2i.h"
#include "edm4hep/Vector3d.h"
#include "edm4hep/Vector3f.h"
#include "edm4hep/Vector4f.h"

#include <tuple>
#include <type_traits>
using Vector2And3Types = std::tuple<edm4hep::Vector3f, edm4hep::Vector3d, edm4hep::Vector2i, edm4hep::Vector2f>;
using AllVectorTypes =
std::tuple<edm4hep::Vector4f, edm4hep::Vector3f, edm4hep::Vector3d, edm4hep::Vector2i, edm4hep::Vector2f>;
using Vector2And3Types = std::tuple<edm4hep::Vector3f, edm4hep::Vector3d, edm4hep::Vector2f>;
using AllVectorTypes = std::tuple<edm4hep::Vector4f, edm4hep::Vector3f, edm4hep::Vector3d, edm4hep::Vector2f>;

template <typename V>
constexpr V create();
Expand All @@ -39,11 +37,6 @@ constexpr edm4hep::Vector2f create() {
return edm4hep::Vector2f{1.0f, 2.0f};
}

template <>
constexpr edm4hep::Vector2i create() {
return edm4hep::Vector2i{1, 2};
}

TEMPLATE_LIST_TEST_CASE("Vector uniform getters", "[vector_utils]", AllVectorTypes) {
using namespace edm4hep;

Expand All @@ -52,7 +45,7 @@ TEMPLATE_LIST_TEST_CASE("Vector uniform getters", "[vector_utils]", AllVectorTyp
STATIC_REQUIRE(utils::vector_x(vector) == utils::ValueType<TestType>(1.0));
STATIC_REQUIRE(utils::vector_y(vector) == utils::ValueType<TestType>(2.0));
// 2D vectors fill z component with 0
if constexpr (std::is_same_v<TestType, edm4hep::Vector2i> || std::is_same_v<TestType, edm4hep::Vector2f>) {
if constexpr (std::is_same_v<TestType, edm4hep::Vector2f>) {
STATIC_REQUIRE(utils::vector_z(vector) == utils::ValueType<TestType>(0.0));
} else if constexpr (std::is_same_v<TestType, edm4hep::Vector4f>) {
STATIC_REQUIRE(utils::vector_t(vector) == utils::ValueType<TestType>(4.0));
Expand All @@ -63,7 +56,6 @@ TEMPLATE_LIST_TEST_CASE("Vector uniform getters", "[vector_utils]", AllVectorTyp

TEST_CASE("Vector ValueType", "[vector_utils]") {
using namespace edm4hep;
STATIC_REQUIRE(std::is_same_v<int32_t, utils::ValueType<Vector2i>>);
STATIC_REQUIRE(std::is_same_v<float, utils::ValueType<Vector2f>>);
STATIC_REQUIRE(std::is_same_v<float, utils::ValueType<Vector3f>>);
STATIC_REQUIRE(std::is_same_v<double, utils::ValueType<Vector3d>>);
Expand All @@ -86,7 +78,7 @@ TEMPLATE_LIST_TEST_CASE("Vector operators", "[vector_utils]", AllVectorTypes) {
STATIC_REQUIRE(sumV - vector1 == vector2);

// Vector product (depends again on whether it is 2D or 3D)
if constexpr (std::is_same_v<TestType, edm4hep::Vector2i> || std::is_same_v<TestType, edm4hep::Vector2f>) {
if constexpr (std::is_same_v<TestType, edm4hep::Vector2f>) {
STATIC_REQUIRE(vector1 * vector2 == utils::ValueType<TestType>(5));
} else if constexpr (std::is_same_v<TestType, edm4hep::Vector3f> || std::is_same_v<TestType, edm4hep::Vector3d>) {
STATIC_REQUIRE(vector1 * vector2 == utils::ValueType<TestType>(14));
Expand All @@ -100,16 +92,13 @@ TEMPLATE_LIST_TEST_CASE("Vector utility functionality", "[vector_utils]", Vector

using namespace edm4hep;

// Can only normalize vectors with floating point numbers
if constexpr (!std::is_same_v<TestType, Vector2i>) {
const auto normV = utils::normalizeVector(vector);
REQUIRE(utils::magnitude(normV) == Catch::Approx(1));
REQUIRE(utils::projection(normV, vector) == Catch::Approx(1));
}
const auto normV = utils::normalizeVector(vector);
REQUIRE(utils::magnitude(normV) == Catch::Approx(1));
REQUIRE(utils::projection(normV, vector) == Catch::Approx(1));

// Small differences in expectations between 2D and 3D vectors for everything
// that involves the z component
if constexpr (std::is_same_v<TestType, Vector2i> || std::is_same_v<TestType, Vector2f>) {
if constexpr (std::is_same_v<TestType, Vector2f>) {
REQUIRE(utils::magnitude(vector) == Catch::Approx(std::sqrt(5)));

const auto otherVec = TestType(3, 4);
Expand Down

0 comments on commit 3fd0daf

Please sign in to comment.