NEURON
geometry.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1987, 1988, 1989, 1990, 1991 Stanford University
3  * Copyright (c) 1991 Silicon Graphics, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that (i) the above copyright notices and this permission notice appear in
8  * all copies of the software and related documentation, and (ii) the names of
9  * Stanford and Silicon Graphics may not be used in any advertising or
10  * publicity relating to the software without the specific, prior written
11  * permission of Stanford and Silicon Graphics.
12  *
13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24 
25 #ifndef iv_geometry_h
26 #define iv_geometry_h
27 #if MAC
28 #undef require
29 #endif
30 
31 #include <InterViews/coord.h>
32 
33 #include <InterViews/_enter.h>
34 
35 /*
36  * Can't make DimensionName an enum because we want to be able
37  * to iterate from 0 to number_of_dimensions. Alas,
38  * C++ does not allow arithmetic on enums.
39  */
40 typedef unsigned int DimensionName;
41 
42 enum {
44 };
45 
47 public:
48  enum { x = 0, y, z, dimensions };
49 #ifdef _DELTA_EXTENSIONS
50 #pragma __static_class
51 #endif
52 };
53 
54 class Requirement {
55 public:
56  Requirement();
60  Coord natural_lead, Coord max_lead, Coord min_lead,
61  Coord natural_trail, Coord max_trail, Coord min_trail
62  );
63 
64  bool equals(const Requirement&, float epsilon) const;
65  bool defined() const;
66 
67  void natural(Coord);
68  Coord natural() const;
69 
70  void stretch(Coord);
71  Coord stretch() const;
72 
73  void shrink(Coord);
74  Coord shrink() const;
75 
76  void alignment(float);
77  float alignment() const;
78 private:
82  float alignment_;
83 #ifdef _DELTA_EXTENSIONS
84 #pragma __static_class
85 #endif
86 };
87 
88 class Requisition {
89 public:
92 
93  void penalty(int);
94  int penalty() const;
95 
96  bool equals(const Requisition&, float epsilon) const;
98  void require_x(const Requirement&);
99  void require_y(const Requirement&);
101  const Requirement& x_requirement() const;
102  const Requirement& y_requirement() const;
106 private:
107  int penalty_;
110 #ifdef _DELTA_EXTENSIONS
111 #pragma __static_class
112 #endif
113 };
114 
115 class Allotment {
116 public:
117  Allotment();
119 
120  bool equals(const Allotment&, float epsilon) const;
121 
122  void origin(Coord);
123  void offset(Coord);
124  Coord origin() const;
125  void span(Coord);
126  Coord span() const;
127 
128  void alignment(float);
129  float alignment() const;
130 
131  Coord begin() const;
132  Coord end() const;
133 private:
136  float alignment_;
137 #ifdef _DELTA_EXTENSIONS
138 #pragma __static_class
139 #endif
140 };
141 
142 class Allocation {
143 public:
146 
147  bool equals(const Allocation&, float epsilon) const;
148 
150  void allot_x(const Allotment&);
151  void allot_y(const Allotment&);
156  const Allotment& x_allotment() const;
157  const Allotment& y_allotment() const;
158 
159  Coord x() const;
160  Coord y() const;
161  Coord left() const;
162  Coord right() const;
163  Coord bottom() const;
164  Coord top() const;
165 private:
168 #ifdef _DELTA_EXTENSIONS
169 #pragma __static_class
170 #endif
171 };
172 
173 class Canvas;
174 
175 class Extension {
176 public:
177  Extension();
179 
180  void operator =(const Extension&);
181 
182  static void transform_xy(
184  );
185 
186  void set(Canvas*, const Allocation&);
188  void clear();
189 
190  void merge(const Extension&);
191  void merge(Canvas*, const Allocation&);
193 
194  Coord left() const;
195  Coord bottom() const;
196  Coord right() const;
197  Coord top() const;
198 private:
203 #ifdef _DELTA_EXTENSIONS
204 #pragma __static_class
205 #endif
206 };
207 
209  natural_ = -fil;
210  stretch_ = 0;
211  shrink_ = 0;
212  alignment_ = 0;
213 }
214 
216  natural_ = natural;
217  stretch_ = 0;
218  shrink_ = 0;
219  alignment_ = 0;
220 }
221 
223  Coord natural, Coord stretch, Coord shrink, float alignment
224 ) {
225  natural_ = natural;
226  stretch_ = stretch;
227  shrink_ = shrink;
229 }
230 
231 inline bool Requirement::defined() const {
232  return natural_ != -fil;
233 }
234 
235 inline void Requirement::natural(Coord c) { natural_ = c; }
236 inline Coord Requirement::natural() const { return natural_; }
237 inline void Requirement::stretch(Coord c) { stretch_ = c; }
238 inline Coord Requirement::stretch() const { return stretch_; }
239 inline void Requirement::shrink(Coord c) { shrink_ = c; }
240 inline Coord Requirement::shrink() const { return shrink_; }
241 inline void Requirement::alignment(float a) { alignment_ = a; }
242 inline float Requirement::alignment() const { return alignment_; }
243 
244 inline int Requisition::penalty() const { return penalty_; }
245 inline void Requisition::penalty(int penalty) { penalty_ = penalty; }
246 
247 inline void Requisition::require_x(const Requirement& r) { x_ = r; }
248 inline void Requisition::require_y(const Requirement& r) { y_ = r; }
249 inline const Requirement& Requisition::x_requirement() const { return x_; }
250 inline const Requirement& Requisition::y_requirement() const { return y_; }
253 
255  origin_ = 0;
256  span_ = 0;
257  alignment_ = 0;
258 }
259 
260 inline Allotment::Allotment(Coord origin, Coord span, float alignment) {
261  origin_ = origin;
262  span_ = span;
264 }
265 
266 inline void Allotment::origin(Coord o) { origin_ = o; }
267 inline void Allotment::offset(Coord o) { origin_ += o; }
268 inline Coord Allotment::origin() const { return origin_; }
269 inline void Allotment::span(Coord c) { span_ = c; }
270 inline Coord Allotment::span() const { return span_; }
271 inline void Allotment::alignment(float a) { alignment_ = a; }
272 inline float Allotment::alignment() const { return alignment_; }
273 
274 inline Coord Allotment::begin() const {
275  return origin_ - Coord(alignment_ * span_);
276 }
277 
278 inline Coord Allotment::end() const {
279  return origin_ - Coord(alignment_ * span_) + span_;
280 }
281 
282 inline void Allocation::allot_x(const Allotment& a) { x_ = a; }
283 inline void Allocation::allot_y(const Allotment& a) { y_ = a; }
284 
285 inline Allotment& Allocation::x_allotment() { return x_; }
286 inline Allotment& Allocation::y_allotment() { return y_; }
287 inline const Allotment& Allocation::x_allotment() const { return x_; }
288 inline const Allotment& Allocation::y_allotment() const { return y_; }
289 
290 inline Coord Allocation::x() const { return x_.origin(); }
291 inline Coord Allocation::y() const { return y_.origin(); }
292 inline Coord Allocation::left() const { return x_.begin(); }
293 inline Coord Allocation::right() const { return x_.end(); }
294 inline Coord Allocation::bottom() const { return y_.begin(); }
295 inline Coord Allocation::top() const { return y_.end(); }
296 
297 inline Coord Extension::left() const { return x_begin_; }
298 inline Coord Extension::bottom() const { return y_begin_; }
299 inline Coord Extension::right() const { return x_end_; }
300 inline Coord Extension::top() const { return y_end_; }
301 
302 #include <InterViews/_leave.h>
303 
304 #endif
#define Canvas
Definition: _defines.h:65
#define Coord
Definition: _defines.h:19
Allotment y_
Definition: geometry.h:167
Coord right() const
Definition: geometry.h:293
Coord top() const
Definition: geometry.h:295
Allocation(const Allocation &)
Coord x() const
Definition: geometry.h:290
void allot_y(const Allotment &)
Definition: geometry.h:283
Coord left() const
Definition: geometry.h:292
Allotment x_
Definition: geometry.h:166
bool equals(const Allocation &, float epsilon) const
Allotment & allotment(DimensionName)
Coord bottom() const
Definition: geometry.h:294
void allot(DimensionName, const Allotment &)
const Allotment & allotment(DimensionName) const
Coord y() const
Definition: geometry.h:291
Allotment & x_allotment()
Definition: geometry.h:285
Allotment & y_allotment()
Definition: geometry.h:286
void allot_x(const Allotment &)
Definition: geometry.h:282
Allotment()
Definition: geometry.h:254
Coord span() const
Definition: geometry.h:270
Coord origin() const
Definition: geometry.h:268
Coord begin() const
Definition: geometry.h:274
void offset(Coord)
Definition: geometry.h:267
Coord origin_
Definition: geometry.h:134
float alignment() const
Definition: geometry.h:272
void origin(Coord)
Definition: geometry.h:266
bool equals(const Allotment &, float epsilon) const
Coord end() const
Definition: geometry.h:278
Coord span_
Definition: geometry.h:135
float alignment_
Definition: geometry.h:136
Coord left() const
Definition: geometry.h:297
void merge(Canvas *, const Allocation &)
void merge(const Extension &)
void set_xy(Canvas *, Coord left, Coord bottom, Coord right, Coord top)
Definition: math.cpp:52
Coord top() const
Definition: geometry.h:300
Extension(const Extension &)
void clear()
Coord y_begin_
Definition: geometry.h:201
Coord x_end_
Definition: geometry.h:200
void operator=(const Extension &)
void set(Canvas *, const Allocation &)
Coord bottom() const
Definition: geometry.h:298
Coord right() const
Definition: geometry.h:299
Extension()
Definition: math.cpp:50
static void transform_xy(Canvas *, Coord &left, Coord &bottom, Coord &right, Coord &top)
Coord x_begin_
Definition: geometry.h:199
Coord y_end_
Definition: geometry.h:202
void merge_xy(Canvas *, Coord left, Coord bottom, Coord right, Coord top)
Coord natural_
Definition: geometry.h:79
bool equals(const Requirement &, float epsilon) const
float alignment_
Definition: geometry.h:82
bool defined() const
Definition: geometry.h:231
Coord natural() const
Definition: geometry.h:236
float alignment() const
Definition: geometry.h:242
Requirement(Coord natural_lead, Coord max_lead, Coord min_lead, Coord natural_trail, Coord max_trail, Coord min_trail)
Coord stretch() const
Definition: geometry.h:238
Coord shrink() const
Definition: geometry.h:240
Coord shrink_
Definition: geometry.h:81
Coord stretch_
Definition: geometry.h:80
int penalty_
Definition: geometry.h:107
void require_x(const Requirement &)
Definition: geometry.h:247
const Requirement & x_requirement() const
Definition: geometry.h:249
Requirement y_
Definition: geometry.h:109
Requirement & requirement(DimensionName)
int penalty() const
Definition: geometry.h:244
void require(DimensionName, const Requirement &)
Requirement x_
Definition: geometry.h:108
void require_y(const Requirement &)
Definition: geometry.h:248
Requisition(const Requisition &)
bool equals(const Requisition &, float epsilon) const
const Requirement & requirement(DimensionName) const
const Requirement & y_requirement() const
Definition: geometry.h:250
#define fil
Definition: coord.h:42
#define c
@ Dimension_Y
Definition: geometry.h:43
@ Dimension_Undefined
Definition: geometry.h:43
@ Dimension_Z
Definition: geometry.h:43
@ Dimension_X
Definition: geometry.h:43
unsigned int DimensionName
Definition: geometry.h:40
o
Definition: seclist.cpp:175