libsbml-draw
allen.h
Go to the documentation of this file.
1 /* MIT License
2 */
3 
4 //== FILEDOC =========================================================================
5 
10 //== BEGINNING OF CODE ===============================================================
11 
12 #ifndef __SBNW_ALLEN_H_
13 #define __SBNW_ALLEN_H_
14 
15 //== INCLUDES ========================================================================
16 
17 #include "SagittariusCore.h"
18 #include "min_max.h"
19 
20 //-- C++ code --
21 #ifdef __cplusplus
22 
23 namespace LibsbmlDraw {
24 
25  class Interval {
26  public:
28  Interval(const Real a, const Real b) {
29  if(a <= b) {
30  _a = a;
31  _b = b;
32  } else {
33  _a = b;
34  _b = a;
35  }
36  }
37 
39  Real a() const { return _a; }
40 
42  Real& a() { return _a; }
43 
44  Real b() const { return _b; }
45 
46  Real& b() { return _b; }
47  private:
49  Real _a, _b;
50  };
51 
53  inline Real allenDist(const Real u, const Real v, const Real x, const Real y) {
54  if(!(v < x || y < u))
55  //intersect
56  return 0.;
57  Real a = x-v, b=u-y; //one will be negative
58  return max(a,b);
59  }
60 
62  inline Real allenOrdered(const Real u, const Real v, const Real x, const Real y) {
63  // think of it like the result of b-a, where b and a are intervals
64  if(!(v < x || y < u))
65  //intersect
66  return 0.;
67  if(v < x)
68  return x-v; //positive
69  else
70  return y-u; //negative
71  }
72 
74  inline bool pointInInterval(const Real p, const Interval& i) {
75  return (i.a() <= p && p <= i.b()) ? true : false;
76  }
77 
78 }
79 
80 #endif
81 
82 #endif
SAGITTARIUS_REAL Real
Make Real visible to C. Consider letting Real lie in top namespace.
Definition: SagittariusCommon.h:112
Min & max for reals.
First file included.