~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to src/Typeset/Graphics/frame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : frame.cpp
 
4
* DESCRIPTION: coordinate frames
 
5
* COPYRIGHT  : (C) 2003  Joris van der Hoeven
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license and comes WITHOUT
 
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
 
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
 
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
11
******************************************************************************/
 
12
 
 
13
#include "frame.hpp"
 
14
 
 
15
/******************************************************************************
 
16
* Scalings
 
17
******************************************************************************/
 
18
 
 
19
struct scaling_rep: public frame_rep {
 
20
  double magnify;
 
21
  point  shift;
 
22
  scaling_rep (double m, point s): magnify (m), shift (s) { linear= true; }
 
23
  operator tree () {
 
24
    return tuple ("scale", as_string (magnify), as_tree (shift)); }
 
25
  point direct_transform (point p) { return shift + magnify * p; }
 
26
  point inverse_transform (point p) { return (p - shift) / magnify; }
 
27
  double direct_bound (point p, double err) { return err / magnify; }
 
28
  double inverse_bound (point p, double err) { return err * magnify; }
 
29
};
 
30
 
 
31
frame
 
32
scaling (double magnify, point shift) {
 
33
  return new scaling_rep (magnify, shift);
 
34
}
 
35
 
 
36
/******************************************************************************
 
37
* Compound frames
 
38
******************************************************************************/
 
39
 
 
40
struct compound_frame_rep: public frame_rep {
 
41
  frame f1, f2;
 
42
  compound_frame_rep (frame f1b, frame f2b):
 
43
    f1 (f1b), f2 (f2b) { linear= f1->linear && f2->linear; }
 
44
  operator tree () { return tuple ("compound", (tree) f1, (tree) f2); }
 
45
  point direct_transform (point p) { return f1 (f2 (p)); }
 
46
  point inverse_transform (point p) { return f2 [f1 [p]]; }
 
47
  double direct_bound (point p, double err) {
 
48
    return f1->direct_bound (f2(p), f2->direct_bound (p, err)); }
 
49
  double inverse_bound (point p, double err) {
 
50
    return f2->inverse_bound (f1[p], f1->inverse_bound (p, err)); }
 
51
};
 
52
 
 
53
frame
 
54
operator * (frame f1, frame f2) {
 
55
  return new compound_frame_rep (f1, f2);
 
56
}
 
57
 
 
58
/******************************************************************************
 
59
* Inverted frames
 
60
******************************************************************************/
 
61
 
 
62
struct inverted_frame_rep: public frame_rep {
 
63
  frame f;
 
64
  inverted_frame_rep (frame f2): f (f2) { linear= f->linear; }
 
65
  operator tree () { return tuple ("inverse", (tree) f); }
 
66
  point direct_transform (point p) { return f [p]; }
 
67
  point inverse_transform (point p) { return f (p); }
 
68
  double direct_bound (point p, double err) {
 
69
    return f->inverse_bound (p, err); }
 
70
  double inverse_bound (point p, double err) {
 
71
    return f->direct_bound (p, err); }
 
72
};
 
73
 
 
74
frame
 
75
invert (frame f) {
 
76
  return new inverted_frame_rep (f);
 
77
}