-
Notifications
You must be signed in to change notification settings - Fork 0
/
axissource.pas
85 lines (67 loc) · 1.41 KB
/
axissource.pas
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
unit AxisSource;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
{ tAxisSource }
tAxisSource = class
private
fCapacity: longword;
procedure SetCapacity(AValue: longword); inline;
public
Values: array of double;
Count: longword;
property Capacity: longword read fCapacity write SetCapacity;
constructor Create(InitialCap: longword = 4);
destructor Destroy; override;
procedure Add(b: array of double);
procedure Add(v: double); inline;
procedure Clear;
end;
implementation
uses
math;
{ tAxisSource }
procedure tAxisSource.SetCapacity(AValue: longword);
begin
if fCapacity = AValue then Exit;
fCapacity:= AValue;
setlength(Values, fCapacity);
end;
constructor tAxisSource.Create(InitialCap: longword = 4);
begin
Count:= 0;
if InitialCap > 4 then
Capacity:= InitialCap
else
Capacity:= 4;
end;
destructor tAxisSource.Destroy;
begin
setlength(Values, 0);
end;
procedure tAxisSource.Add(b: array of double);
var
i, c: integer;
begin
c:= Count;
Count+= length(b);
if Count > Capacity then
Capacity:= Capacity + max(Capacity shr 2, length(b));
for i:= 0 to high(b) do
Values[c + i]:= b[i];
end;
procedure tAxisSource.Add(v: double);
begin
inc(Count);
if Count > Capacity then
Capacity:= Capacity + Capacity shr 2;
Values[Count - 1]:= v;
end;
procedure tAxisSource.Clear;
begin
Count:= 0;
Capacity:= 4;
end;
end.