libpgplotxx.a (C++ interface to PGPLOT)
structs.h
Go to the documentation of this file.
1 
19 // include guard
20 #ifndef TF_PGPLOTSTRUCTS_H_VERSION
21 
22 #define TF_PGPLOTSTRUCTS_H_VERSION \
23  "TF_PGPLOTSTRUCTS_H V1.0 (17-03-2015)"
24 
25 namespace pgplot {
26 
32 
42 struct Trange {
44  float min,max;
46  Trange(const float& themin, const float& themax):
47  min(themin), max(themax) { }
49  Trange(const Trange& range):
50  min(range.min), max(range.max) { }
52  Trange(): min(0.), max(0.) { }
54  Trange& extend(const Trange& range) {
55  min=(min < range.min ? min : range.min);
56  max=(max > range.max ? max : range.max);
57  return(*this);
58  }
60  Trange& extendf(const float& f) {
61  float d=f*this->abs();
62  min -= d;
63  max += d;
64  return(*this);
65  }
67  Trange& shrink(const Trange& range) {
68  min=(min > range.min ? min : range.min);
69  max=(max < range.max ? max : range.max);
70  return(*this);
71  }
73  Trange& shrinkf(const Trange& range) {
74  float ar=this->fullrange();
75  max=min+ar*range.max;
76  min=min+ar*range.min;
77  return(*this);
78  }
80  float absmax() const {
81  float amin=(min < 0 ? -min : min);
82  float amax=(max < 0 ? -max : max);
83  return(amax > amin ? amax : amin);
84  }
86  float abs() const {
87  float absrange=this->fullrange();
88  return(absrange > 0 ? absrange : -absrange);
89  }
91  float fullrange() const { return(max-min); }
93  Trange& lcutf(const float& fraction)
94  { min=min+fraction*(max-min); return(*this); }
96  Trange& hcutf(const float& fraction)
97  { max=max-fraction*(max-min); return(*this); }
99  Trange& lcut(const float& value)
100  { min+=value; return(*this); }
102  Trange& hcut(const float& value)
103  { max-=value; return(*this); }
105  template<typename T>
106  Trange& operator*=(const T& value)
107  { min*=value; max*=value; return(*this); }
109  Trange& operator*=(const Trange& range)
110  {
111  // order matters!
112  float d=this->fullrange();
113  max=min+range.max*d;
114  min+=range.min*d;
115  return(*this);
116  }
118  Trange& swap() { float junk=min; min=max; max=junk; return(*this); }
120  bool contains(const float& v) const { return((v>=this->min) &&
121  (v<=this->max)); }
122 }; // struct Trange
123 
124 /*----------------------------------------------------------------------*/
125 
130 struct Trect {
134  Trect(const float& xmin, const float& xmax,
135  const float& ymin, const float& ymax):
136  x(Trange(xmin,xmax)), y(Trange(ymin,ymax)) { }
138  Trect(const Trect& rect):
139  x(rect.x), y(rect.y) { }
141  Trect(const Trange& thex, const Trange& they): x(thex), y(they) { }
143  Trect(): x(0.,0.), y(0.,0.) { }
145  Trect& lcutf(const float& fraction)
146  { x.lcutf(fraction); return(*this); }
148  Trect& rcutf(const float& fraction)
149  { x.hcutf(fraction); return(*this); }
151  Trect& tcutf(const float& fraction)
152  { y.hcutf(fraction); return(*this); }
154  Trect& bcutf(const float& fraction)
155  { y.lcutf(fraction); return(*this); }
157  Trect& lcut(const float& fraction)
158  { x.lcut(fraction); return(*this); }
160  Trect& rcut(const float& fraction)
161  { x.hcut(fraction); return(*this); }
163  Trect& tcut(const float& fraction)
164  { y.hcut(fraction); return(*this); }
166  Trect& bcut(const float& fraction)
167  { y.lcut(fraction); return(*this); }
169  Trect& shrinkf(const Trect& rect)
170  { x.shrinkf(rect.x); y.shrinkf(rect.y); return(*this); }
172  Trect& shift(const float& dx, const float& dy)
173  { x.min+=dx; x.max+=dx; y.min+=dy; y.max+=dy; return(*this); }
175  Trect& shift(const Trange& off)
176  { this->shift(off.min, off.max); return(*this); }
178  Trect& operator*=(const Trect& rect)
179  { x*=rect.x; y*=rect.y; return(*this); }
180 }; // struct Trect
181 
182 /*----------------------------------------------------------------------*/
183 
186 struct Tcoor {
187  float x;
188  float y;
189  Tcoor& operator+=(const Tcoor& c)
191  { this->x+=c.x; this->y+=c.y; return(*this); }
194  { Tcoor r=(*this); return(r += c); }
196  bool inside(const Trect& r) const
197  { return(r.x.contains(this->x) && r.y.contains(this->y)); }
198 }; // struct Tcoor
199 
200 /*----------------------------------------------------------------------*/
201 
204 struct Tbbox {
205  Tcoor coor[4];
206  Tbbox();
209  Tbbox(const float x[4], const float y[4]);
210 }; // struct Tbbox
211 
212 /*----------------------------------------------------------------------*/
213 
220 struct Tcol {
222  union { float r,h; };
224  union { float g,l; };
226  union { float b,s; };
227 }; // struct Tcol
228 
231 } // namespace pgplot
232 
233 #endif // TF_PGPLOTSTRUCTS_H_VERSION (includeguard)
234 
235 /* ----- END OF structs.h ----- */
Trange & lcutf(const float &fraction)
fractional cut at lower edge
Definition: structs.h:93
Tcoor operator+(const Tcoor &c)
shift coordinate by a vector c
Definition: structs.h:193
Trect & operator*=(const Trect &rect)
scale relative to other rect (for viewport calculations)
Definition: structs.h:178
Trange & swap()
swap range
Definition: structs.h:118
Trange & hcutf(const float &fraction)
fractional cut at higher edge
Definition: structs.h:96
hold coordinates
Definition: structs.h:186
Trect(const Trange &thex, const Trange &they)
set constructor
Definition: structs.h:141
Trange(const Trange &range)
copy constgructor
Definition: structs.h:49
Trect & lcut(const float &fraction)
absolute cut at left edge
Definition: structs.h:157
contains all pgplot stuff
Definition: affpgplot.cc:46
hold bounding box for text etc.
Definition: structs.h:204
float absmax() const
return absolute maximum
Definition: structs.h:80
Trange()
default constructor
Definition: structs.h:52
Trect(const Trect &rect)
copy constructor
Definition: structs.h:138
Trect & shift(const Trange &off)
shift rectangle - uses off.min=dx and off.max=dy
Definition: structs.h:175
Trect & rcutf(const float &fraction)
fractional cut at right edge
Definition: structs.h:148
Tcoor & operator+=(const Tcoor &c)
Definition: structs.h:190
Trange & shrink(const Trange &range)
shrink this range if argument range is smaller
Definition: structs.h:67
hold any parameter range
Definition: structs.h:42
Trange & operator*=(const Trange &range)
scale relative to other range
Definition: structs.h:109
Trange(const float &themin, const float &themax)
set constgructor
Definition: structs.h:46
Trange & extendf(const float &f)
extend at both ends by a fraction of total range
Definition: structs.h:60
Trange x
coordinate ranges
Definition: structs.h:132
Trect & lcutf(const float &fraction)
fractional cut at left edge
Definition: structs.h:145
Trange & extend(const Trange &range)
extend this range if argument range is larger
Definition: structs.h:54
Trect & tcut(const float &fraction)
absolute cut at top edge
Definition: structs.h:163
float fullrange() const
return absolute range
Definition: structs.h:91
bool inside(const Trect &r) const
return true if coordinate is inside rect r
Definition: structs.h:196
bool contains(const float &v) const
check if value is inside range
Definition: structs.h:120
float y
y-coordinate shift coordinate by a vector c
Definition: structs.h:188
Trange y
Definition: structs.h:132
Trect()
default constructor
Definition: structs.h:143
Tcoor coor[4]
coordinates of four corners default constructor
Definition: structs.h:205
Trange & hcut(const float &value)
absolute cut at higher edge
Definition: structs.h:102
float abs() const
return total range
Definition: structs.h:86
Trect & bcutf(const float &fraction)
fractional cut at bottom edge
Definition: structs.h:154
float min
range [min....max]
Definition: structs.h:44
Trect(const float &xmin, const float &xmax, const float &ymin, const float &ymax)
set constructor
Definition: structs.h:134
float l
Definition: structs.h:224
float s
Definition: structs.h:226
hold any rectangle
Definition: structs.h:130
a struct to hold colour triples i.e. rgb or hls values
Definition: structs.h:220
float x
x-coordinate
Definition: structs.h:187
float r
Definition: structs.h:222
float g
Definition: structs.h:224
Tbbox()
default constructor
Definition: structs.cc:26
Trect & rcut(const float &fraction)
absolute cut at right edge
Definition: structs.h:160
Trange & lcut(const float &value)
absolute cut at lower edge
Definition: structs.h:99
float b
Definition: structs.h:226
Trect & tcutf(const float &fraction)
fractional cut at top edge
Definition: structs.h:151
float max
Definition: structs.h:44
Trect & shrinkf(const Trect &rect)
fractional shrink/expand
Definition: structs.h:169
Trect & shift(const float &dx, const float &dy)
shift rectangle by dx and dy
Definition: structs.h:172
float h
Definition: structs.h:222
Trect & bcut(const float &fraction)
absolute cut at bottom edge
Definition: structs.h:166
Trange & operator*=(const T &value)
scale both values
Definition: structs.h:106
Trange & shrinkf(const Trange &range)
fractional shrink/extend
Definition: structs.h:73