Commit 069de599 authored by Daniil Rastorguev's avatar Daniil Rastorguev
Browse files

changed return value type to std::optional, got rid of exception

parent 6cab1db7
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -117,10 +117,12 @@ ROOT::Math::XYZPoint PixelDetectorModel::getSensorIntercept(const ROOT::Math::XY
    // We have to be centered around the sensor box. This means we need to shift by the matrix center
    auto translation_local = ROOT::Math::Translation3D(static_cast<ROOT::Math::XYZVector>(getMatrixCenter()));

    try {
    auto intersection_point = LiangBarsky(direction, translation_local.Inverse()(inside), getSensorSize());

    // Get intersection from Liang-Barsky line clipping and re-transform to local coordinates:
        return translation_local(LiangBarsky(direction, translation_local.Inverse()(inside), getSensorSize()));
    } catch(std::invalid_argument&) {
    if(intersection_point) {
        return translation_local(intersection_point.value());
    } else {
        return inside;
    }
}
+9 −7
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
#include <Math/Point3D.h>
#include <Math/Vector3D.h>

#include <optional>

namespace allpix {

    /**
@@ -28,12 +30,12 @@ namespace allpix {
     * @param direction Direction vector of the motion
     * @param position Original ("before") position to be considered
     * @param box Size of the box to calculate the intersections with
     * @return Closest intersection with box in the direction indicated by input vector
     *
     * @throws std::invalid_argument if no intersection of track segment with the box volume can be found in positive
     * @return Closest intersection with box in the direction indicated by input vector if there is such intersection,
     * std::nullopt if no intersection of track segment with the box volume can be found in positive
     * direction from the given position.
     *
     */
    inline ROOT::Math::XYZPoint LiangBarsky(const ROOT::Math::XYZVector& direction,
    inline std::optional<ROOT::Math::XYZPoint> LiangBarsky(const ROOT::Math::XYZVector& direction,
                                                           const ROOT::Math::XYZPoint& position,
                                                           const ROOT::Math::XYZVector& box) {

@@ -80,7 +82,7 @@ namespace allpix {
        }

        // Otherwise: The line does not intersect the box.
        throw std::invalid_argument("no intersection with volume boundaries found");
        return std::nullopt;
    }
} // namespace allpix