ATLAS Offline Software
Loading...
Searching...
No Matches
VP1Interval.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class VP1Interval //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: May 2008 //
12// //
14
15#include "VP1Base/VP1Interval.h"
16#include "VP1Base/VP1Msg.h"
17#include <cmath>
18
19//____________________________________________________________________
25
26//____________________________________________________________________
27void VP1Interval::set(const double& lower,const double& upper, bool openLower, bool openUpper, bool excludeInterval)
28{
29 m_lower = lower;
30 m_upper = upper;
34 testSanity();
35}
36
37//____________________________________________________________________
39{
40 if (!isSane())
41 VP1Msg::messageDebug("WARNING: VP1Interval is not sane: "+toString());
42}
43
44//____________________________________________________________________
45bool VP1Interval::hasOverlap(const VP1Interval& other) const
46{
47 if (isEmpty()||other.isEmpty())
48 return false;
49 if (isAllR()||other.isAllR())
50 return true;
51 if (m_upper<other.m_lower||other.m_upper<m_lower)
52 return false;
53 if (m_upper==other.m_lower)
54 return !other.openLower() && !openUpper();
55 if (other.m_upper==m_lower)
56 return !openLower() && !other.openUpper();
57 return true;
58}
59
60//____________________________________________________________________
61bool VP1Interval::contains(const VP1Interval& other) const
62{
63 if (!noLowerBound()) {
64 if (other.m_lower<m_lower)
65 return false;
66 if (other.m_lower==m_lower&&!other.m_openLower&&m_openLower)
67 return false;
68 }
69 if (!noUpperBound()) {
70 if (other.m_upper>m_upper)
71 return false;
72 if (other.m_upper==m_upper&&!other.m_openUpper&&m_openUpper)
73 return false;
74 }
75 return true;
76}
77
78
79/*bool VP1Interval::contains(const double& x) const
80{
81 VP1Msg::messageDebug("m_excludeInterval: "+QString::number(m_excludeInterval));
82 if (m_excludeInterval) {
83 return ! (!excludedByLower(x) && !excludedByUpper(x));
84 }
85 return !excludedByLower(x) && !excludedByUpper(x);
86}
87*/
88
89//____________________________________________________________________
90bool VP1Interval::contains(const double& x, const double& period ) const
91{
92 if (isEmpty())
93 return false;
94
95 if (period<=0)
96 return period==0;
97
98 if (length()>=period)
99 return true;
100
101 //Translate x a number of periods, so that x is in
102 //[lower,lower+period[, and compare:
103 return contains(x+period*ceil((m_lower-x)/period));
104}
105
106
107//____________________________________________________________________
108bool VP1Interval::hasOverlap(const VP1Interval& other, const double& period ) const
109{
110 if (isEmpty()||other.isEmpty())
111 return false;
112 if (period<=0)
113 return period==0;
114 if (length()>=period||other.length()>=period)
115 return true;
116 //Translate the other interval so that it's lower value is in
117 //[lower,lower+period[, and then compare (both the interval and the
118 //interval translated -period are necessary):
119 const double t(period*ceil((m_lower-other.m_lower)/period));
120 const double a(other.m_lower+t), b(other.m_upper+t);
121 if (hasOverlap(VP1Interval(a,b,other.m_openLower,other.m_openUpper)))
122 return true;
123 return hasOverlap(VP1Interval(a-period,b-period,other.m_openLower,other.m_openUpper));
124}
static Double_t a
#define x
double m_upper
Definition VP1Interval.h:80
double lower() const
bool isEmpty() const
QString toString() const
bool isSane() const
bool isAllR() const
bool excludeInterval() const
bool contains(const double &x) const
bool noUpperBound() const
double upper() const
bool m_openLower
Definition VP1Interval.h:81
VP1Interval(const double &lower, const double &upper, bool openLower=true, bool openUpper=true, bool excludeRange=false)
bool hasOverlap(const VP1Interval &other) const
void testSanity() const
bool m_excludeInterval
Definition VP1Interval.h:83
double openLower() const
bool m_openUpper
Definition VP1Interval.h:82
double openUpper() const
double m_lower
Definition VP1Interval.h:79
double length() const
bool noLowerBound() const
void set(const double &lower, const double &upper, bool openLower=true, bool openUpper=true, bool excludeRange=false)
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39