From cc7a9e2161245eaaad2073aca95e6c65e5ef1a46 Mon Sep 17 00:00:00 2001 From: Moritz Kiehn <msmk@cern.ch> Date: Thu, 6 Apr 2017 15:55:40 +0000 Subject: [PATCH] Surfaces/TrapezoidBounds: use updated api and BoundaryCheck --- .../include/ACTS/Surfaces/TrapezoidBounds.hpp | 119 ++++-------------- Core/src/Surfaces/TrapezoidBounds.cpp | 68 +++++++--- Tests/Surfaces/TrapezoidBoundsTests.cpp | 14 +-- 3 files changed, 80 insertions(+), 121 deletions(-) diff --git a/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp b/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp index fa3e6e920..386d69736 100644 --- a/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp +++ b/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp @@ -1,6 +1,6 @@ // This file is part of the ACTS project. // -// Copyright (C) 2016 ACTS project team +// Copyright (C) 2016-2017 ACTS project team // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -14,6 +14,7 @@ #define ACTS_SURFACES_TRAPEZOIDBOUNDS_H 1 #include <cmath> + #include "ACTS/Surfaces/PlanarBounds.hpp" #include "ACTS/Surfaces/RectangleBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" @@ -50,46 +51,16 @@ public: /// @param haley half length Y - defined at x=0 TrapezoidBounds(double minhalex, double maxhalex, double haley); - /// Copy constructor - /// - /// @param trabo are the source bounds for assignment - TrapezoidBounds(const TrapezoidBounds& trabo) - : PlanarBounds(trabo), m_boundingBox(0., 0.) - { - } - - /// Destructor virtual ~TrapezoidBounds(); - /// Virtual constructor virtual TrapezoidBounds* clone() const final override; - /// Return the type of the bounds for persistency virtual BoundsType - type() const final - { - return SurfaceBounds::Trapezoid; - } - - /// Assignment operator - TrapezoidBounds& - operator=(const TrapezoidBounds& sbo); + type() const final override; - /// This method returns the minimal halflength in X - /// (first coordinate of local surface frame) - double - minHalflengthX() const; - - /// This method returns the maximal halflength in X - /// (first coordinate of local surface frame) - double - maxHalflengthX() const; - - /// This method returns the halflength in Y - /// (second coordinate of local surface frame) - double - halflengthY() const; + virtual std::vector<TDD_real_t> + valueStore() const final override; /// The orientation of the Trapezoid is according to the figure above, /// in words: the shorter of the two parallel sides of the trapezoid @@ -134,40 +105,14 @@ public: /// /// @param lpos Local position (assumed to be in right surface frame) /// @param bcheck boundary check directive - /// /// @return boolean indicator for the success of this operation virtual bool inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const final override; - /// This method checks inside bounds in loc0 - /// @note loc0/loc1 correspond to the natural coordinates of the surface - /// @note As loc0/loc1 are correlated the single check doesn't make sense : - /// check is done on enclosing Rectangle ! - /// - /// @param lpos is the local position to be checked - /// @param tol0 is the tolerance applied - /// - /// @return boolean indicator for the success of this operation - virtual bool - insideLoc0(const Vector2D& lpos, double tol0 = 0.) const final override; - - /// This method checks inside bounds in loc0 - /// @note loc0/loc1 correspond to the natural coordinates of the surface - /// @note As loc0/loc1 are correlated the single check doesn't make sense : - /// -> check is done on enclosing Rectangle ! - /// - /// @param lpos is the local position to be checked - /// @param tol1 is the tolerance applied - /// - /// @return boolean indicator for the success of this operation - virtual bool - insideLoc1(const Vector2D& lpos, double tol1 = 0.) const final override; - /// Minimal distance to boundary ( > 0 if outside and <=0 if inside) /// /// @param lpos is the local position to check for the distance - /// /// @return is a signed distance parameter virtual double distanceToBoundary(const Vector2D& lpos) const final override; @@ -186,54 +131,44 @@ public: virtual std::ostream& dump(std::ostream& sl) const final override; + /// This method returns the minimal halflength in X + /// (first coordinate of local surface frame) + double + minHalflengthX() const; + + /// This method returns the maximal halflength in X + /// (first coordinate of local surface frame) + double + maxHalflengthX() const; + + /// This method returns the halflength in Y + /// (second coordinate of local surface frame) + double + halflengthY() const; + private: - RectangleBounds m_boundingBox; ///< internal bounding box cache + double m_minHalfX; + double m_maxHalfX; + double m_halfY; + RectangleBounds m_boundingBox; }; -inline TrapezoidBounds* -TrapezoidBounds::clone() const -{ - return new TrapezoidBounds(*this); -} - inline double TrapezoidBounds::minHalflengthX() const { - return m_valueStore[TrapezoidBounds::bv_minHalfX]; + return m_minHalfX; } inline double TrapezoidBounds::maxHalflengthX() const { - return m_valueStore[TrapezoidBounds::bv_maxHalfX]; + return m_maxHalfX; } inline double TrapezoidBounds::halflengthY() const { - return m_valueStore[TrapezoidBounds::bv_halfY]; -} - -inline bool -TrapezoidBounds::inside(const Vector2D& lpos, const BoundaryCheck& bcheck) const -{ - return bcheck.isInsidePolygon(lpos, vertices()); -} - -inline const std::vector<Vector2D> -TrapezoidBounds::vertices() const -{ - // counter-clockwise from bottom-right corner - return {{minHalflengthX(), -halflengthY()}, - {maxHalflengthX(), halflengthY()}, - {-maxHalflengthX(), halflengthY()}, - {-minHalflengthX(), -halflengthY()}}; -} - -inline const RectangleBounds& -TrapezoidBounds::boundingBox() const -{ - return m_boundingBox; + return m_halfY; } } // end of namespace diff --git a/Core/src/Surfaces/TrapezoidBounds.cpp b/Core/src/Surfaces/TrapezoidBounds.cpp index 100d2548c..df37e3a26 100644 --- a/Core/src/Surfaces/TrapezoidBounds.cpp +++ b/Core/src/Surfaces/TrapezoidBounds.cpp @@ -1,6 +1,6 @@ // This file is part of the ACTS project. // -// Copyright (C) 2016 ACTS project team +// Copyright (C) 2016-2017 ACTS project team // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -11,6 +11,7 @@ /////////////////////////////////////////////////////////////////// #include "ACTS/Surfaces/TrapezoidBounds.hpp" + #include <cmath> #include <iomanip> #include <iostream> @@ -18,32 +19,66 @@ Acts::TrapezoidBounds::TrapezoidBounds(double minhalex, double maxhalex, double haley) - : PlanarBounds(TrapezoidBounds::bv_length), m_boundingBox(0.0, 0.0) + : m_minHalfX(std::abs(minhalex)) + , m_maxHalfX(std::abs(maxhalex)) + , m_halfY(std::abs(haley)) + , m_boundingBox(std::max(minhalex, maxhalex), haley) { - m_valueStore[TrapezoidBounds::bv_minHalfX] = std::abs(minhalex); - m_valueStore[TrapezoidBounds::bv_maxHalfX] = std::abs(maxhalex); - m_valueStore[TrapezoidBounds::bv_halfY] = std::abs(haley); - m_boundingBox = RectangleBounds(std::max(minhalex, maxhalex), haley); } Acts::TrapezoidBounds::~TrapezoidBounds() { } -Acts::TrapezoidBounds& -Acts::TrapezoidBounds::operator=(const TrapezoidBounds& trabo) +Acts::TrapezoidBounds* +Acts::TrapezoidBounds::clone() const +{ + return new TrapezoidBounds(*this); +} + +Acts::SurfaceBounds::BoundsType +Acts::TrapezoidBounds::type() const +{ + return SurfaceBounds::Trapezoid; +} + +std::vector<TDD_real_t> +Acts::TrapezoidBounds::valueStore() const +{ + std::vector<TDD_real_t> values(TrapezoidBounds::bv_length); + values[TrapezoidBounds::bv_minHalfX] = minHalflengthX(); + values[TrapezoidBounds::bv_maxHalfX] = maxHalflengthX(); + values[TrapezoidBounds::bv_halfY] = halflengthY(); + return values; +} + +bool +Acts::TrapezoidBounds::inside(const Acts::Vector2D& lpos, + const Acts::BoundaryCheck& bcheck) const { - if (this != &trabo) { - PlanarBounds::operator=(trabo); - m_boundingBox = trabo.m_boundingBox; - } - return *this; + return bcheck.isInside(lpos, vertices()); } double Acts::TrapezoidBounds::distanceToBoundary(const Acts::Vector2D& lpos) const { - return BoundaryCheck(true).distanceToBoundary(lpos, vertices()); + return BoundaryCheck(true).distance(lpos, vertices()); +} + +std::vector<Acts::Vector2D> +Acts::TrapezoidBounds::vertices() const +{ + // counter-clockwise from bottom-right corner + return {{minHalflengthX(), -halflengthY()}, + {maxHalflengthX(), halflengthY()}, + {-maxHalflengthX(), halflengthY()}, + {-minHalflengthX(), -halflengthY()}}; +} + +const Acts::RectangleBounds& +Acts::TrapezoidBounds::boundingBox() const +{ + return m_boundingBox; } std::ostream& @@ -52,9 +87,8 @@ Acts::TrapezoidBounds::dump(std::ostream& sl) const sl << std::setiosflags(std::ios::fixed); sl << std::setprecision(7); sl << "Acts::TrapezoidBounds: (minHlenghtX, maxHlengthX, hlengthY) = " - << "(" << m_valueStore.at(TrapezoidBounds::bv_minHalfX) << ", " - << m_valueStore.at(TrapezoidBounds::bv_maxHalfX) << ", " - << m_valueStore.at(TrapezoidBounds::bv_halfY) << ")"; + << "(" << minHalflengthX() << ", " << maxHalflengthX() << ", " + << halflengthY() << ")"; sl << std::setprecision(-1); return sl; } diff --git a/Tests/Surfaces/TrapezoidBoundsTests.cpp b/Tests/Surfaces/TrapezoidBoundsTests.cpp index 2f69d7a2f..096c67c6d 100644 --- a/Tests/Surfaces/TrapezoidBoundsTests.cpp +++ b/Tests/Surfaces/TrapezoidBoundsTests.cpp @@ -17,15 +17,12 @@ #include <boost/test/output_test_stream.hpp> // leave blank -// +#include <limits> + #include "ACTS/Surfaces/TrapezoidBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" -// -#include <limits> -// namespace bdata = boost::unit_test::data; namespace utf = boost::unit_test; -const double inf = std::numeric_limits<double>::infinity(); const double NaN = std::numeric_limits<double>::quiet_NaN(); namespace Acts { @@ -107,13 +104,6 @@ namespace Test { == true); BOOST_TEST(trapezoidBoundsObject.inside(outside, BoundaryCheck(true)) == false); - // - /// Test insideLoc0 - BOOST_TEST(trapezoidBoundsObject.insideLoc0(inRectangle) == true); - // - /// Test insideLoc1 - BOOST_TEST(trapezoidBoundsObject.insideLoc1(inRectangle) == true); - // } /// Unit test for testing TrapezoidBounds assignment BOOST_AUTO_TEST_CASE(TrapezoidBoundsAssignment) -- GitLab