-
Notifications
You must be signed in to change notification settings - Fork 0
/
UPoints.pas
executable file
·167 lines (136 loc) · 3.34 KB
/
UPoints.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
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
unit UPoints;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Contnrs;
type
{ TDigPoint }
TDigPoint=class
private
fX: double;
fY: double;
public
constructor Create( ix, iy: integer);
procedure Change(ix, iy: integer);
property X: double read fX;
property Y: double read fY;
end;
{ TDigPointsList }
TDigPointsList=class(TObjectList)
private
fCurrent: TDigPoint;
fScale: double;
StartX, StartY, EndX, EndY: double;
CosFI, SinFI: double;
function GetCurrentX: double;
function GetCurrentY: double;
function CalcX(Point: TDigPoint):double;
function CalcY(Point: TDigPoint):double;
function GetPoints(i: integer): TDigPoint;
function GetX(i: integer): double;
function GetY(i: integer): double;
public
constructor Create;
destructor Destroy; override;
procedure AddPoint(ix, iy: integer);
procedure SetXaxis( SX, SY, EX, EY: integer);
function SaveToText:TStringList;
property Current: TDigPoint read fCurrent;
property CurrentX: double read GetCurrentX;
property CurrentY: double read GetCurrentY;
property Points[i: integer]: TDigPoint read GetPoints;
property X[i:integer]: double read GetX;
property Y[i:integer]: double read GetY;
property Scale:double read fScale write fScale;
end;
implementation
{ TDigPointsList }
constructor TDigPointsList.Create;
begin
inherited Create(true);
fCurrent := TDigPoint.Create(0,0);
Scale:=1;
end;
destructor TDigPointsList.Destroy;
begin
FreeAndNil(fCurrent);
inherited Destroy;
end;
function TDigPointsList.GetCurrentX: double;
begin
result:=CalcX(Current);
end;
function TDigPointsList.GetCurrentY: double;
begin
result:=CalcY(Current);
end;
function TDigPointsList.CalcX(Point: TDigPoint): double;
var
DX, DY: double;
begin
DX := Point.X-StartX;
DY := StartY-Point.Y;
result:=(DX*CosFI+DY*sinFi)*Scale;
end;
function TDigPointsList.CalcY(Point: TDigPoint): double;
var
DX, DY: double;
begin
DX := Point.X-StartX;
DY := StartY-Point.Y;
result:=(-DX*SinFI+DY*CosFi)*Scale;
end;
function TDigPointsList.GetPoints(i: integer): TDigPoint;
begin
result:=Items[i] as TDigPoint;
end;
function TDigPointsList.GetX(i: integer): double;
begin
result:=CalcX(Points[i]);
end;
function TDigPointsList.GetY(i: integer): double;
begin
result:=CalcY(Points[i]);
end;
procedure TDigPointsList.AddPoint(ix, iy: integer);
begin
Add(TDigPoint.Create(ix, iy));
end;
procedure TDigPointsList.SetXaxis(SX, SY, EX, EY: integer);
var
L: double;
begin
StartX:=SX;
StartY:=SY;
EndX:=EX;
EndY:=EY;
L:=sqrt(sqr(EX-SX)+sqr(EY-SY));
CosFI:=(EX-SX)/L;
SinFI:=(SY-EY)/L; // на картинке ось Y идет вниз, а нам надо вверх
end;
function TDigPointsList.SaveToText: TStringList;
var
S: TStringList;
i: integer;
begin
result:=nil;
if Count=0 then exit;
S:=TStringList.Create;
for i:=0 to count-1 do
begin
S.Add(FormatFloat('0.00',X[i])+' , '+FormatFloat('0.00',Y[i]));
end;
result:=S;
end;
{ TDigPoint }
constructor TDigPoint.Create(ix, iy: integer);
begin
fX:=ix;
fY:=iy;
end;
procedure TDigPoint.Change(ix, iy: integer);
begin
fX:=ix;
fY:=iy;
end;
end.