~ubuntu-branches/ubuntu/trusty/mricron/trusty-proposed

« back to all changes in this revision

Viewing changes to npm/dmath/plot.inc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-07-29 22:07:43 UTC
  • Revision ID: james.westby@ubuntu.com-20100729220743-q621ts2zj806gu0n
Tags: upstream-0.20100725.1~dfsg.1
ImportĀ upstreamĀ versionĀ 0.20100725.1~dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{ **********************************************************************
 
2
  *                               PLOT.INC                             *
 
3
  **********************************************************************
 
4
         Variables and routines common to PLOT.PAS and WINPLOT.PAS
 
5
  ********************************************************************** }
 
6
 
 
7
var
 
8
  XminPixel, YminPixel : Integer;  { Pixel coord. of upper left corner }
 
9
  XmaxPixel, YmaxPixel : Integer;  { Pixel coord. of lower right corner }
 
10
  FactX, FactY         : Float;    { Scaling factors }
 
11
 
 
12
  function Xpixel(X : Float) : Integer;
 
13
  var
 
14
    P : Float;
 
15
  begin
 
16
    P := FactX * (X - XAxis.Min);
 
17
    if Abs(P) > 30000 then
 
18
      Xpixel := 30000
 
19
    else
 
20
      Xpixel := Round(P) + XminPixel;
 
21
  end;
 
22
 
 
23
  function Ypixel(Y : Float) : Integer;
 
24
  var
 
25
    P : Float;
 
26
  begin
 
27
    P := FactY * (YAxis.Max - Y);
 
28
    if Abs(P) > 30000 then
 
29
      Ypixel := 30000
 
30
    else
 
31
      Ypixel := Round(P) + YminPixel;
 
32
  end;
 
33
 
 
34
  function Xuser(X : Integer) : Float;
 
35
  begin
 
36
    Xuser := XAxis.Min + (X - XminPixel) / FactX;
 
37
  end;
 
38
 
 
39
  function Yuser(Y : Integer) : Float;
 
40
  begin
 
41
    Yuser := YAxis.Max - (Y - YminPixel) / FactY;
 
42
  end;
 
43
 
 
44
  procedure Interval(X1, X2 : Float; MinDiv, MaxDiv : Integer;
 
45
                     var Min, Max, Step : Float);
 
46
  var
 
47
    H, R, K : Float;
 
48
  begin
 
49
    if X1 >= X2 then Exit;
 
50
    H := X2 - X1;
 
51
    R := Int(Log10(H));
 
52
    if H < 1.0 then R := R - 1.0;
 
53
    Step := Exp10(R);
 
54
 
 
55
    repeat
 
56
      K := Int(H / Step);
 
57
      if K < MinDiv then Step := 0.5 * Step;
 
58
      if K > MaxDiv then Step := 2.0 * Step;
 
59
    until (K >= MinDiv) and (K <= MaxDiv);
 
60
 
 
61
    Min := Step * Int(X1 / Step);
 
62
    Max := Step * Int(X2 / Step);
 
63
    while Min > X1 do Min := Min - Step;
 
64
    while Max < X2 do Max := Max + Step;
 
65
  end;
 
66
 
 
67
  procedure AutoScale(Z : PVector; Lbound, Ubound : Integer;
 
68
                      var Axis : TAxis);
 
69
  var
 
70
    I                  : Integer;
 
71
    Zmin, Zmax, Z1, Z2 : Float;
 
72
  begin
 
73
    if Axis.Scale = LIN_SCALE then
 
74
      Interval(Min(Z, Lbound, Ubound), Max(Z, Lbound, Ubound),
 
75
               2, 6, Axis.Min, Axis.Max, Axis.Step)
 
76
    else
 
77
      begin
 
78
        Zmin := MAXNUM; Zmax := 0.0;
 
79
        for I := Lbound to Ubound do
 
80
          if Z^[I] > 0.0 then
 
81
            if Z^[I] < Zmin then
 
82
              Zmin := Z^[I]
 
83
            else if Z^[I] > Zmax then
 
84
              Zmax := Z^[I];
 
85
        Z1 := Int(Log10(Zmin));
 
86
        Z2 := Int(Log10(Zmax));
 
87
        if Zmin < 1.0 then Z1 := Z1 - 1.0;
 
88
        if Zmax > 1.0 then Z2 := Z2 + 1.0;
 
89
        Axis.Min := Z1;
 
90
        Axis.Max := Z2;
 
91
        Axis.Step := 1.0;
 
92
      end;
 
93
  end;
 
94