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 #pragma once
26 
27 #include <InterViews/coord.h>
28 
29 #include <InterViews/_enter.h>
30 
31 /*
32  * Can't make DimensionName an enum because we want to be able
33  * to iterate from 0 to number_of_dimensions. Alas,
34  * C++ does not allow arithmetic on enums.
35  */
36 typedef unsigned int DimensionName;
37 
38 enum {
40 };
41 
43 public:
44  enum { x = 0, y, z, dimensions };
45 #ifdef _DELTA_EXTENSIONS
46 #pragma __static_class
47 #endif
48 };
49 
50 class Requirement {
51 public:
52  Requirement();
56  Coord natural_lead, Coord max_lead, Coord min_lead,
57  Coord natural_trail, Coord max_trail, Coord min_trail
58  );
59 
60  bool equals(const Requirement&, float epsilon) const;
61  bool defined() const;
62 
63  void natural(Coord);
64  Coord natural() const;
65 
66  void stretch(Coord);
67  Coord stretch() const;
68 
69  void shrink(Coord);
70  Coord shrink() const;
71 
72  void alignment(float);
73  float alignment() const;
74 private:
78  float alignment_;
79 #ifdef _DELTA_EXTENSIONS
80 #pragma __static_class
81 #endif
82 };
83 
84 class Requisition {
85 public:
88 
89  void penalty(int);
90  int penalty() const;
91 
92  bool equals(const Requisition&, float epsilon) const;
94  void require_x(const Requirement&);
95  void require_y(const Requirement&);
97  const Requirement& x_requirement() const;
98  const Requirement& y_requirement() const;
102 private:
103  int penalty_;
106 #ifdef _DELTA_EXTENSIONS
107 #pragma __static_class
108 #endif
109 };
110 
111 class Allotment {
112 public:
113  Allotment();
115 
116  bool equals(const Allotment&, float epsilon) const;
117 
118  void origin(Coord);
119  void offset(Coord);
120  Coord origin() const;
121  void span(Coord);
122  Coord span() const;
123 
124  void alignment(float);
125  float alignment() const;
126 
127  Coord begin() const;
128  Coord end() const;
129 private:
132  float alignment_;
133 #ifdef _DELTA_EXTENSIONS
134 #pragma __static_class
135 #endif
136 };
137 
138 class Allocation {
139 public:
142 
143  bool equals(const Allocation&, float epsilon) const;
144 
146  void allot_x(const Allotment&);
147  void allot_y(const Allotment&);
152  const Allotment& x_allotment() const;
153  const Allotment& y_allotment() const;
154 
155  Coord x() const;
156  Coord y() const;
157  Coord left() const;
158  Coord right() const;
159  Coord bottom() const;
160  Coord top() const;
161 private:
164 #ifdef _DELTA_EXTENSIONS
165 #pragma __static_class
166 #endif
167 };
168 
169 class Canvas;
170 
171 class Extension {
172 public:
175 
176  void operator =(const Extension&);
177 
178  static void transform_xy(
180  );
181 
182  void set(Canvas*, const Allocation&);
184  void clear();
185 
186  void merge(const Extension&);
187  void merge(Canvas*, const Allocation&);
189 
190  Coord left() const;
191  Coord bottom() const;
192  Coord right() const;
193  Coord top() const;
194 private:
199 #ifdef _DELTA_EXTENSIONS
200 #pragma __static_class
201 #endif
202 };
203 
205  natural_ = -fil;
206  stretch_ = 0;
207  shrink_ = 0;
208  alignment_ = 0;
209 }
210 
212  natural_ = natural;
213  stretch_ = 0;
214  shrink_ = 0;
215  alignment_ = 0;
216 }
217 
219  Coord natural, Coord stretch, Coord shrink, float alignment
220 ) {
221  natural_ = natural;
222  stretch_ = stretch;
223  shrink_ = shrink;
225 }
226 
227 inline bool Requirement::defined() const {
228  return natural_ != -fil;
229 }
230 
231 inline void Requirement::natural(Coord c) { natural_ = c; }
232 inline Coord Requirement::natural() const { return natural_; }
233 inline void Requirement::stretch(Coord c) { stretch_ = c; }
234 inline Coord Requirement::stretch() const { return stretch_; }
235 inline void Requirement::shrink(Coord c) { shrink_ = c; }
236 inline Coord Requirement::shrink() const { return shrink_; }
237 inline void Requirement::alignment(float a) { alignment_ = a; }
238 inline float Requirement::alignment() const { return alignment_; }
239 
240 inline int Requisition::penalty() const { return penalty_; }
241 inline void Requisition::penalty(int penalty) { penalty_ = penalty; }
242 
243 inline void Requisition::require_x(const Requirement& r) { x_ = r; }
244 inline void Requisition::require_y(const Requirement& r) { y_ = r; }
245 inline const Requirement& Requisition::x_requirement() const { return x_; }
246 inline const Requirement& Requisition::y_requirement() const { return y_; }
249 
251  origin_ = 0;
252  span_ = 0;
253  alignment_ = 0;
254 }
255 
256 inline Allotment::Allotment(Coord origin, Coord span, float alignment) {
257  origin_ = origin;
258  span_ = span;
260 }
261 
262 inline void Allotment::origin(Coord o) { origin_ = o; }
263 inline void Allotment::offset(Coord o) { origin_ += o; }
264 inline Coord Allotment::origin() const { return origin_; }
265 inline void Allotment::span(Coord c) { span_ = c; }
266 inline Coord Allotment::span() const { return span_; }
267 inline void Allotment::alignment(float a) { alignment_ = a; }
268 inline float Allotment::alignment() const { return alignment_; }
269 
270 inline Coord Allotment::begin() const {
271  return origin_ - Coord(alignment_ * span_);
272 }
273 
274 inline Coord Allotment::end() const {
275  return origin_ - Coord(alignment_ * span_) + span_;
276 }
277 
278 inline void Allocation::allot_x(const Allotment& a) { x_ = a; }
279 inline void Allocation::allot_y(const Allotment& a) { y_ = a; }
280 
281 inline Allotment& Allocation::x_allotment() { return x_; }
282 inline Allotment& Allocation::y_allotment() { return y_; }
283 inline const Allotment& Allocation::x_allotment() const { return x_; }
284 inline const Allotment& Allocation::y_allotment() const { return y_; }
285 
286 inline Coord Allocation::x() const { return x_.origin(); }
287 inline Coord Allocation::y() const { return y_.origin(); }
288 inline Coord Allocation::left() const { return x_.begin(); }
289 inline Coord Allocation::right() const { return x_.end(); }
290 inline Coord Allocation::bottom() const { return y_.begin(); }
291 inline Coord Allocation::top() const { return y_.end(); }
292 
293 inline Coord Extension::left() const { return x_begin_; }
294 inline Coord Extension::bottom() const { return y_begin_; }
295 inline Coord Extension::right() const { return x_end_; }
296 inline Coord Extension::top() const { return y_end_; }
297 
298 #include <InterViews/_leave.h>
#define Canvas
Definition: _defines.h:63
#define Coord
Definition: _defines.h:17
Allotment y_
Definition: geometry.h:163
Coord right() const
Definition: geometry.h:289
Coord top() const
Definition: geometry.h:291
Allocation(const Allocation &)
Coord x() const
Definition: geometry.h:286
void allot_y(const Allotment &)
Definition: geometry.h:279
Coord left() const
Definition: geometry.h:288
Allotment x_
Definition: geometry.h:162
bool equals(const Allocation &, float epsilon) const
Allotment & allotment(DimensionName)
Coord bottom() const
Definition: geometry.h:290
void allot(DimensionName, const Allotment &)
const Allotment & allotment(DimensionName) const
Coord y() const
Definition: geometry.h:287
Allotment & x_allotment()
Definition: geometry.h:281
Allotment & y_allotment()
Definition: geometry.h:282
void allot_x(const Allotment &)
Definition: geometry.h:278
Allotment()
Definition: geometry.h:250
Coord span() const
Definition: geometry.h:266
Coord origin() const
Definition: geometry.h:264
Coord begin() const
Definition: geometry.h:270
void offset(Coord)
Definition: geometry.h:263
Coord origin_
Definition: geometry.h:130
float alignment() const
Definition: geometry.h:268
void origin(Coord)
Definition: geometry.h:262
bool equals(const Allotment &, float epsilon) const
Coord end() const
Definition: geometry.h:274
Coord span_
Definition: geometry.h:131
float alignment_
Definition: geometry.h:132
Coord left() const
Definition: geometry.h:293
void merge(Canvas *, const Allocation &)
void merge(const Extension &)
void set_xy(Canvas *, Coord left, Coord bottom, Coord right, Coord top)
Coord top() const
Definition: geometry.h:296
Extension(const Extension &)
void clear()
Coord y_begin_
Definition: geometry.h:197
Coord x_end_
Definition: geometry.h:196
void operator=(const Extension &)
void set(Canvas *, const Allocation &)
Coord bottom() const
Definition: geometry.h:294
Coord right() const
Definition: geometry.h:295
static void transform_xy(Canvas *, Coord &left, Coord &bottom, Coord &right, Coord &top)
Coord x_begin_
Definition: geometry.h:195
Coord y_end_
Definition: geometry.h:198
void merge_xy(Canvas *, Coord left, Coord bottom, Coord right, Coord top)
Coord natural_
Definition: geometry.h:75
bool equals(const Requirement &, float epsilon) const
float alignment_
Definition: geometry.h:78
bool defined() const
Definition: geometry.h:227
Coord natural() const
Definition: geometry.h:232
float alignment() const
Definition: geometry.h:238
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:234
Coord shrink() const
Definition: geometry.h:236
Coord shrink_
Definition: geometry.h:77
Coord stretch_
Definition: geometry.h:76
int penalty_
Definition: geometry.h:103
void require_x(const Requirement &)
Definition: geometry.h:243
const Requirement & x_requirement() const
Definition: geometry.h:245
Requirement y_
Definition: geometry.h:105
Requirement & requirement(DimensionName)
int penalty() const
Definition: geometry.h:240
void require(DimensionName, const Requirement &)
Requirement x_
Definition: geometry.h:104
void require_y(const Requirement &)
Definition: geometry.h:244
Requisition(const Requisition &)
bool equals(const Requisition &, float epsilon) const
const Requirement & requirement(DimensionName) const
const Requirement & y_requirement() const
Definition: geometry.h:246
#define fil
Definition: coord.h:41
@ Dimension_Y
Definition: geometry.h:39
@ Dimension_Undefined
Definition: geometry.h:39
@ Dimension_Z
Definition: geometry.h:39
@ Dimension_X
Definition: geometry.h:39
unsigned int DimensionName
Definition: geometry.h:36
static int c
Definition: hoc.cpp:169