types.pp 17 KB

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