Commit 18971bc7 authored by Daniil Rastorguev's avatar Daniil Rastorguev Committed by Simon Spannagel
Browse files

changed standalone functions to static class methods

(cherry picked from commit a2c08bfe)
parent 5220b0fb
Loading
Loading
Loading
Loading
+75 −71
Original line number Diff line number Diff line
@@ -26,16 +26,18 @@

namespace allpix {

    class LiangBarsky {
    public:
        /**
         * @brief Check intersection of a line defined by a point and a vector with a box
         * @param direction Defining vector of the line
         * @param position A point on that line
         * @param box Size of the box to calculate the intersections with
         * @return Pair of signed distances from `position` to intersection points along the line in units of length of
     * `direction`, with sign of these distances meaning direction w.r.t. line-defining vector or std::nullopt if the line
     * has no intersection with the given box
         * `direction`, with sign of these distances meaning direction w.r.t. line-defining vector or std::nullopt if the
         * line has no intersection with the given box
         */
    inline std::optional<std::pair<double, double>> LiangBarskyIntersectionDistances(const ROOT::Math::XYZVector& direction,
        static std::optional<std::pair<double, double>> IntersectionDistances(const ROOT::Math::XYZVector& direction,
                                                                              const ROOT::Math::XYZPoint& position,
                                                                              const ROOT::Math::XYZVector& box) {

@@ -85,16 +87,17 @@ namespace allpix {
         * or std::nullopt if no intersection of track segment with the box volume can be found in positive
         * direction from the given position.
         */
    inline std::optional<ROOT::Math::XYZPoint> LiangBarskyClosestIntersection(const ROOT::Math::XYZVector& direction,
        static std::optional<ROOT::Math::XYZPoint> ClosestIntersection(const ROOT::Math::XYZVector& direction,
                                                                       const ROOT::Math::XYZPoint& position,
                                                                       const ROOT::Math::XYZVector& box) {

        auto intersect = LiangBarskyIntersectionDistances(direction, position, box);
            auto intersect = IntersectionDistances(direction, position, box);

            if(!intersect) {
                return std::nullopt;
            }
        // The intersection is a point P + t * D. Return closest impact point if positive (i.e. in direction of the motion)
            // The intersection is a point P + t * D. Return closest impact point if positive (i.e. in direction of the
            // motion)
            auto [t0, t1] = intersect.value();
            if(t0 > 0 && t1 > 0) {
                return (position + std::min(t0, t1) * direction);
@@ -107,6 +110,7 @@ namespace allpix {
            // Otherwise: there is no intersection in positive direction
            return std::nullopt;
        }
    };
} // namespace allpix

#endif /* ALLPIX_LIANG_BARSKY_H */