types.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2002 by Florian Klaempfl,
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$MODE OBJFPC}
  12. unit Types;
  13. interface
  14. {$modeswitch advancedrecords}
  15. {$modeswitch class}
  16. {$if defined(win32) or defined(win64) or defined(wince)}
  17. uses
  18. Windows;
  19. {$elseif defined(win16)}
  20. uses
  21. WinTypes;
  22. {$endif}
  23. {$if defined(win32) or defined(win64)}
  24. const
  25. RT_RCDATA = Windows.RT_RCDATA deprecated 'Use Windows.RT_RCDATA instead';
  26. {$elseif defined(win16)}
  27. const
  28. RT_RCDATA = WinTypes.RT_RCDATA deprecated 'Use WinTypes.RT_RCDATA instead';
  29. {$endif}
  30. type
  31. TEndian = Objpas.TEndian;
  32. TDirection = (FromBeginning, FromEnd);
  33. TValueRelationship = -1..1;
  34. DWORD = LongWord;
  35. PLongint = System.PLongint;
  36. PSmallInt = System.PSmallInt;
  37. {$ifndef FPUNONE}
  38. PDouble = System.PDouble;
  39. {$endif}
  40. PByte = System.PByte;
  41. Largeint = int64;
  42. LARGE_INT = LargeInt;
  43. PLargeInt = ^LargeInt;
  44. LargeUint = qword;
  45. LARGE_UINT= LargeUInt;
  46. PLargeuInt = ^LargeuInt;
  47. TBooleanDynArray = array of Boolean;
  48. TByteDynArray = array of Byte;
  49. TCardinalDynArray = array of Cardinal;
  50. TInt64DynArray = array of Int64;
  51. TIntegerDynArray = array of Integer;
  52. TLongWordDynArray = array of LongWord;
  53. TPointerDynArray = array of Pointer;
  54. TQWordDynArray = array of QWord;
  55. TShortIntDynArray = array of ShortInt;
  56. TSmallIntDynArray = array of SmallInt;
  57. TStringDynArray = array of AnsiString;
  58. TWideStringDynArray = array of WideString;
  59. TWordDynArray = array of Word;
  60. TCurrencyArray = Array of currency;
  61. {$ifndef FPUNONE}
  62. TSingleDynArray = array of Single;
  63. TDoubleDynArray = array of Double;
  64. TExtendedDynArray = array of Extended;
  65. TCompDynArray = array of Comp;
  66. {$endif}
  67. {$if defined(win32) or defined(win64) or defined(wince)}
  68. TArray4IntegerType = Windows.TArray4IntegerType;
  69. TSmallPoint = Windows.TSmallPoint;
  70. PSmallPoint = Windows.PSmallPoint;
  71. TSize = Windows.TSize;
  72. TagSize = Windows.tagSize deprecated;
  73. PSize = Windows.PSize;
  74. TPoint = Windows.TPoint;
  75. TagPoint = Windows.TagPoint deprecated;
  76. PPoint = Windows.PPoint;
  77. TRect = Windows.TRect;
  78. PRect = Windows.PRect;
  79. TSplitRectType = Windows.TSplitRectType;
  80. const
  81. srLeft = TSplitRectType.srLeft;
  82. srRight = TSplitRectType.srRight;
  83. srTop = TSplitRectType.srTop;
  84. srBottom = TSplitRectType.srBottom;
  85. type
  86. {$else}
  87. {$i typshrdh.inc}
  88. TagSize = tSize deprecated;
  89. TagPoint = TPoint deprecated;
  90. {$endif}
  91. { TPointF }
  92. TPointF =
  93. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  94. packed
  95. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  96. record
  97. x,y : Single;
  98. public
  99. function Add(const apt: TPoint): TPointF;
  100. function Add(const apt: TPointF): TPointF;
  101. function Distance(const apt : TPointF) : Single;
  102. function DotProduct(const apt : TPointF) : Single;
  103. function IsZero : Boolean;
  104. function Subtract(const apt : TPointF): TPointF;
  105. function Subtract(const apt : TPoint): TPointF;
  106. procedure SetLocation(const apt :TPointF);
  107. procedure SetLocation(const apt :TPoint);
  108. procedure SetLocation(ax,ay : Longint);
  109. procedure Offset(const apt :TPointF);
  110. procedure Offset(const apt :TPoint);
  111. procedure Offset(dx,dy : Longint);
  112. function Scale (afactor:Single) : TPointF;
  113. function Ceiling : TPoint;
  114. function Truncate: TPoint;
  115. function Floor : TPoint;
  116. function Round : TPoint;
  117. function Length : Single;
  118. class operator = (const apt1, apt2 : TPointF) : Boolean;
  119. class operator <> (const apt1, apt2 : TPointF): Boolean;
  120. class operator + (const apt1, apt2 : TPointF): TPointF;
  121. class operator - (const apt1, apt2 : TPointF): TPointF;
  122. class operator - (const apt1 : TPointF): TPointF;
  123. class operator * (const apt1, apt2: TPointF): Single; // scalar product
  124. class operator * (const apt1: TPointF; afactor: single): TPointF;
  125. class operator * (afactor: single; const apt1: TPointF): TPointF;
  126. end;
  127. { TRectF }
  128. TRectF =
  129. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  130. packed
  131. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  132. record
  133. private
  134. function GetHeight: Single; inline;
  135. function GetWidth: Single; inline;
  136. procedure SetHeight(AValue: Single);
  137. procedure SetWidth (AValue: Single);
  138. public
  139. function Union (const r: TRectF):TRectF; inline;
  140. procedure Offset (const dx,dy : Single); inline;
  141. property Width : Single read GetWidth write SetWidth;
  142. property Height : Single read GetHeight write SetHeight;
  143. case Integer of
  144. 0: (Left, Top, Right, Bottom: Single);
  145. 1: (TopLeft, BottomRight: TPointF);
  146. end;
  147. TDuplicates = (dupIgnore, dupAccept, dupError);
  148. type
  149. TOleChar = WideChar;
  150. POleStr = PWideChar;
  151. PPOleStr = ^POleStr;
  152. TListCallback = procedure(data,arg:pointer) of object;
  153. TListStaticCallback = procedure(data,arg:pointer);
  154. const
  155. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  156. STGTY_STORAGE = 1;
  157. STGTY_STREAM = 2;
  158. STGTY_LOCKBYTES = 3;
  159. STGTY_PROPERTY = 4;
  160. STREAM_SEEK_SET = 0;
  161. STREAM_SEEK_CUR = 1;
  162. STREAM_SEEK_END = 2;
  163. LOCK_WRITE = 1;
  164. LOCK_EXCLUSIVE = 2;
  165. LOCK_ONLYONCE = 4;
  166. STATFLAG_DEFAULT = 0;
  167. STATFLAG_NONAME = 1;
  168. STATFLAG_NOOPEN = 2;
  169. {$ifndef Wince}
  170. // in Wince these are in unit windows. Under 32/64 in ActiveX.
  171. // for now duplicate them. Not that bad for untyped constants.
  172. E_FAIL = HRESULT($80004005);
  173. E_INVALIDARG = HRESULT($80070057);
  174. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  175. STG_E_FILENOTFOUND = HRESULT($80030002);
  176. STG_E_PATHNOTFOUND = HRESULT($80030003);
  177. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  178. STG_E_ACCESSDENIED = HRESULT($80030005);
  179. STG_E_INVALIDHANDLE = HRESULT($80030006);
  180. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  181. STG_E_INVALIDPOINTER = HRESULT($80030009);
  182. STG_E_NOMOREFILES = HRESULT($80030012);
  183. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  184. STG_E_SEEKERROR = HRESULT($80030019);
  185. STG_E_WRITEFAULT = HRESULT($8003001D);
  186. STG_E_READFAULT = HRESULT($8003001E);
  187. STG_E_SHAREVIOLATION = HRESULT($80030020);
  188. STG_E_LOCKVIOLATION = HRESULT($80030021);
  189. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  190. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  191. STG_E_MEDIUMFULL = HRESULT($80030070);
  192. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  193. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  194. STG_E_INVALIDHEADER = HRESULT($800300FB);
  195. STG_E_INVALIDNAME = HRESULT($800300FC);
  196. STG_E_UNKNOWN = HRESULT($800300FD);
  197. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  198. STG_E_INVALIDFLAG = HRESULT($800300FF);
  199. STG_E_INUSE = HRESULT($80030100);
  200. STG_E_NOTCURRENT = HRESULT($80030101);
  201. STG_E_REVERTED = HRESULT($80030102);
  202. STG_E_CANTSAVE = HRESULT($80030103);
  203. STG_E_OLDFORMAT = HRESULT($80030104);
  204. STG_E_OLDDLL = HRESULT($80030105);
  205. STG_E_SHAREREQUIRED = HRESULT($80030106);
  206. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  207. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  208. STG_E_BADBASEADDRESS = HRESULT($80030110);
  209. STG_E_INCOMPLETE = HRESULT($80030201);
  210. STG_E_TERMINATED = HRESULT($80030202);
  211. STG_S_CONVERTED = $00030200;
  212. STG_S_BLOCK = $00030201;
  213. STG_S_RETRYNOW = $00030202;
  214. STG_S_MONITORING = $00030203;
  215. {$endif}
  216. {$if (not defined(win32)) and (not defined(win64)) and (not defined(wince))}
  217. type
  218. PCLSID = PGUID;
  219. TCLSID = TGUID;
  220. PDWord = ^DWord;
  221. PDisplay = Pointer;
  222. PEvent = Pointer;
  223. TXrmOptionDescRec = record
  224. end;
  225. XrmOptionDescRec = TXrmOptionDescRec;
  226. PXrmOptionDescRec = ^TXrmOptionDescRec;
  227. Widget = Pointer;
  228. WidgetClass = Pointer;
  229. ArgList = Pointer;
  230. Region = Pointer;
  231. _FILETIME =
  232. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  233. packed
  234. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  235. record
  236. dwLowDateTime : DWORD;
  237. dwHighDateTime : DWORD;
  238. end;
  239. TFileTime = _FILETIME;
  240. FILETIME = _FILETIME;
  241. PFileTime = ^TFileTime;
  242. {$else}
  243. type
  244. PCLSID = Windows.PCLSID;
  245. TCLSID = Windows.CLSID;
  246. TFiletime = Windows.TFileTime;
  247. Filetime = Windows.FileTime;
  248. PFiletime = Windows.PFileTime;
  249. {$endif Windows}
  250. type
  251. tagSTATSTG = record
  252. pwcsName : POleStr;
  253. dwType : DWord;
  254. cbSize : Large_uint;
  255. mtime : TFileTime;
  256. ctime : TFileTime;
  257. atime : TFileTime;
  258. grfMode : DWord;
  259. grfLocksSupported : DWord;
  260. clsid : TCLSID;
  261. grfStateBits : DWord;
  262. reserved : DWord;
  263. end;
  264. TStatStg = tagSTATSTG;
  265. STATSTG = TStatStg;
  266. PStatStg = ^TStatStg;
  267. { classes depends on these interfaces, we can't use the activex unit in classes though }
  268. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  269. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  270. Function LockServer(fLock : LongBool) : HResult;StdCall;
  271. End;
  272. ISequentialStream = interface(IUnknown)
  273. ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  274. function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
  275. function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
  276. end;
  277. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  278. function Seek(dlibMove : LargeInt; dwOrigin : DWORD; out libNewPosition : LargeUInt) : HResult;stdcall;
  279. function SetSize(libNewSize : LargeUInt) : HRESULT;stdcall;
  280. function CopyTo(stm: IStream;cb : LargeUInt;out cbRead : LargeUInt; out cbWritten : LargeUInt) : HRESULT;stdcall;
  281. function Commit(grfCommitFlags : DWORD) : HRESULT;stdcall;
  282. function Revert : HRESULT;stdcall;
  283. function LockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : DWORD) : HRESULT;stdcall;
  284. function UnlockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : DWORD) : HRESULT;stdcall;
  285. Function Stat(out statstg : TStatStg;grfStatFlag : DWORD) : HRESULT;stdcall;
  286. function Clone(out stm : IStream) : HRESULT;stdcall;
  287. end;
  288. function EqualRect(const r1,r2 : TRect) : Boolean;
  289. function Rect(Left,Top,Right,Bottom : Integer) : TRect; inline;
  290. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect; inline;
  291. function Point(x,y : Integer) : TPoint; inline;
  292. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  293. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  294. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  295. function IsRectEmpty(const Rect : TRect) : Boolean;
  296. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  297. function CenterPoint(const Rect: TRect): TPoint;
  298. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  299. function Size(AWidth, AHeight: Integer): TSize; inline;
  300. function Size(const ARect: TRect): TSize;
  301. implementation
  302. Uses Math;
  303. {$if (not defined(win32)) and (not defined(win64)) and (not defined(wince))}
  304. {$i typshrd.inc}
  305. {$endif}
  306. function EqualRect(const r1,r2 : TRect) : Boolean;
  307. begin
  308. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  309. end;
  310. function Rect(Left,Top,Right,Bottom : Integer) : TRect; inline;
  311. begin
  312. Rect.Left:=Left;
  313. Rect.Top:=Top;
  314. Rect.Right:=Right;
  315. Rect.Bottom:=Bottom;
  316. end;
  317. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect; inline;
  318. begin
  319. Bounds.Left:=ALeft;
  320. Bounds.Top:=ATop;
  321. Bounds.Right:=ALeft+AWidth;
  322. Bounds.Bottom:=ATop+AHeight;
  323. end;
  324. function Point(x,y : Integer) : TPoint; inline;
  325. begin
  326. Point.x:=x;
  327. Point.y:=y;
  328. end;
  329. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  330. begin
  331. PtInRect:=(p.y>=Rect.Top) and
  332. (p.y<Rect.Bottom) and
  333. (p.x>=Rect.Left) and
  334. (p.x<Rect.Right);
  335. end;
  336. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  337. var
  338. lRect: TRect;
  339. begin
  340. lRect := R1;
  341. if R2.Left > R1.Left then
  342. lRect.Left := R2.Left;
  343. if R2.Top > R1.Top then
  344. lRect.Top := R2.Top;
  345. if R2.Right < R1.Right then
  346. lRect.Right := R2.Right;
  347. if R2.Bottom < R1.Bottom then
  348. lRect.Bottom := R2.Bottom;
  349. // The var parameter is only assigned in the end to avoid problems
  350. // when passing the same rectangle in the var and const parameters.
  351. // See http://bugs.freepascal.org/view.php?id=17722
  352. if IsRectEmpty(lRect) then
  353. begin
  354. FillChar(Rect,SizeOf(Rect),0);
  355. IntersectRect:=false;
  356. end
  357. else
  358. begin
  359. IntersectRect:=true;
  360. Rect := lRect;
  361. end;
  362. end;
  363. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  364. var
  365. lRect: TRect;
  366. begin
  367. lRect:=R1;
  368. if R2.Left<R1.Left then
  369. lRect.Left:=R2.Left;
  370. if R2.Top<R1.Top then
  371. lRect.Top:=R2.Top;
  372. if R2.Right>R1.Right then
  373. lRect.Right:=R2.Right;
  374. if R2.Bottom>R1.Bottom then
  375. lRect.Bottom:=R2.Bottom;
  376. if IsRectEmpty(lRect) then
  377. begin
  378. FillChar(Rect,SizeOf(Rect),0);
  379. UnionRect:=false;
  380. end
  381. else
  382. begin
  383. Rect:=lRect;
  384. UnionRect:=true;
  385. end;
  386. end;
  387. function IsRectEmpty(const Rect : TRect) : Boolean;
  388. begin
  389. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  390. end;
  391. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  392. begin
  393. if assigned(@Rect) then
  394. begin
  395. with Rect do
  396. begin
  397. inc(Left,dx);
  398. inc(Top,dy);
  399. inc(Right,dx);
  400. inc(Bottom,dy);
  401. end;
  402. OffsetRect:=true;
  403. end
  404. else
  405. OffsetRect:=false;
  406. end;
  407. function Avg(a, b: Longint): Longint;
  408. begin
  409. if a < b then
  410. Result := a + ((b - a) shr 1)
  411. else
  412. Result := b + ((a - b) shr 1);
  413. end;
  414. function CenterPoint(const Rect: TRect): TPoint;
  415. begin
  416. with Rect do
  417. begin
  418. Result.X := Avg(Left, Right);
  419. Result.Y := Avg(Top, Bottom);
  420. end;
  421. end;
  422. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  423. begin
  424. if Assigned(@Rect) then
  425. begin
  426. with Rect do
  427. begin
  428. dec(Left, dx);
  429. dec(Top, dy);
  430. inc(Right, dx);
  431. inc(Bottom, dy);
  432. end;
  433. Result := True;
  434. end
  435. else
  436. Result := False;
  437. end;
  438. function Size(AWidth, AHeight: Integer): TSize; inline;
  439. begin
  440. Result.cx := AWidth;
  441. Result.cy := AHeight;
  442. end;
  443. function Size(const ARect: TRect): TSize; inline;
  444. begin
  445. Result.cx := ARect.Right - ARect.Left;
  446. Result.cy := ARect.Bottom - ARect.Top;
  447. end;
  448. { TPointF}
  449. function TPointF.Add(const apt: TPoint): TPointF;
  450. begin
  451. result.x:=x+apt.x;
  452. result.y:=y+apt.y;
  453. end;
  454. function TPointF.Add(const apt: TPointF): TPointF;
  455. begin
  456. result.x:=x+apt.x;
  457. result.y:=y+apt.y;
  458. end;
  459. function TPointF.Subtract(const apt : TPointF): TPointF;
  460. begin
  461. result.x:=x-apt.x;
  462. result.y:=y-apt.y;
  463. end;
  464. function TPointF.Subtract(const apt: TPoint): TPointF;
  465. begin
  466. result.x:=x-apt.x;
  467. result.y:=y-apt.y;
  468. end;
  469. function TPointF.Distance(const apt : TPointF) : Single;
  470. begin
  471. result:=sqrt(sqr(apt.x-x)+sqr(apt.y-y));
  472. end;
  473. function TPointF.DotProduct(const apt: TPointF): Single;
  474. begin
  475. result:=x*apt.x+y*apt.y;
  476. end;
  477. function TPointF.IsZero : Boolean;
  478. begin
  479. result:=SameValue(x,0.0) and SameValue(y,0.0);
  480. end;
  481. procedure TPointF.Offset(const apt :TPointF);
  482. begin
  483. x:=x+apt.x;
  484. y:=y+apt.y;
  485. end;
  486. procedure TPointF.Offset(const apt: TPoint);
  487. begin
  488. x:=x+apt.x;
  489. y:=y+apt.y;
  490. end;
  491. procedure TPointF.Offset(dx,dy : Longint);
  492. begin
  493. x:=x+dx;
  494. y:=y+dy;
  495. end;
  496. function TPointF.Scale(afactor: Single): TPointF;
  497. begin
  498. result.x:=afactor*x;
  499. result.y:=afactor*y;
  500. end;
  501. function TPointF.Ceiling: TPoint;
  502. begin
  503. result.x:=ceil(x);
  504. result.y:=ceil(y);
  505. end;
  506. function TPointF.Truncate: TPoint;
  507. begin
  508. result.x:=trunc(x);
  509. result.y:=trunc(y);
  510. end;
  511. function TPointF.Floor: TPoint;
  512. begin
  513. result.x:=Math.floor(x);
  514. result.y:=Math.floor(y);
  515. end;
  516. function TPointF.Round: TPoint;
  517. begin
  518. result.x:=System.round(x);
  519. result.y:=System.round(y);
  520. end;
  521. function TPointF.Length: Single;
  522. begin //distance(self) ?
  523. result:=sqrt(sqr(x)+sqr(y));
  524. end;
  525. class operator TPointF.= (const apt1, apt2 : TPointF) : Boolean;
  526. begin
  527. result:=SameValue(apt1.x,apt2.x) and SameValue(apt1.y,apt2.y);
  528. end;
  529. class operator TPointF.<> (const apt1, apt2 : TPointF): Boolean;
  530. begin
  531. result:=NOT (SameValue(apt1.x,apt2.x) and Samevalue(apt1.y,apt2.y));
  532. end;
  533. class operator TPointF. * (const apt1, apt2: TPointF): Single;
  534. begin
  535. result:=apt1.x*apt2.x + apt1.y*apt2.y;
  536. end;
  537. class operator TPointF. * (afactor: single; const apt1: TPointF): TPointF;
  538. begin
  539. result:=apt1.Scale(afactor);
  540. end;
  541. class operator TPointF. * (const apt1: TPointF; afactor: single): TPointF;
  542. begin
  543. result:=apt1.Scale(afactor);
  544. end;
  545. class operator TPointF.+ (const apt1, apt2 : TPointF): TPointF;
  546. begin
  547. result.x:=apt1.x+apt2.x;
  548. result.y:=apt1.y+apt2.y;
  549. end;
  550. class operator TPointF.- (const apt1, apt2 : TPointF): TPointF;
  551. begin
  552. result.x:=apt1.x-apt2.x;
  553. result.y:=apt1.y-apt2.y;
  554. end;
  555. class operator TPointF. - (const apt1: TPointF): TPointF;
  556. begin
  557. Result.x:=-apt1.x;
  558. Result.y:=-apt1.y;
  559. end;
  560. procedure TPointF.SetLocation(const apt :TPointF);
  561. begin
  562. x:=apt.x; y:=apt.y;
  563. end;
  564. procedure TPointF.SetLocation(const apt: TPoint);
  565. begin
  566. x:=apt.x; y:=apt.y;
  567. end;
  568. procedure TPointF.SetLocation(ax,ay : Longint);
  569. begin
  570. x:=ax; y:=ay;
  571. end;
  572. { TRectF }
  573. function TRectF.GetHeight: Single;
  574. begin
  575. result:=bottom-top;
  576. end;
  577. function TRectF.GetWidth: Single;
  578. begin
  579. result:=right-left;
  580. end;
  581. procedure TRectF.SetHeight(AValue: Single);
  582. begin
  583. bottom:=top+avalue;
  584. end;
  585. procedure TRectF.SetWidth(AValue: Single);
  586. begin
  587. right:=left+avalue;
  588. end;
  589. function TRectF.Union(const r: TRectF): TRectF;
  590. begin
  591. result.left:=min(r.left,left);
  592. result.top:=min(r.top,top);
  593. result.right:=min(r.right,right);
  594. result.bottom:=min(r.bottom,bottom);
  595. end;
  596. procedure TRectF.Offset(const dx, dy: Single);
  597. begin
  598. left:=left+dx; right:=right+dx;
  599. bottom:=bottom+dy; top:=top+dy;
  600. end;
  601. end.