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

« back to all changes in this revision

Viewing changes to src/Typeset/Graphics/point.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     : point.cpp
 
4
* DESCRIPTION: points
 
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 "point.hpp"
 
14
#include "math_util.hpp"
 
15
 
 
16
point
 
17
operator + (point p1, point p2) {
 
18
  int i, n= min (N(p1), N(p2));
 
19
  point r (n);
 
20
  for (i=0; i<n; i++)
 
21
    r[i]= p1[i] + p2[i];
 
22
  return r;
 
23
}
 
24
 
 
25
point
 
26
operator - (point p1, point p2) {
 
27
  int i, n= min (N(p1), N(p2));
 
28
  point r (n);
 
29
  for (i=0; i<n; i++)
 
30
    r[i]= p1[i] - p2[i];
 
31
  return r;
 
32
}
 
33
 
 
34
point
 
35
operator * (double x, point p) {
 
36
  int i, n= N(p);
 
37
  point r (n);
 
38
  for (i=0; i<n; i++)
 
39
    r[i]= x * p[i];
 
40
  return r;
 
41
}
 
42
 
 
43
point
 
44
operator / (point p, double x) {
 
45
  int i, n= N(p);
 
46
  point r (n);
 
47
  for (i=0; i<n; i++)
 
48
    r[i]= p[i] / x;
 
49
  return r;
 
50
}
 
51
 
 
52
point
 
53
as_point (tree t) {
 
54
  if (!is_tuple (t)) return point ();
 
55
  else {
 
56
    int i, n= N(t);
 
57
    point p(n);
 
58
    for (i=0; i<n; i++)
 
59
      p[i]= as_double (t[i]);
 
60
    return p;
 
61
  }
 
62
}
 
63
 
 
64
tree
 
65
as_tree (point p) {
 
66
  int i, n= N(p);
 
67
  tree t (TUPLE, n);
 
68
  for (i=0; i<n; i++)
 
69
    t[i]= as_string (p[i]);
 
70
  return t;
 
71
}
 
72
 
 
73
double
 
74
operator * (point p1, point p2) {
 
75
  int i, n= min (N(p1), N(p2));
 
76
  double r= 0;
 
77
  for (i=0; i<n; i++)
 
78
    r+= p1[i] * p2[i];
 
79
  return r;
 
80
}
 
81
 
 
82
double
 
83
norm (point p) {
 
84
  return sqrt (p*p);
 
85
}