OpenCurves  0.9
plotexpressionbinddomain.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef __PLOTEXPRESSIONBINDDOMAIN_H_
7 #define __PLOTEXPRESSIONBINDDOMAIN_H_
8 
9 #include "plotsconfig.h"
10 
11 #include <cstddef>
12 
16 {
17  BindError = -1,
21 };
22 
50 {
51  double domainMin;
52  double domainMax;
53  double sampleDelta;
54  size_t sampleCount;
55  bool minSet;
56  bool maxSet;
57 
59  inline PlotExpressionBindDomain() : domainMin(0), domainMax(0), sampleDelta(0), sampleCount(0), minSet(false), maxSet(false) {}
60 
62  void setUnbounded();
63 
68  inline bool isUnbounded() const { return sampleCount == 0u; }
69 
84  inline bool contains(double sampleTime, bool closedMin = true, bool closedMax = true) const;
85 };
86 
105 
112 {
113  return domainUnion(a, a, b);
114 }
115 
116 
118 {
120  sampleCount = 0u;
121  minSet = maxSet = false;
122 }
123 
124 
125 inline bool PlotExpressionBindDomain::contains(double sampleTime, bool closedMin, bool closedMax) const
126 {
127  if (minSet && (closedMin && sampleTime < domainMin || !closedMin && sampleTime <= domainMin))
128  {
129  return false;
130  }
131 
132  if (maxSet && (closedMax && sampleTime > domainMax || !closedMax && sampleTime >= domainMax))
133  {
134  return false;
135  }
136 
137  return true;
138 }
139 
140 #endif // __PLOTEXPRESSIONBINDDOMAIN_H_
Binding failed due to a failure to match curves.
Definition: plotexpressionbinddomain.h:18
void domainUnion(PlotExpressionBindDomain &result, const PlotExpressionBindDomain &a, const PlotExpressionBindDomain &b)
Finds the union of two domains, a and b.
size_t sampleCount
The number of samples to be generated.
Definition: plotexpressionbinddomain.h:54
Binding succeeded, multiple bindings may be possible.
Definition: plotexpressionbinddomain.h:20
void setUnbounded()
Sets the domain to be unbounded.
Definition: plotexpressionbinddomain.h:117
Core data for binding a PlotExpression.
Definition: plotexpressionbinddomain.h:49
double domainMin
The minimum value to be passed to PlotExpression::sample().
Definition: plotexpressionbinddomain.h:51
bool contains(double sampleTime, bool closedMin=true, bool closedMax=true) const
Checks if sampleTime lies within the domain.
Definition: plotexpressionbinddomain.h:125
bool minSet
domainMin is set and relevant.
Definition: plotexpressionbinddomain.h:55
BindResult
Return values for the PlotExpression::bind() method.
Definition: plotexpressionbinddomain.h:15
double sampleDelta
Time delta between calls to PlotExpression::sample().
Definition: plotexpressionbinddomain.h:53
bool isUnbounded() const
Returns true if the domain is unbounded.
Definition: plotexpressionbinddomain.h:68
Binding succeeded, no further attempts required.
Definition: plotexpressionbinddomain.h:19
bool maxSet
domainMax is set and relevant.
Definition: plotexpressionbinddomain.h:56
double domainMax
The maximum value to be passed to PlotExpression::sample().
Definition: plotexpressionbinddomain.h:52
Binding failed due to an error.
Definition: plotexpressionbinddomain.h:17
PlotExpressionBindDomain()
Constructor. Creates an unbounded domain.
Definition: plotexpressionbinddomain.h:59