types.pp 18 KB

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