BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ZLimits.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Scattering/ZLimits.cpp
6 //! @brief Defines class ZLimits.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
16 #include <algorithm>
17 #include <stdexcept>
18 
19 ZLimits::ZLimits() : m_lower{true, 0}, m_upper{true, 0} {}
20 
21 ZLimits::ZLimits(double min, double max) : ZLimits({false, min}, {false, max}) {}
22 
23 ZLimits::ZLimits(OneSidedLimit lower_limit, OneSidedLimit upper_limit)
24  : m_lower(std::move(lower_limit)), m_upper(std::move(upper_limit))
25 {
26  if (!lower_limit.m_limitless && !upper_limit.m_limitless
27  && lower_limit.m_value > upper_limit.m_value)
28  throw std::runtime_error("ZLimits constructor: "
29  "lower limit bigger than upper limit.");
30 }
31 
32 bool ZLimits::isFinite() const
33 {
35  return false;
36  return true;
37 }
38 
40 {
41  return m_lower;
42 }
43 
45 {
46  return m_upper;
47 }
48 
50 {
51  if (left.m_limitless || right.m_limitless)
52  return {true, 0};
53  return {false, std::min(left.m_value, right.m_value)};
54 }
55 
57 {
58  if (left.m_limitless || right.m_limitless)
59  return {true, 0};
60  return {false, std::max(left.m_value, right.m_value)};
61 }
62 
63 bool operator==(const OneSidedLimit& left, const OneSidedLimit& right)
64 {
65  if (left.m_limitless != right.m_limitless)
66  return false;
67  if (!left.m_limitless && left.m_value != right.m_value)
68  return false;
69  return true;
70 }
71 
72 bool operator!=(const OneSidedLimit& left, const OneSidedLimit& right)
73 {
74  return !(left == right);
75 }
76 
77 std::ostream& operator<<(std::ostream& ostr, const OneSidedLimit& limit)
78 {
79  return ostr << "{" << (limit.m_limitless ? "true, " : "false, ") << limit.m_value << "}";
80 }
81 
82 ZLimits ConvexHull(const ZLimits& left, const ZLimits& right)
83 {
84  return {MinLimit(left.lowerLimit(), right.lowerLimit()),
85  MaxLimit(left.upperLimit(), right.upperLimit())};
86 }
87 
88 bool operator==(const ZLimits& left, const ZLimits& right)
89 {
90  return (left.lowerLimit() == right.lowerLimit() && left.upperLimit() == right.upperLimit());
91 }
92 
93 bool operator!=(const ZLimits& left, const ZLimits& right)
94 {
95  return !(left == right);
96 }
97 
98 std::ostream& operator<<(std::ostream& ostr, const ZLimits& limits)
99 {
100  return ostr << "Lower: " << limits.lowerLimit() << ", Upper: " << limits.upperLimit();
101 }
OneSidedLimit MinLimit(const OneSidedLimit &left, const OneSidedLimit &right)
Definition: ZLimits.cpp:49
ZLimits ConvexHull(const ZLimits &left, const ZLimits &right)
Definition: ZLimits.cpp:82
OneSidedLimit MaxLimit(const OneSidedLimit &left, const OneSidedLimit &right)
Definition: ZLimits.cpp:56
Defines class ZLimits.
bool operator!=(const BasicVector3D< T > &a, const BasicVector3D< T > &b)
Comparison of two vectors for inequality.
bool operator==(const BasicVector3D< T > &a, const BasicVector3D< T > &b)
Comparison of two vectors for equality.
std::ostream & operator<<(std::ostream &os, const BasicVector3D< T > &a)
Output to stream.
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:41
OneSidedLimit lowerLimit() const
Definition: ZLimits.cpp:39
OneSidedLimit upperLimit() const
Definition: ZLimits.cpp:44
bool isFinite() const
Definition: ZLimits.cpp:32
OneSidedLimit m_upper
Definition: ZLimits.h:54
OneSidedLimit m_lower
Definition: ZLimits.h:53
ZLimits()
Definition: ZLimits.cpp:19
Helper class that represents a onesided limit.
Definition: ZLimits.h:30
double m_value
Definition: ZLimits.h:32
bool m_limitless
Definition: ZLimits.h:31