types.pp 18 KB

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