Commit a2c08bfe authored by Daniil Rastorguev's avatar Daniil Rastorguev
Browse files

changed standalone functions to static class methods

parent e04e3c79
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ ROOT::Math::XYZPoint PixelDetectorModel::getSensorIntercept(const ROOT::Math::XY
    auto translation_local = ROOT::Math::Translation3D(static_cast<ROOT::Math::XYZVector>(getMatrixCenter()));

    auto intersection_point =
        LiangBarskyClosestIntersection(direction, translation_local.Inverse()(inside), getSensorSize());
        LiangBarsky::ClosestIntersection(direction, translation_local.Inverse()(inside), getSensorSize());

    // Get intersection from Liang-Barsky line clipping and re-transform to local coordinates:
    if(intersection_point) {
+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 */