types.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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 : LargeUInt; dwOrigin : Longint; out libNewPosition : LargeUInt) : HResult;stdcall;
  265. function SetSize(libNewSize : LargeUInt) : HRESULT;stdcall;
  266. function CopyTo(stm: IStream;cb : LargeUInt;out cbRead : LargeUInt; out cbWritten : LargeUInt) : HRESULT;stdcall;
  267. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  268. function Revert : HRESULT;stdcall;
  269. function LockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : Longint) : HRESULT;stdcall;
  270. function UnlockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : Longint) : HRESULT;stdcall;
  271. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  272. function Clone(out stm : IStream) : HRESULT;stdcall;
  273. end;
  274. function EqualRect(const r1,r2 : TRect) : Boolean;
  275. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  276. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  277. function Point(x,y : Integer) : TPoint; inline;
  278. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  279. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  280. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  281. function IsRectEmpty(const Rect : TRect) : Boolean;
  282. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  283. function CenterPoint(const Rect: TRect): TPoint;
  284. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  285. function Size(AWidth, AHeight: Integer): TSize;
  286. function Size(const ARect: TRect): TSize;
  287. implementation
  288. Uses Math;
  289. {$ifndef Windows}
  290. {$i typshrd.inc}
  291. {$endif}
  292. function EqualRect(const r1,r2 : TRect) : Boolean;
  293. begin
  294. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  295. end;
  296. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  297. begin
  298. Rect.Left:=Left;
  299. Rect.Top:=Top;
  300. Rect.Right:=Right;
  301. Rect.Bottom:=Bottom;
  302. end;
  303. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  304. begin
  305. Bounds.Left:=ALeft;
  306. Bounds.Top:=ATop;
  307. Bounds.Right:=ALeft+AWidth;
  308. Bounds.Bottom:=ATop+AHeight;
  309. end;
  310. function Point(x,y : Integer) : TPoint; inline;
  311. begin
  312. Point.x:=x;
  313. Point.y:=y;
  314. end;
  315. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  316. begin
  317. PtInRect:=(p.y>=Rect.Top) and
  318. (p.y<Rect.Bottom) and
  319. (p.x>=Rect.Left) and
  320. (p.x<Rect.Right);
  321. end;
  322. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  323. var
  324. lRect: TRect;
  325. begin
  326. lRect := R1;
  327. if R2.Left > R1.Left then
  328. lRect.Left := R2.Left;
  329. if R2.Top > R1.Top then
  330. lRect.Top := R2.Top;
  331. if R2.Right < R1.Right then
  332. lRect.Right := R2.Right;
  333. if R2.Bottom < R1.Bottom then
  334. lRect.Bottom := R2.Bottom;
  335. // The var parameter is only assigned in the end to avoid problems
  336. // when passing the same rectangle in the var and const parameters.
  337. // See http://bugs.freepascal.org/view.php?id=17722
  338. if IsRectEmpty(lRect) then
  339. begin
  340. FillChar(Rect,SizeOf(Rect),0);
  341. IntersectRect:=false;
  342. end
  343. else
  344. begin
  345. IntersectRect:=true;
  346. Rect := lRect;
  347. end;
  348. end;
  349. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  350. var
  351. lRect: TRect;
  352. begin
  353. lRect:=R1;
  354. if R2.Left<R1.Left then
  355. lRect.Left:=R2.Left;
  356. if R2.Top<R1.Top then
  357. lRect.Top:=R2.Top;
  358. if R2.Right>R1.Right then
  359. lRect.Right:=R2.Right;
  360. if R2.Bottom>R1.Bottom then
  361. lRect.Bottom:=R2.Bottom;
  362. if IsRectEmpty(lRect) then
  363. begin
  364. FillChar(Rect,SizeOf(Rect),0);
  365. UnionRect:=false;
  366. end
  367. else
  368. begin
  369. Rect:=lRect;
  370. UnionRect:=true;
  371. end;
  372. end;
  373. function IsRectEmpty(const Rect : TRect) : Boolean;
  374. begin
  375. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  376. end;
  377. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  378. begin
  379. if assigned(@Rect) then
  380. begin
  381. with Rect do
  382. begin
  383. inc(Left,dx);
  384. inc(Top,dy);
  385. inc(Right,dx);
  386. inc(Bottom,dy);
  387. end;
  388. OffsetRect:=true;
  389. end
  390. else
  391. OffsetRect:=false;
  392. end;
  393. function Avg(a, b: Longint): Longint;
  394. begin
  395. if a < b then
  396. Result := a + ((b - a) shr 1)
  397. else
  398. Result := b + ((a - b) shr 1);
  399. end;
  400. function CenterPoint(const Rect: TRect): TPoint;
  401. begin
  402. with Rect do
  403. begin
  404. Result.X := Avg(Left, Right);
  405. Result.Y := Avg(Top, Bottom);
  406. end;
  407. end;
  408. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  409. begin
  410. if Assigned(@Rect) then
  411. begin
  412. with Rect do
  413. begin
  414. dec(Left, dx);
  415. dec(Top, dy);
  416. inc(Right, dx);
  417. inc(Bottom, dy);
  418. end;
  419. Result := True;
  420. end
  421. else
  422. Result := False;
  423. end;
  424. function Size(AWidth, AHeight: Integer): TSize;
  425. begin
  426. Result.cx := AWidth;
  427. Result.cy := AHeight;
  428. end;
  429. function Size(const ARect: TRect): TSize;
  430. begin
  431. Result.cx := ARect.Right - ARect.Left;
  432. Result.cy := ARect.Bottom - ARect.Top;
  433. end;
  434. { TPointF}
  435. function TPointF.Add(const apt: TPoint): TPointF;
  436. begin
  437. result.x:=x+apt.x;
  438. result.y:=y+apt.y;
  439. end;
  440. function TPointF.Add(const apt: TPointF): TPointF;
  441. begin
  442. result.x:=x+apt.x;
  443. result.y:=y+apt.y;
  444. end;
  445. function TPointF.Subtract(const apt : TPointF): TPointF;
  446. begin
  447. result.x:=x-apt.x;
  448. result.y:=y-apt.y;
  449. end;
  450. function TPointF.Subtract(const apt: TPoint): TPointF;
  451. begin
  452. result.x:=x-apt.x;
  453. result.y:=y-apt.y;
  454. end;
  455. function TPointF.Distance(const apt : TPointF) : Single;
  456. begin
  457. result:=sqrt(sqr(apt.x-x)+sqr(apt.y-y));
  458. end;
  459. function TPointF.DotProduct(const apt: TPointF): Single;
  460. begin
  461. result:=x*apt.x+y*apt.y;
  462. end;
  463. function TPointF.IsZero : Boolean;
  464. begin
  465. result:=SameValue(x,0.0) and SameValue(y,0.0);
  466. end;
  467. procedure TPointF.Offset(const apt :TPointF);
  468. begin
  469. x:=x+apt.x;
  470. y:=y+apt.y;
  471. end;
  472. procedure TPointF.Offset(const apt: TPoint);
  473. begin
  474. x:=x+apt.x;
  475. y:=y+apt.y;
  476. end;
  477. procedure TPointF.Offset(dx,dy : Longint);
  478. begin
  479. x:=x+dx;
  480. y:=y+dy;
  481. end;
  482. function TPointF.Scale(afactor: Single): TPointF;
  483. begin
  484. result.x:=afactor*x;
  485. result.y:=afactor*y;
  486. end;
  487. function TPointF.Ceiling: TPoint;
  488. begin
  489. result.x:=ceil(x);
  490. result.y:=ceil(y);
  491. end;
  492. function TPointF.Truncate: TPoint;
  493. begin
  494. result.x:=trunc(x);
  495. result.y:=trunc(y);
  496. end;
  497. function TPointF.Floor: TPoint;
  498. begin
  499. result.x:=Math.floor(x);
  500. result.y:=Math.floor(y);
  501. end;
  502. function TPointF.Round: TPoint;
  503. begin
  504. result.x:=System.round(x);
  505. result.y:=System.round(y);
  506. end;
  507. function TPointF.Length: Single;
  508. begin //distance(self) ?
  509. result:=sqrt(sqr(x)+sqr(y));
  510. end;
  511. class operator TPointF.= (const apt1, apt2 : TPointF) : Boolean;
  512. begin
  513. result:=SameValue(apt1.x,apt2.x) and SameValue(apt1.y,apt2.y);
  514. end;
  515. class operator TPointF.<> (const apt1, apt2 : TPointF): Boolean;
  516. begin
  517. result:=NOT (SameValue(apt1.x,apt2.x) and Samevalue(apt1.y,apt2.y));
  518. end;
  519. class operator TPointF. * (const apt1, apt2: TPointF): Single;
  520. begin
  521. result:=apt1.x*apt2.x + apt1.y*apt2.y;
  522. end;
  523. class operator TPointF. * (afactor: single; const apt1: TPointF): TPointF;
  524. begin
  525. result:=apt1.Scale(afactor);
  526. end;
  527. class operator TPointF. * (const apt1: TPointF; afactor: single): TPointF;
  528. begin
  529. result:=apt1.Scale(afactor);
  530. end;
  531. class operator TPointF.+ (const apt1, apt2 : TPointF): TPointF;
  532. begin
  533. result.x:=apt1.x+apt2.x;
  534. result.y:=apt1.y+apt2.y;
  535. end;
  536. class operator TPointF.- (const apt1, apt2 : TPointF): TPointF;
  537. begin
  538. result.x:=apt1.x-apt2.x;
  539. result.y:=apt1.y-apt2.y;
  540. end;
  541. class operator TPointF. - (const apt1: TPointF): TPointF;
  542. begin
  543. Result.x:=-apt1.x;
  544. Result.y:=-apt1.y;
  545. end;
  546. procedure TPointF.SetLocation(const apt :TPointF);
  547. begin
  548. x:=apt.x; y:=apt.y;
  549. end;
  550. procedure TPointF.SetLocation(const apt: TPoint);
  551. begin
  552. x:=apt.x; y:=apt.y;
  553. end;
  554. procedure TPointF.SetLocation(ax,ay : Longint);
  555. begin
  556. x:=ax; y:=ay;
  557. end;
  558. { TRectF }
  559. function TRectF.GetHeight: Single;
  560. begin
  561. result:=bottom-top;
  562. end;
  563. function TRectF.GetWidth: Single;
  564. begin
  565. result:=right-left;
  566. end;
  567. procedure TRectF.SetHeight(AValue: Single);
  568. begin
  569. bottom:=top+avalue;
  570. end;
  571. procedure TRectF.SetWidth(AValue: Single);
  572. begin
  573. right:=left+avalue;
  574. end;
  575. function TRectF.Union(const r: TRectF): TRectF;
  576. begin
  577. result.left:=min(r.left,left);
  578. result.top:=min(r.top,top);
  579. result.right:=min(r.right,right);
  580. result.bottom:=min(r.bottom,bottom);
  581. end;
  582. procedure TRectF.Offset(const dx, dy: Single);
  583. begin
  584. left:=left+dx; right:=right+dx;
  585. bottom:=bottom+dy; top:=top+dy;
  586. end;
  587. end.