File: state.cc

package info (click to toggle)
epix 1.2.10-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,160 kB
  • sloc: cpp: 16,442; sh: 5,058; makefile: 198
file content (509 lines) | stat: -rw-r--r-- 9,837 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/* 
 * state.cc -- ePiX's current drawing state
 *
 * This file is part of ePiX, a C++ library for creating high-quality 
 * figures in LaTeX 
 *
 * Version 1.1.22
 * Last Change: September 24, 2007
 */

/* 
 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
 * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh>
 * Department of Mathematics and Computer Science
 * College of the Holy Cross
 * Worcester, MA, 01610-2395, USA
 */

/*
 * ePiX is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * ePiX is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ePiX; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include "constants.h"
#include "errors.h"
#include "triples.h"
#include "Color.h"

#include "length.h"

#include "camera.h"

#include "angle_units.h"
#include "arrow_style.h"
#include "label_style.h"
#include "marker_style.h"
#include "paint_style.h"
#include "path_style.h"

#include "active_screen.h"
#include "screen.h"

#include "clipping.h"

#include "state.h"

namespace ePiX {

  // set camera position
  void viewpoint(const P& arg)
  {
    cam().at(arg);
  }

  void viewpoint(double x1, double x2, double x3)
  {
    cam().at(P(x1, x2, x3));
  }

  // Set angular mode
  void radians()
  {
    the_angle_style().set_radians_mode();
  }

  void degrees()
  {
    the_angle_style().set_degrees_mode();
  }

  void revolutions()
  {
    the_angle_style().set_revolutions_mode();
  }


  // number of current units in a full turn
  double full_turn()
  {
    return the_angle_style().from_degrees(360.0);
  }


  // clipping is always on
  void clip(bool arg) { }

  void clip_box()
  {
    the_clip_box() = clip_state();
  }

  void clip_box(const P& arg1, const P& arg2)
  {
    the_clip_box() = clip_state(arg1, arg2);
  }

  void clip_to(const P& arg)
  {
    the_clip_box() = clip_state(P(0,0,0), arg);
  }

  void clip_box(const P& arg)
  {
    the_clip_box() = clip_state(-arg, arg);
  }

  // add a clip face; perp points inward
  void clip_face(const P& loc, const P& perp)
  {
    the_clip_box().add_face(loc, perp);
  }

  // add parallel clip planes
  void clip_slice(const P& loc, const P& perp)
  {
    the_clip_box().add_face(loc-0.5*EPIX_EPSILON*perp, perp)
      .add_face(loc+0.5*EPIX_EPSILON*perp, -perp);
  }

  void clip_slice(const P& perp, double thickness)
  {
    clip_slice(P(0,0,0), perp, thickness);
  }

  void clip_slice(const P& perp)
  {
    clip_slice(P(0,0,0), perp);
  }

  void clip_slice(const P& loc, const P& perp, double thickness)
  {
    the_clip_box().add_face(loc-0.5*thickness*perp, perp)
      .add_face(loc+0.5*thickness*perp, -perp);
  }

  // remove user-specified clip planes, preserve clip box settings
  void clip_restore()
  {
    the_clip_box().clear_extras();
  }


  // Set crop state and select region
  void set_crop(bool arg)
  {
    active_screen()->set_crop(arg);
  }

  void crop()
  {
    active_screen()->crop();
  }

  void crop_rectangle(const P& sw, const P& ne)
  {
    active_screen()->crop_mask_rectangle(sw, ne).set_crop(true);
  }

  void crop_ellipse(const P& sw, const P& ne)
  {
    active_screen()->crop_mask_ellipse(sw, ne).set_crop(true);
  }

  void crop_diamond(const P& sw, const P& ne)
  {
    active_screen()->crop_mask_diamond(sw, ne).set_crop(true);
  }

  void crop_rectangle()
  {
    active_screen()->crop_mask_rectangle().set_crop(true);
  }

  void crop_ellipse()
  {
    active_screen()->crop_mask_ellipse().set_crop(true);
  }

  void crop_diamond()
  {
    active_screen()->crop_mask_diamond().set_crop(true);
  }


  void crop_box(const P& arg1, const P& arg2)
  {
    active_screen()->crop_mask_rectangle(arg1, arg2).set_crop(true);
  }

  void crop_box() // (re)set active crop box to active bounding box
  {
    active_screen()->crop_mask_rectangle().set_crop(true);
  }


  // Set font size and face, label angle, mask color
  void font_size(const std::string& arg)
  {
    the_label_style().fontsize(arg);
  }

  void font_face(const std::string& arg)
  {
    the_label_style().fontface(arg);
  }

  void label_color(const Color& col)
  {
    the_label_style().text_color(col);
  }

  void label_angle(double th)
  {
    the_label_style().label_angle(th);
  }

  void label_mask(const Color& arg)
  {
    the_label_style().mask_color(arg);
  }

  void label_mask()
  {
    the_label_style().mask_color(White());
  }

  void label_pad(std::string len)
  {
    the_label_style().label_padding(length(len));
  }

  void label_border(const Color& col, double len)
  {
    the_label_style().label_border(pen_data(col, length(len)));
  }

  void label_border(const Color& col, std::string len)
  {
    the_label_style().label_border(pen_data(col, len));
  }

  // set color only
  void label_border(const Color& col)
  {
    length len(the_label_style().label_border().width());
    the_label_style().label_border(pen_data(col, len));
  }

  // set width only
  void label_border(double len)
  {
    Color col(the_label_style().label_border().color());
    the_label_style().label_border(pen_data(col, length(len)));
  }

  void label_border(std::string len)
  {
    Color col(the_label_style().label_border().color());
    the_label_style().label_border(pen_data(col, len));
  }

  void no_label_border()
  {
    label_border("0pt");
  }


  // Gray depth, path filling, [fill color]
  void gray(double depth)
  {
    the_paint_style().fill_color(Black(depth));
  }

  // new function
  void fill(const Color& col)
  {
    the_paint_style().fill_color(col);
    the_paint_style().fill_flag(!col.is_unset());
  }

  void fill(bool arg)
  {
    the_paint_style().fill_flag(arg);
    if (arg && the_paint_style().fill_color().is_unset())
      the_paint_style().fill_color(White());
  }

  void nofill()
  {
    the_paint_style().fill_flag(false);
  }


  // Arrowhead parameters
  void arrow_width(double w)
    {
      the_arrowhead_style().width(w);
    }

  void arrow_ratio(double r)
    {
      the_arrowhead_style().ratio(r);
    }

  void arrow_inset(double arg)
    {
      the_arrowhead_style().inset(arg);
    }

  void arrow_fill(bool fill)
    {
      the_arrowhead_style().fill(fill);
    }


  // Set (approximate) length of dashes, dot separation
  void dash_size(double len)
  {
    the_path_style().separation(len);
  }

  void dot_sep(double len)
  {
    dash_size(len);
  }

  // Dot/box marker size
  void dot_size(double diam)
  {
    the_mark_size().dot_size(diam);
  }

  void tick_size(double len)
  {
    the_mark_size().tick_size(len);
  }

  // Line style
  void line_style(std::string style)
  {
    the_path_style() = path_state(style);
  }

  void solid()
  {
    line_style("-");
  }

  void dashed()
  {
    line_style("-  -");
  }

  void dotted()
  {
    line_style(" . ");
  }


  // Line width
  void pen(const std::string& len)
  {
    the_paint_style().line_width(length(len));
  }

  void pen(double wd)
  {
    the_paint_style().line_width(length(wd));
  }


  void bbold()
  {
    the_paint_style().line_width(BBOLD_WIDTH);
  }

  void bold()
  {
    the_paint_style().line_width(BOLD_WIDTH);
  }

  void plain()
  {
    the_paint_style().line_width(PLAIN_WIDTH);
  }

  // line width and color
  void bbold(const Color& col)
  {
    the_paint_style().line_color(col);
    the_paint_style().line_width(BBOLD_WIDTH);
  }

  void bold(const Color& col)
  {
    the_paint_style().line_color(col);
    the_paint_style().line_width(BOLD_WIDTH);
  }

  void plain(const Color& col)
  {
    the_paint_style().line_color(col);
    the_paint_style().line_width(PLAIN_WIDTH);
  }

  void pen(const Color& col)
  {
    the_paint_style().line_color(col);
  }
  void pen(const Color& col, double len)
  {
    the_paint_style().line_color(col);
    the_paint_style().line_width(length(len));
  }
  void pen(const Color& col, std::string len)
  {
    the_paint_style().line_color(col);
    the_paint_style().line_width(length(len));
  }

  // base width and color
  void base(const Color& col)
  {
    the_paint_style().base_color(col);
  }
  void base(const Color& col, double len)
  {
    the_paint_style().base_color(col);
    the_paint_style().base_width(length(len));
  }
  void base(const Color& col, std::string len)
  {
    the_paint_style().base_color(col);
    the_paint_style().base_width(length(len));
  }


  // Red-Blue-Green
  void rgb(double r, double g, double b)
  {
    the_paint_style().line_color(RGB(r, g, b));
    the_paint_style().fill_color(RGB(r, g, b));
    the_label_style().text_color(RGB(r, g, b));
  }

  // Cyan-Magenta-Yellow-Black
  void cmyk(double c, double m, double y, double k)
  {
    the_paint_style().line_color(CMYK(c, m, y, k));
    the_paint_style().fill_color(CMYK(c, m, y, k));
    the_label_style().text_color(CMYK(c, m, y, k));
  }

  void rgb(const P& arg)
  {
    rgb(arg.x1(), arg.x2(), arg.x3());
  }

  void cmyk(const P& arg)
  {
    cmyk(arg.x1(), arg.x2(), arg.x3(), 0);
  }

  // primary colors
  void red(double d)
  {
    rgb(d,0,0);
  }
  void green(double d)
  {
    rgb(0,d,0);
  }
  void blue(double d)
  {
    rgb(0,0,d);
  }
  void white(double d)
  {
    rgb(d,d,d);
  }
  void black(double d)
  {
    rgb(1-d,1-d,1-d);
  }

  void cyan(double d)
  {
    cmyk(d,0,0,0);
  }
  void magenta(double d)
  {
    cmyk(0,d,0,0);
  }
  void yellow(double d)
  {
    cmyk(0,0,d,0);
  }
} // end of namespace