diff --git a/Documentation/Examples/geometry_example.cc b/Documentation/Examples/geometry_example.cc index dac31edc4ad173e6860a7cbabb901366cedb27d1..048347aee5be19df25571cfc96752f49e1a0dad7 100644 --- a/Documentation/Examples/geometry_example.cc +++ b/Documentation/Examples/geometry_example.cc @@ -24,7 +24,7 @@ using namespace corsika::units::si; int main() { // define the root coordinate system - CoordinateSystem root; + auto const root = CoordinateSystem::CreateRootCS(); // another CS defined by a translation relative to the root CS CoordinateSystem cs2 = root.translate({0_m, 0_m, 1_m}); @@ -50,10 +50,10 @@ int main() { std::cout << "p2-p1 norm^2: " << norm << std::endl; Sphere s(p1, 10_m); // define a sphere around a point with a radius - std::cout << "p1 inside s: " << s.isInside(p2) << std::endl; + std::cout << "p1 inside s: " << s.Contains(p2) << std::endl; Sphere s2(p1, 3_um); // another sphere - std::cout << "p1 inside s2: " << s2.isInside(p2) << std::endl; + std::cout << "p1 inside s2: " << s2.Contains(p2) << std::endl; // let's try parallel projections: auto const v1 = Vector(root, {1_m, 1_m, 0_m}); diff --git a/Documentation/Examples/helix_example.cc b/Documentation/Examples/helix_example.cc index aea320270191ebcfb14e37a41fbdbbde2014c209..2797a30a1e9eb61d54cb51b4a3040e4dea80ca80 100644 --- a/Documentation/Examples/helix_example.cc +++ b/Documentation/Examples/helix_example.cc @@ -22,8 +22,7 @@ using namespace corsika::geometry; using namespace corsika::units::si; int main() { - - CoordinateSystem root; + auto const root = CoordinateSystem::CreateRootCS(); Point const r0(root, {0_m, 0_m, 0_m}); auto const omegaC = 2 * M_PI * 1_Hz; diff --git a/Framework/Cascade/Cascade.h b/Framework/Cascade/Cascade.h index b2aa17216a6b6c9bfaab96ee38569ba7b2b7cf19..f5d88b33f99834416bd569b0f53623b630db5add 100644 --- a/Framework/Cascade/Cascade.h +++ b/Framework/Cascade/Cascade.h @@ -66,7 +66,7 @@ namespace corsika::cascade { void Step(Particle& particle) { [[maybe_unused]] double nextStep = fProcesseList.MinStepLength(particle); // corsika::utls::ignore(nextStep); - corsika::geometry::CoordinateSystem root; + auto const root = corsika::geometry::CoordinateSystem::CreateRootCS(); corsika::geometry::LineTrajectory trajectory( // trajectory is not yet used. this is a dummy. corsika::geometry::Point(root, {0_m, 0_m, 0_m}), diff --git a/Framework/Geometry/CoordinateSystem.h b/Framework/Geometry/CoordinateSystem.h index a6a0912904b6704cc7ad3fcbd4100ff64946976e..089a3f80c96a8c7c2e9b2ebceeae4c6dc5bb2c8e 100644 --- a/Framework/Geometry/CoordinateSystem.h +++ b/Framework/Geometry/CoordinateSystem.h @@ -30,15 +30,17 @@ namespace corsika::geometry { CoordinateSystem(CoordinateSystem const& reference, EigenTransform const& transf) : reference(&reference) , transf(transf) {} + + CoordinateSystem() + : // for creating the root CS + transf(EigenTransform::Identity()) {} public: + static auto CreateRootCS() { return CoordinateSystem(); } + static EigenTransform GetTransformation(CoordinateSystem const& c1, CoordinateSystem const& c2); - CoordinateSystem() - : // for creating the root CS - transf(EigenTransform::Identity()) {} - auto& operator=(const CoordinateSystem& pCS) { reference = pCS.reference; transf = pCS.transf; @@ -52,6 +54,10 @@ namespace corsika::geometry { } auto rotate(QuantityVector axis, double angle) const { + if (axis.eVector.isZero()) { + throw std::string("null-vector given as axis parameter"); + } + EigenTransform const rotation{Eigen::AngleAxisd(angle, axis.eVector.normalized())}; return CoordinateSystem(*this, rotation); @@ -59,6 +65,10 @@ namespace corsika::geometry { auto translateAndRotate(QuantityVector translation, QuantityVector axis, double angle) { + if (axis.eVector.isZero()) { + throw std::string("null-vector given as axis parameter"); + } + EigenTransform const transf{Eigen::AngleAxisd(angle, axis.eVector.normalized()) * EigenTranslation(translation.eVector)}; diff --git a/Framework/Geometry/Sphere.h b/Framework/Geometry/Sphere.h index 436c8e4029472ed17e211b2a02c0c3e486ab33a2..6ab7c8b9690a7d92e51a6cbb75fc3a73fc227f8c 100644 --- a/Framework/Geometry/Sphere.h +++ b/Framework/Geometry/Sphere.h @@ -26,8 +26,8 @@ namespace corsika::geometry { : center(pCenter) , radius(pRadius) {} - //! returns true if the Point p is within the sphere - auto isInside(Point const& p) const { + //! returns true if the Point \a p is within the sphere + auto Contains(Point const& p) const { return radius * radius > (center - p).squaredNorm(); } }; diff --git a/Framework/Geometry/testGeometry.cc b/Framework/Geometry/testGeometry.cc index 31be0d360e81c9f53a6bda36c0fe4c685a61c4cb..98527c0c18985bde8a0e574df1ed111e8132ac55 100644 --- a/Framework/Geometry/testGeometry.cc +++ b/Framework/Geometry/testGeometry.cc @@ -28,7 +28,7 @@ using namespace corsika::units::si; double constexpr absMargin = 1.0e-8; TEST_CASE("transformations between CoordinateSystems") { - CoordinateSystem rootCS; + CoordinateSystem rootCS = CoordinateSystem::CreateRootCS(); REQUIRE(CoordinateSystem::GetTransformation(rootCS, rootCS) .isApprox(EigenTransform::Identity())); @@ -45,7 +45,7 @@ TEST_CASE("transformations between CoordinateSystems") { Approx(0).margin(absMargin)); SECTION("unconnected CoordinateSystems") { - CoordinateSystem rootCS2; + CoordinateSystem rootCS2 = CoordinateSystem::CreateRootCS(); REQUIRE_THROWS(CoordinateSystem::GetTransformation(rootCS, rootCS2)); } @@ -126,18 +126,18 @@ TEST_CASE("transformations between CoordinateSystems") { } TEST_CASE("Sphere") { - CoordinateSystem rootCS; + CoordinateSystem rootCS = CoordinateSystem::CreateRootCS(); Point center(rootCS, {0_m, 3_m, 4_m}); Sphere sphere(center, 5_m); SECTION("isInside") { - REQUIRE_FALSE(sphere.isInside(Point(rootCS, {100_m, 0_m, 0_m}))); - REQUIRE(sphere.isInside(Point(rootCS, {2_m, 3_m, 4_m}))); + REQUIRE_FALSE(sphere.Contains(Point(rootCS, {100_m, 0_m, 0_m}))); + REQUIRE(sphere.Contains(Point(rootCS, {2_m, 3_m, 4_m}))); } } TEST_CASE("Trajectories") { - CoordinateSystem rootCS; + CoordinateSystem rootCS = CoordinateSystem::CreateRootCS(); Point r0(rootCS, {0_m, 0_m, 0_m}); SECTION("Line") {