diff --git a/corsika/detail/framework/geometry/Box.inl b/corsika/detail/framework/geometry/Box.inl index d8b7d4129414de7015779b6162f24f6a718b5a79..118d6a7817badbf1adbd21d37fabac0c40becfd6 100644 --- a/corsika/detail/framework/geometry/Box.inl +++ b/corsika/detail/framework/geometry/Box.inl @@ -6,7 +6,24 @@ * the license. */ +#pragma once + namespace corsika { + inline Box::Box(CoordinateSystemPtr cs, LengthType const x, LengthType const y, + LengthType const z) + : center_(Point(cs, {0_m, 0_m, 0_m})) + , cs_(cs) + , x_(x) + , y_(y) + , z_(z) {} + + inline Box::Box(CoordinateSystemPtr cs, LengthType const side) + : center_(Point(cs, {0_m, 0_m, 0_m})) + , cs_(cs) + , x_(side / 2) + , y_(side / 2) + , z_(side / 2) {} + inline bool Box::contains(Point const& p) const { if ((abs(p.getX(cs_)) < x_) && (abs(p.getY(cs_)) < y_) && (abs(p.getZ(cs_)) < z_)) return true; diff --git a/corsika/framework/geometry/Box.hpp b/corsika/framework/geometry/Box.hpp index 20ad70b7ecc0b73eb89234bdc61ff532d6ad4ef0..696ad54555f8418d964e1b7f4f9ab1bea6d68eaf 100644 --- a/corsika/framework/geometry/Box.hpp +++ b/corsika/framework/geometry/Box.hpp @@ -14,24 +14,20 @@ #include <corsika/framework/geometry/IVolume.hpp> namespace corsika { + + /** + * Describes a sphere in space + * + * The center point and the orintation of the Box is set by + * a CoordinateSystemPtr at construction. + **/ class Box : public IVolume { public: - // a CoordinateSystemPtr to specify the orintation of coordinate - Box(Point const& center, CoordinateSystemPtr cs, LengthType const x, - LengthType const y, LengthType const z) - : center_(center) - , cs_(make_translation(cs, center.getCoordinates(cs))) - , x_(x) - , y_(y) - , z_(z) {} - - Box(Point const& center, CoordinateSystemPtr cs, LengthType const side) - : center_(center) - , cs_(make_translation(cs, center.getCoordinates(cs))) - , x_(side / 2) - , y_(side / 2) - , z_(side / 2) {} + Box(CoordinateSystemPtr cs, LengthType const x, LengthType const y, + LengthType const z); + + Box(CoordinateSystemPtr cs, LengthType const side); //! returns true if the Point p is within the sphere bool contains(Point const& p) const override; diff --git a/tests/framework/testGeometry.cpp b/tests/framework/testGeometry.cpp index 67242751c413312db71e6861c2a5aa74f8929336..d9f2e7c29340bed32dfbc8f4a74158e8fea490ff 100644 --- a/tests/framework/testGeometry.cpp +++ b/tests/framework/testGeometry.cpp @@ -285,11 +285,12 @@ TEST_CASE("Geometry Sphere") { TEST_CASE("Geometry Box") { CoordinateSystemPtr const& rootCS = get_root_CoordinateSystem(); - Point center(rootCS, {0_m, 0_m, 5_m}); - Box box(center, rootCS, 4_m, 5_m, 6_m); + auto initialCS = make_translation(rootCS, {0_m, 0_m, 5_m}); + Point center = Point(initialCS, {0_m, 0_m, 0_m}); + Box box(initialCS, 4_m, 5_m, 6_m); SECTION("getCenter") { - CHECK((box.getCenter().getCoordinates(rootCS) - center.getCoordinates()) + CHECK((box.getCenter().getCoordinates(rootCS) - center.getCoordinates(rootCS)) .getNorm() .magnitude() == Approx(0).margin(absMargin)); CHECK(box.getX() / 4_m == Approx(1)); @@ -304,7 +305,7 @@ TEST_CASE("Geometry Box") { SECTION("internal coordinate") { CoordinateSystemPtr const internalCS = box.getCoordinateSystem(); - auto coordinate = center.getCoordinates(internalCS); + auto coordinate = box.getCenter().getCoordinates(internalCS); CHECK(coordinate.getX() / 1_m == Approx(0)); CHECK(coordinate.getY() / 1_m == Approx(0)); CHECK(coordinate.getZ() / 1_m == Approx(0)); @@ -318,11 +319,10 @@ TEST_CASE("Geometry Box") { } SECTION("from different coordinate") { - CoordinateSystemPtr const& rootCS = get_root_CoordinateSystem(); QuantityVector<length_d> const axis_z{0_m, 0_m, 1_m}; - auto rotatedCS = make_rotation(rootCS, axis_z, 90); + auto rotatedCS = make_rotation(initialCS, axis_z, 90); Point center(rootCS, {0_m, 0_m, 5_m}); - Box box(center, rotatedCS, 4_m, 5_m, 6_m); + Box box(rotatedCS, 4_m, 5_m, 6_m); CHECK(box.contains(Point(rootCS, {4.5_m, 0_m, 0_m}))); CHECK_FALSE(box.contains(Point(rootCS, {0_m, 4.5_m, 0_m}))); }