types.pp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit Types;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$modeswitch advancedrecords}
  17. {$modeswitch class}
  18. {$if defined(win32) or defined(win64) or defined(wince)}
  19. uses
  20. {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows;
  21. {$elseif defined(win16)}
  22. uses
  23. {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}WinTypes;
  24. {$endif}
  25. {$if defined(win32) or defined(win64)}
  26. const
  27. RT_RCDATA = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.RT_RCDATA deprecated 'Use Windows.RT_RCDATA instead';
  28. {$elseif defined(win16)}
  29. const
  30. RT_RCDATA = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}WinTypes.RT_RCDATA deprecated 'Use WinTypes.RT_RCDATA instead';
  31. {$endif}
  32. type
  33. TEndian = Objpas.TEndian;
  34. TDirection = (FromBeginning, FromEnd);
  35. TValueRelationship = -1..1;
  36. DWORD = LongWord;
  37. PLongint = System.PLongint;
  38. PSmallInt = System.PSmallInt;
  39. {$ifndef FPUNONE}
  40. PDouble = System.PDouble;
  41. {$endif}
  42. PByte = System.PByte;
  43. Largeint = int64;
  44. LARGE_INT = LargeInt;
  45. PLargeInt = ^LargeInt;
  46. LargeUint = qword;
  47. LARGE_UINT= LargeUInt;
  48. PLargeuInt = ^LargeuInt;
  49. TBooleanDynArray = array of Boolean;
  50. TByteDynArray = array of Byte;
  51. TCardinalDynArray = array of Cardinal;
  52. TInt64DynArray = array of Int64;
  53. TIntegerDynArray = array of Integer;
  54. TLongWordDynArray = array of LongWord;
  55. TPointerDynArray = array of Pointer;
  56. TQWordDynArray = array of QWord;
  57. TShortIntDynArray = array of ShortInt;
  58. TSmallIntDynArray = array of SmallInt;
  59. TRTLStringDynArray = array of RTLString;
  60. TAnsiStringDynArray = Array of AnsiString;
  61. TWideStringDynArray = array of WideString;
  62. TUnicodeStringDynArray = array of UnicodeString;
  63. {$if SIZEOF(CHAR)=2}
  64. TStringDynArray = Array of UnicodeString;
  65. {$ELSE}
  66. TStringDynArray = Array of AnsiString;
  67. {$ENDIF}
  68. TObjectDynArray = array of TObject;
  69. TWordDynArray = array of Word;
  70. TCurrencyArray = Array of currency;
  71. {$ifndef FPUNONE}
  72. TSingleDynArray = array of Single;
  73. TDoubleDynArray = array of Double;
  74. TExtendedDynArray = array of Extended;
  75. TCompDynArray = array of Comp;
  76. {$endif}
  77. {$if defined(win32) or defined(win64) or defined(wince)}
  78. TArray4IntegerType = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TArray4IntegerType;
  79. TSmallPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TSmallPoint;
  80. PSmallPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PSmallPoint;
  81. TSize = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TSize;
  82. TagSize = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.tagSize deprecated;
  83. PSize = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PSize;
  84. TPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TPoint;
  85. TagPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TagPoint deprecated;
  86. PPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PPoint;
  87. TRect = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TRect;
  88. PRect = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PRect;
  89. TSplitRectType = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TSplitRectType;
  90. const
  91. srLeft = TSplitRectType.srLeft;
  92. srRight = TSplitRectType.srRight;
  93. srTop = TSplitRectType.srTop;
  94. srBottom = TSplitRectType.srBottom;
  95. type
  96. {$else}
  97. {$i typshrdh.inc}
  98. TagSize = tSize deprecated;
  99. TagPoint = TPoint deprecated;
  100. {$endif}
  101. { TPointF }
  102. PPointF = ^TPointF;
  103. TPointF =
  104. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  105. packed
  106. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  107. record
  108. x,y : Single;
  109. public
  110. function Add(const apt: TPoint): TPointF;
  111. function Add(const apt: TPointF): TPointF;
  112. function Distance(const apt : TPointF) : Single;
  113. function DotProduct(const apt : TPointF) : Single;
  114. function IsZero : Boolean;
  115. function Subtract(const apt : TPointF): TPointF;
  116. function Subtract(const apt : TPoint): TPointF;
  117. procedure SetLocation(const apt :TPointF);
  118. procedure SetLocation(const apt :TPoint);
  119. procedure SetLocation(ax,ay : Longint);
  120. procedure Offset(const apt :TPointF);
  121. procedure Offset(const apt :TPoint);
  122. procedure Offset(dx,dy : Longint);
  123. function Scale (afactor:Single) : TPointF;
  124. function Ceiling : TPoint;
  125. function Truncate: TPoint;
  126. function Floor : TPoint;
  127. function Round : TPoint;
  128. function Length : Single;
  129. function Rotate(angle: single): TPointF;
  130. function Reflect(const normal: TPointF): TPointF;
  131. function MidPoint(const b: TPointF): TPointF;
  132. class function PointInCircle(const pt, center: TPointF; radius: single): Boolean; static;
  133. class function PointInCircle(const pt, center: TPointF; radius: integer): Boolean; static;
  134. function Angle(const b: TPointF): Single;
  135. function AngleCosine(const b: TPointF): single;
  136. class function Create(const ax, ay: Single): TPointF; overload; static; inline;
  137. class function Create(const apt: TPoint): TPointF; overload; static; inline;
  138. class operator = (const apt1, apt2 : TPointF) : Boolean;
  139. class operator <> (const apt1, apt2 : TPointF): Boolean;
  140. class operator + (const apt1, apt2 : TPointF): TPointF;
  141. class operator - (const apt1, apt2 : TPointF): TPointF;
  142. class operator - (const apt1 : TPointF): TPointF;
  143. class operator * (const apt1, apt2: TPointF): TPointF;
  144. class operator * (const apt1: TPointF; afactor: single): TPointF;
  145. class operator * (afactor: single; const apt1: TPointF): TPointF;
  146. class operator / (const apt1: TPointF; afactor: single): TPointF;
  147. class operator := (const apt: TPoint): TPointF;
  148. class operator ** (const apt1, apt2: TPointF): Single; // scalar product
  149. end;
  150. { TSizeF }
  151. PSizeF = ^TSizeF;
  152. TSizeF =
  153. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  154. packed
  155. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  156. record
  157. cx,cy : Single;
  158. public
  159. function Add(const asz: TSize): TSizeF;
  160. function Add(const asz: TSizeF): TSizeF;
  161. function Distance(const asz : TSizeF) : Single;
  162. function IsZero : Boolean;
  163. function Subtract(const asz : TSizeF): TSizeF;
  164. function Subtract(const asz : TSize): TSizeF;
  165. function SwapDimensions:TSizeF;
  166. function Scale (afactor:Single) : TSizeF;
  167. function Ceiling : TSize;
  168. function Truncate: TSize;
  169. function Floor : TSize;
  170. function Round : TSize;
  171. function Length : Single;
  172. class function Create(const ax, ay: Single): TSizeF; overload; static; inline;
  173. class function Create(const asz: TSize): TSizeF; overload; static; inline;
  174. class operator = (const asz1, asz2 : TSizeF) : Boolean;
  175. class operator <> (const asz1, asz2 : TSizeF): Boolean;
  176. class operator + (const asz1, asz2 : TSizeF): TSizeF;
  177. class operator - (const asz1, asz2 : TSizeF): TSizeF;
  178. class operator - (const asz1 : TSizeF): TSizeF;
  179. class operator * (const asz1: TSizeF; afactor: single): TSizeF;
  180. class operator * (afactor: single; const asz1: TSizeF): TSizeF;
  181. class operator := (const apt: TPointF): TSizeF;
  182. class operator := (const asz: TSize): TSizeF;
  183. class operator := (const asz: TSizeF): TPointF;
  184. property Width: Single read cx write cx;
  185. property Height: Single read cy write cy;
  186. end;
  187. { TRectF }
  188. PRectF = ^TRectF;
  189. TRectF =
  190. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  191. packed
  192. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  193. record
  194. private
  195. function GetLocation: TPointF;
  196. function GetSize: TSizeF;
  197. procedure SetSize(AValue: TSizeF);
  198. function GetHeight: Single; inline;
  199. function GetWidth: Single; inline;
  200. procedure SetHeight(AValue: Single);
  201. procedure SetWidth (AValue: Single);
  202. public
  203. constructor Create(Origin: TPointF); // empty rect at given origin
  204. constructor Create(Origin: TPointF; AWidth, AHeight: Single);
  205. constructor Create(ALeft, ATop, ARight, ABottom: Single);
  206. constructor Create(P1, P2: TPointF; Normalize: Boolean = False);
  207. constructor Create(R: TRectF; Normalize: Boolean = False);
  208. constructor Create(R: TRect; Normalize: Boolean = False);
  209. class operator = (L, R: TRectF): Boolean;
  210. class operator <> (L, R: TRectF): Boolean;
  211. class operator + (L, R: TRectF): TRectF; // union
  212. class operator * (L, R: TRectF): TRectF; // intersection
  213. class operator := (const arc: TRect): TRectF;
  214. class function Empty: TRectF; static;
  215. procedure NormalizeRect;
  216. function IsEmpty: Boolean;
  217. function Contains(Pt: TPointF): Boolean;
  218. function Contains(R: TRectF): Boolean;
  219. function IntersectsWith(R: TRectF): Boolean;
  220. class function Intersect(R1: TRectF; R2: TRectF): TRectF; static;
  221. procedure Intersect(R: TRectF);
  222. class function Union(R1, R2: TRectF): TRectF; static;
  223. class function Union(const Points: array of TPointF): TRectF; static;
  224. procedure SetLocation(X, Y: Single);
  225. procedure SetLocation(P: TPointF);
  226. procedure Inflate(DX, DY: Single);
  227. procedure Inflate(DL, DT, DR, DB: Single);
  228. function CenterPoint: TPointF;
  229. procedure Union (const r: TRectF); inline;
  230. procedure Offset (const dx,dy : Single); inline;
  231. procedure Offset (DP: TPointF); inline;
  232. property Width : Single read GetWidth write SetWidth;
  233. property Height : Single read GetHeight write SetHeight;
  234. property Size : TSizeF read getSize write SetSize;
  235. property Location: TPointF read getLocation write setLocation;
  236. case Integer of
  237. 0: (Left, Top, Right, Bottom: Single);
  238. 1: (TopLeft, BottomRight: TPointF);
  239. end;
  240. TDuplicates = (dupIgnore, dupAccept, dupError);
  241. TPoint3D =
  242. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  243. packed
  244. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  245. record
  246. public
  247. Type TSingle3Array = array[0..2] of single;
  248. constructor Create(const ax,ay,az:single);
  249. procedure Offset(const adeltax,adeltay,adeltaz:single); inline;
  250. procedure Offset(const adelta:TPoint3D); inline;
  251. public
  252. case Integer of
  253. 0: (data:TSingle3Array);
  254. 1: (x,y,z : single);
  255. end;
  256. type
  257. TOleChar = WideChar;
  258. POleStr = PWideChar;
  259. PPOleStr = ^POleStr;
  260. TListCallback = procedure(data,arg:pointer) of object;
  261. TListStaticCallback = procedure(data,arg:pointer);
  262. const
  263. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  264. STGTY_STORAGE = 1;
  265. STGTY_STREAM = 2;
  266. STGTY_LOCKBYTES = 3;
  267. STGTY_PROPERTY = 4;
  268. STREAM_SEEK_SET = 0;
  269. STREAM_SEEK_CUR = 1;
  270. STREAM_SEEK_END = 2;
  271. LOCK_WRITE = 1;
  272. LOCK_EXCLUSIVE = 2;
  273. LOCK_ONLYONCE = 4;
  274. STATFLAG_DEFAULT = 0;
  275. STATFLAG_NONAME = 1;
  276. STATFLAG_NOOPEN = 2;
  277. {$ifndef Wince}
  278. // in Wince these are in unit windows. Under 32/64 in ActiveX.
  279. // for now duplicate them. Not that bad for untyped constants.
  280. E_FAIL = HRESULT($80004005);
  281. E_INVALIDARG = HRESULT($80070057);
  282. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  283. STG_E_FILENOTFOUND = HRESULT($80030002);
  284. STG_E_PATHNOTFOUND = HRESULT($80030003);
  285. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  286. STG_E_ACCESSDENIED = HRESULT($80030005);
  287. STG_E_INVALIDHANDLE = HRESULT($80030006);
  288. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  289. STG_E_INVALIDPOINTER = HRESULT($80030009);
  290. STG_E_NOMOREFILES = HRESULT($80030012);
  291. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  292. STG_E_SEEKERROR = HRESULT($80030019);
  293. STG_E_WRITEFAULT = HRESULT($8003001D);
  294. STG_E_READFAULT = HRESULT($8003001E);
  295. STG_E_SHAREVIOLATION = HRESULT($80030020);
  296. STG_E_LOCKVIOLATION = HRESULT($80030021);
  297. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  298. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  299. STG_E_MEDIUMFULL = HRESULT($80030070);
  300. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  301. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  302. STG_E_INVALIDHEADER = HRESULT($800300FB);
  303. STG_E_INVALIDNAME = HRESULT($800300FC);
  304. STG_E_UNKNOWN = HRESULT($800300FD);
  305. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  306. STG_E_INVALIDFLAG = HRESULT($800300FF);
  307. STG_E_INUSE = HRESULT($80030100);
  308. STG_E_NOTCURRENT = HRESULT($80030101);
  309. STG_E_REVERTED = HRESULT($80030102);
  310. STG_E_CANTSAVE = HRESULT($80030103);
  311. STG_E_OLDFORMAT = HRESULT($80030104);
  312. STG_E_OLDDLL = HRESULT($80030105);
  313. STG_E_SHAREREQUIRED = HRESULT($80030106);
  314. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  315. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  316. STG_E_BADBASEADDRESS = HRESULT($80030110);
  317. STG_E_INCOMPLETE = HRESULT($80030201);
  318. STG_E_TERMINATED = HRESULT($80030202);
  319. STG_S_CONVERTED = $00030200;
  320. STG_S_BLOCK = $00030201;
  321. STG_S_RETRYNOW = $00030202;
  322. STG_S_MONITORING = $00030203;
  323. {$endif}
  324. {$if (not defined(win32)) and (not defined(win64)) and (not defined(wince))}
  325. type
  326. PCLSID = PGUID;
  327. TCLSID = TGUID;
  328. PDWord = ^DWord;
  329. PDisplay = Pointer;
  330. PEvent = Pointer;
  331. TXrmOptionDescRec = record
  332. end;
  333. XrmOptionDescRec = TXrmOptionDescRec;
  334. PXrmOptionDescRec = ^TXrmOptionDescRec;
  335. Widget = Pointer;
  336. WidgetClass = Pointer;
  337. ArgList = Pointer;
  338. Region = Pointer;
  339. _FILETIME =
  340. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  341. packed
  342. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  343. record
  344. dwLowDateTime : DWORD;
  345. dwHighDateTime : DWORD;
  346. end;
  347. TFileTime = _FILETIME;
  348. FILETIME = _FILETIME;
  349. PFileTime = ^TFileTime;
  350. {$else}
  351. type
  352. PCLSID = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PCLSID;
  353. TCLSID = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.CLSID;
  354. TFiletime = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TFileTime;
  355. Filetime = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.FileTime;
  356. PFiletime = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PFileTime;
  357. {$endif Windows}
  358. type
  359. tagSTATSTG = record
  360. pwcsName : POleStr;
  361. dwType : DWord;
  362. cbSize : Large_uint;
  363. mtime : TFileTime;
  364. ctime : TFileTime;
  365. atime : TFileTime;
  366. grfMode : DWord;
  367. grfLocksSupported : DWord;
  368. clsid : TCLSID;
  369. grfStateBits : DWord;
  370. reserved : DWord;
  371. end;
  372. TStatStg = tagSTATSTG;
  373. STATSTG = TStatStg;
  374. PStatStg = ^TStatStg;
  375. { classes depends on these interfaces, we can't use the activex unit in classes though }
  376. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  377. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  378. Function LockServer(fLock : LongBool) : HResult;StdCall;
  379. End;
  380. ISequentialStream = interface(IUnknown)
  381. ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  382. function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
  383. function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
  384. end;
  385. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  386. function Seek(dlibMove : LargeInt; dwOrigin : DWORD; out libNewPosition : LargeUInt) : HResult;stdcall;
  387. function SetSize(libNewSize : LargeUInt) : HRESULT;stdcall;
  388. function CopyTo(stm: IStream;cb : LargeUInt;out cbRead : LargeUInt; out cbWritten : LargeUInt) : HRESULT;stdcall;
  389. function Commit(grfCommitFlags : DWORD) : HRESULT;stdcall;
  390. function Revert : HRESULT;stdcall;
  391. function LockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : DWORD) : HRESULT;stdcall;
  392. function UnlockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : DWORD) : HRESULT;stdcall;
  393. Function Stat(out statstg : TStatStg;grfStatFlag : DWORD) : HRESULT;stdcall;
  394. function Clone(out stm : IStream) : HRESULT;stdcall;
  395. end;
  396. function EqualRect(const r1,r2 : TRect) : Boolean;
  397. function Rect(Left,Top,Right,Bottom : Integer) : TRect; inline;
  398. function RectF(Left,Top,Right,Bottom : Single) : TRectF; inline;
  399. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect; inline;
  400. function Point(x,y : Integer) : TPoint; inline;
  401. function PointF(x,y: Single) : TPointF; inline;
  402. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  403. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  404. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  405. function IsRectEmpty(const Rect : TRect) : Boolean;
  406. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  407. function CenterPoint(const Rect: TRect): TPoint;
  408. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  409. function Size(AWidth, AHeight: Integer): TSize; inline;
  410. function Size(const ARect: TRect): TSize;
  411. {$ifndef VER3_0}
  412. type
  413. TBitConverter = class
  414. generic class procedure UnsafeFrom<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0); static; {inline;}
  415. generic class procedure From<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0); static;
  416. generic class function UnsafeInTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T; static; {inline;}
  417. generic class function InTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T; static;
  418. end;
  419. {$endif}
  420. implementation
  421. {$IFDEF FPC_DOTTEDUNITS}
  422. Uses System.Math;
  423. {$ELSE FPC_DOTTEDUNITS}
  424. Uses Math;
  425. {$ENDIF FPC_DOTTEDUNITS}
  426. {$if (not defined(win32)) and (not defined(win64)) and (not defined(wince))}
  427. {$i typshrd.inc}
  428. {$endif}
  429. function EqualRect(const r1,r2 : TRect) : Boolean;
  430. begin
  431. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  432. end;
  433. function Rect(Left,Top,Right,Bottom : Integer) : TRect; inline;
  434. begin
  435. Rect.Left:=Left;
  436. Rect.Top:=Top;
  437. Rect.Right:=Right;
  438. Rect.Bottom:=Bottom;
  439. end;
  440. function RectF(Left,Top,Right,Bottom : Single) : TRectF; inline;
  441. begin
  442. RectF.Left:=Left;
  443. RectF.Top:=Top;
  444. RectF.Right:=Right;
  445. RectF.Bottom:=Bottom;
  446. end;
  447. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect; inline;
  448. begin
  449. Bounds.Left:=ALeft;
  450. Bounds.Top:=ATop;
  451. Bounds.Right:=ALeft+AWidth;
  452. Bounds.Bottom:=ATop+AHeight;
  453. end;
  454. function Point(x,y : Integer) : TPoint; inline;
  455. begin
  456. Point.x:=x;
  457. Point.y:=y;
  458. end;
  459. function PointF(x,y: Single) : TPointF; inline;
  460. begin
  461. PointF.x:=x;
  462. PointF.y:=y;
  463. end;
  464. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  465. begin
  466. PtInRect:=(p.y>=Rect.Top) and
  467. (p.y<Rect.Bottom) and
  468. (p.x>=Rect.Left) and
  469. (p.x<Rect.Right);
  470. end;
  471. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  472. var
  473. lRect: TRect;
  474. begin
  475. lRect := R1;
  476. if R2.Left > R1.Left then
  477. lRect.Left := R2.Left;
  478. if R2.Top > R1.Top then
  479. lRect.Top := R2.Top;
  480. if R2.Right < R1.Right then
  481. lRect.Right := R2.Right;
  482. if R2.Bottom < R1.Bottom then
  483. lRect.Bottom := R2.Bottom;
  484. // The var parameter is only assigned in the end to avoid problems
  485. // when passing the same rectangle in the var and const parameters.
  486. // See http://bugs.freepascal.org/view.php?id=17722
  487. if IsRectEmpty(lRect) then
  488. begin
  489. FillChar(Rect,SizeOf(Rect),0);
  490. IntersectRect:=false;
  491. end
  492. else
  493. begin
  494. IntersectRect:=true;
  495. Rect := lRect;
  496. end;
  497. end;
  498. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  499. var
  500. lRect: TRect;
  501. begin
  502. lRect:=R1;
  503. if R2.Left<R1.Left then
  504. lRect.Left:=R2.Left;
  505. if R2.Top<R1.Top then
  506. lRect.Top:=R2.Top;
  507. if R2.Right>R1.Right then
  508. lRect.Right:=R2.Right;
  509. if R2.Bottom>R1.Bottom then
  510. lRect.Bottom:=R2.Bottom;
  511. if IsRectEmpty(lRect) then
  512. begin
  513. FillChar(Rect,SizeOf(Rect),0);
  514. UnionRect:=false;
  515. end
  516. else
  517. begin
  518. Rect:=lRect;
  519. UnionRect:=true;
  520. end;
  521. end;
  522. function IsRectEmpty(const Rect : TRect) : Boolean;
  523. begin
  524. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  525. end;
  526. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  527. begin
  528. if assigned(@Rect) then
  529. begin
  530. with Rect do
  531. begin
  532. inc(Left,dx);
  533. inc(Top,dy);
  534. inc(Right,dx);
  535. inc(Bottom,dy);
  536. end;
  537. OffsetRect:=true;
  538. end
  539. else
  540. OffsetRect:=false;
  541. end;
  542. function Avg(a, b: Longint): Longint;
  543. begin
  544. if a < b then
  545. Result := a + ((b - a) shr 1)
  546. else
  547. Result := b + ((a - b) shr 1);
  548. end;
  549. function CenterPoint(const Rect: TRect): TPoint;
  550. begin
  551. with Rect do
  552. begin
  553. Result.X := Avg(Left, Right);
  554. Result.Y := Avg(Top, Bottom);
  555. end;
  556. end;
  557. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  558. begin
  559. if Assigned(@Rect) then
  560. begin
  561. with Rect do
  562. begin
  563. dec(Left, dx);
  564. dec(Top, dy);
  565. inc(Right, dx);
  566. inc(Bottom, dy);
  567. end;
  568. Result := True;
  569. end
  570. else
  571. Result := False;
  572. end;
  573. function Size(AWidth, AHeight: Integer): TSize; inline;
  574. begin
  575. Result.cx := AWidth;
  576. Result.cy := AHeight;
  577. end;
  578. function Size(const ARect: TRect): TSize; inline;
  579. begin
  580. Result.cx := ARect.Right - ARect.Left;
  581. Result.cy := ARect.Bottom - ARect.Top;
  582. end;
  583. { TPointF}
  584. function TPointF.Add(const apt: TPoint): TPointF;
  585. begin
  586. result.x:=x+apt.x;
  587. result.y:=y+apt.y;
  588. end;
  589. function TPointF.Add(const apt: TPointF): TPointF;
  590. begin
  591. result.x:=x+apt.x;
  592. result.y:=y+apt.y;
  593. end;
  594. function TPointF.Subtract(const apt : TPointF): TPointF;
  595. begin
  596. result.x:=x-apt.x;
  597. result.y:=y-apt.y;
  598. end;
  599. function TPointF.Subtract(const apt: TPoint): TPointF;
  600. begin
  601. result.x:=x-apt.x;
  602. result.y:=y-apt.y;
  603. end;
  604. function TPointF.Distance(const apt : TPointF) : Single;
  605. begin
  606. result:=sqrt(sqr(apt.x-x)+sqr(apt.y-y));
  607. end;
  608. function TPointF.DotProduct(const apt: TPointF): Single;
  609. begin
  610. result:=x*apt.x+y*apt.y;
  611. end;
  612. function TPointF.IsZero : Boolean;
  613. begin
  614. result:=SameValue(x,0.0) and SameValue(y,0.0);
  615. end;
  616. procedure TPointF.Offset(const apt :TPointF);
  617. begin
  618. x:=x+apt.x;
  619. y:=y+apt.y;
  620. end;
  621. procedure TPointF.Offset(const apt: TPoint);
  622. begin
  623. x:=x+apt.x;
  624. y:=y+apt.y;
  625. end;
  626. procedure TPointF.Offset(dx,dy : Longint);
  627. begin
  628. x:=x+dx;
  629. y:=y+dy;
  630. end;
  631. function TPointF.Scale(afactor: Single): TPointF;
  632. begin
  633. result.x:=afactor*x;
  634. result.y:=afactor*y;
  635. end;
  636. function TPointF.Ceiling: TPoint;
  637. begin
  638. result.x:=ceil(x);
  639. result.y:=ceil(y);
  640. end;
  641. function TPointF.Truncate: TPoint;
  642. begin
  643. result.x:=trunc(x);
  644. result.y:=trunc(y);
  645. end;
  646. function TPointF.Floor: TPoint;
  647. begin
  648. result.x:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(x);
  649. result.y:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(y);
  650. end;
  651. function TPointF.Round: TPoint;
  652. begin
  653. result.x:=System.round(x);
  654. result.y:=System.round(y);
  655. end;
  656. function TPointF.Length: Single;
  657. begin
  658. result:=sqrt(sqr(x)+sqr(y));
  659. end;
  660. function TPointF.Rotate(angle: single): TPointF;
  661. var
  662. sina, cosa: single;
  663. begin
  664. sincos(angle, sina, cosa);
  665. result.x := x * cosa - y * sina;
  666. result.y := x * sina + y * cosa;
  667. end;
  668. function TPointF.Reflect(const normal: TPointF): TPointF;
  669. begin
  670. result := self + (-2 * normal ** self) * normal;
  671. end;
  672. function TPointF.MidPoint(const b: TPointF): TPointF;
  673. begin
  674. result.x := 0.5 * (x + b.x);
  675. result.y := 0.5 * (y + b.y);
  676. end;
  677. class function TPointF.PointInCircle(const pt, center: TPointF; radius: single): Boolean;
  678. begin
  679. result := sqr(center.x - pt.x) + sqr(center.y - pt.y) < sqr(radius);
  680. end;
  681. class function TPointF.PointInCircle(const pt, center: TPointF; radius: integer): Boolean;
  682. begin
  683. result := sqr(center.x - pt.x) + sqr(center.y - pt.y) < sqr(single(radius));
  684. end;
  685. function TPointF.Angle(const b: TPointF): Single;
  686. begin
  687. result := ArcTan2(y - b.y, x - b.x);
  688. end;
  689. function TPointF.AngleCosine(const b: TPointF): single;
  690. begin
  691. result := EnsureRange((self ** b) / sqrt((sqr(x) + sqr(y)) * (sqr(b.x) + sqr(b.y))), -1, 1);
  692. end;
  693. class operator TPointF.= (const apt1, apt2 : TPointF) : Boolean;
  694. begin
  695. result:=SameValue(apt1.x,apt2.x) and SameValue(apt1.y,apt2.y);
  696. end;
  697. class operator TPointF.<> (const apt1, apt2 : TPointF): Boolean;
  698. begin
  699. result:=NOT (SameValue(apt1.x,apt2.x) and Samevalue(apt1.y,apt2.y));
  700. end;
  701. class operator TPointF. * (const apt1, apt2: TPointF): TPointF;
  702. begin
  703. result.x:=apt1.x*apt2.x;
  704. result.y:=apt1.y*apt2.y;
  705. end;
  706. class operator TPointF. * (afactor: single; const apt1: TPointF): TPointF;
  707. begin
  708. result:=apt1.Scale(afactor);
  709. end;
  710. class operator TPointF. * (const apt1: TPointF; afactor: single): TPointF;
  711. begin
  712. result:=apt1.Scale(afactor);
  713. end;
  714. class operator TPointF. ** (const apt1, apt2: TPointF): Single;
  715. begin
  716. result:=apt1.x*apt2.x + apt1.y*apt2.y;
  717. end;
  718. class operator TPointF.+ (const apt1, apt2 : TPointF): TPointF;
  719. begin
  720. result.x:=apt1.x+apt2.x;
  721. result.y:=apt1.y+apt2.y;
  722. end;
  723. class operator TPointF.- (const apt1, apt2 : TPointF): TPointF;
  724. begin
  725. result.x:=apt1.x-apt2.x;
  726. result.y:=apt1.y-apt2.y;
  727. end;
  728. class operator TPointF. - (const apt1: TPointF): TPointF;
  729. begin
  730. Result.x:=-apt1.x;
  731. Result.y:=-apt1.y;
  732. end;
  733. class operator TPointF. / (const apt1: TPointF; afactor: single): TPointF;
  734. begin
  735. result:=apt1.Scale(1/afactor);
  736. end;
  737. class operator TPointF. := (const apt: TPoint): TPointF;
  738. begin
  739. Result.x:=apt.x;
  740. Result.y:=apt.y;
  741. end;
  742. procedure TPointF.SetLocation(const apt :TPointF);
  743. begin
  744. x:=apt.x; y:=apt.y;
  745. end;
  746. procedure TPointF.SetLocation(const apt: TPoint);
  747. begin
  748. x:=apt.x; y:=apt.y;
  749. end;
  750. procedure TPointF.SetLocation(ax,ay : Longint);
  751. begin
  752. x:=ax; y:=ay;
  753. end;
  754. class function TPointF.Create(const ax, ay: Single): TPointF;
  755. begin
  756. Result.x := ax;
  757. Result.y := ay;
  758. end;
  759. class function TPointF.Create(const apt: TPoint): TPointF;
  760. begin
  761. Result.x := apt.X;
  762. Result.y := apt.Y;
  763. end;
  764. { TSizeF }
  765. function TSizeF.Add(const asz: TSize): TSizeF;
  766. begin
  767. result.cx:=cx+asz.cx;
  768. result.cy:=cy+asz.cy;
  769. end;
  770. function TSizeF.Add(const asz: TSizeF): TSizeF;
  771. begin
  772. result.cx:=cx+asz.cx;
  773. result.cy:=cy+asz.cy;
  774. end;
  775. function TSizeF.Subtract(const asz : TSizeF): TSizeF;
  776. begin
  777. result.cx:=cx-asz.cx;
  778. result.cy:=cy-asz.cy;
  779. end;
  780. function TSizeF.SwapDimensions:TSizeF;
  781. begin
  782. result.cx:=cy;
  783. result.cy:=cx;
  784. end;
  785. function TSizeF.Subtract(const asz: TSize): TSizeF;
  786. begin
  787. result.cx:=cx-asz.cx;
  788. result.cy:=cy-asz.cy;
  789. end;
  790. function TSizeF.Distance(const asz : TSizeF) : Single;
  791. begin
  792. result:=sqrt(sqr(asz.cx-cx)+sqr(asz.cy-cy));
  793. end;
  794. function TSizeF.IsZero : Boolean;
  795. begin
  796. result:=SameValue(cx,0.0) and SameValue(cy,0.0);
  797. end;
  798. function TSizeF.Scale(afactor: Single): TSizeF;
  799. begin
  800. result.cx:=afactor*cx;
  801. result.cy:=afactor*cy;
  802. end;
  803. function TSizeF.Ceiling: TSize;
  804. begin
  805. result.cx:=ceil(cx);
  806. result.cy:=ceil(cy);
  807. end;
  808. function TSizeF.Truncate: TSize;
  809. begin
  810. result.cx:=trunc(cx);
  811. result.cy:=trunc(cy);
  812. end;
  813. function TSizeF.Floor: TSize;
  814. begin
  815. result.cx:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(cx);
  816. result.cy:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(cy);
  817. end;
  818. function TSizeF.Round: TSize;
  819. begin
  820. result.cx:=System.round(cx);
  821. result.cy:=System.round(cy);
  822. end;
  823. function TSizeF.Length: Single;
  824. begin //distance(self) ?
  825. result:=sqrt(sqr(cx)+sqr(cy));
  826. end;
  827. class operator TSizeF.= (const asz1, asz2 : TSizeF) : Boolean;
  828. begin
  829. result:=SameValue(asz1.cx,asz2.cx) and SameValue(asz1.cy,asz2.cy);
  830. end;
  831. class operator TSizeF.<> (const asz1, asz2 : TSizeF): Boolean;
  832. begin
  833. result:=NOT (SameValue(asz1.cx,asz2.cx) and Samevalue(asz1.cy,asz2.cy));
  834. end;
  835. class operator TSizeF. * (afactor: single; const asz1: TSizeF): TSizeF;
  836. begin
  837. result:=asz1.Scale(afactor);
  838. end;
  839. class operator TSizeF. * (const asz1: TSizeF; afactor: single): TSizeF;
  840. begin
  841. result:=asz1.Scale(afactor);
  842. end;
  843. class operator TSizeF.+ (const asz1, asz2 : TSizeF): TSizeF;
  844. begin
  845. result.cx:=asz1.cx+asz2.cx;
  846. result.cy:=asz1.cy+asz2.cy;
  847. end;
  848. class operator TSizeF.- (const asz1, asz2 : TSizeF): TSizeF;
  849. begin
  850. result.cx:=asz1.cx-asz2.cx;
  851. result.cy:=asz1.cy-asz2.cy;
  852. end;
  853. class operator TSizeF. - (const asz1: TSizeF): TSizeF;
  854. begin
  855. Result.cx:=-asz1.cx;
  856. Result.cy:=-asz1.cy;
  857. end;
  858. class operator TSizeF. := (const apt: TPointF): TSizeF;
  859. begin
  860. Result.cx:=apt.x;
  861. Result.cy:=apt.y;
  862. end;
  863. class operator TSizeF. := (const asz: TSize): TSizeF;
  864. begin
  865. Result.cx := asz.cx;
  866. Result.cy := asz.cy;
  867. end;
  868. class operator TSizeF. := (const asz: TSizeF): TPointF;
  869. begin
  870. Result.x := asz.cx;
  871. Result.y := asz.cy;
  872. end;
  873. class function TSizeF.Create(const ax, ay: Single): TSizeF;
  874. begin
  875. Result.cx := ax;
  876. Result.cy := ay;
  877. end;
  878. class function TSizeF.Create(const asz: TSize): TSizeF;
  879. begin
  880. Result.cx := asz.cX;
  881. Result.cy := asz.cY;
  882. end;
  883. { TRectF }
  884. class operator TRectF. * (L, R: TRectF): TRectF;
  885. begin
  886. Result := TRectF.Intersect(L, R);
  887. end;
  888. class operator TRectF. + (L, R: TRectF): TRectF;
  889. begin
  890. Result := TRectF.Union(L, R);
  891. end;
  892. class operator TRectF. := (const arc: TRect): TRectF;
  893. begin
  894. Result.Left:=arc.Left;
  895. Result.Top:=arc.Top;
  896. Result.Right:=arc.Right;
  897. Result.Bottom:=arc.Bottom;
  898. end;
  899. class operator TRectF. <> (L, R: TRectF): Boolean;
  900. begin
  901. Result := not(L=R);
  902. end;
  903. class operator TRectF. = (L, R: TRectF): Boolean;
  904. begin
  905. Result :=
  906. SameValue(L.Left,R.Left) and SameValue(L.Right,R.Right) and
  907. SameValue(L.Top,R.Top) and SameValue(L.Bottom,R.Bottom);
  908. end;
  909. constructor TRectF.Create(ALeft, ATop, ARight, ABottom: Single);
  910. begin
  911. Left := ALeft;
  912. Top := ATop;
  913. Right := ARight;
  914. Bottom := ABottom;
  915. end;
  916. constructor TRectF.Create(P1, P2: TPointF; Normalize: Boolean);
  917. begin
  918. TopLeft := P1;
  919. BottomRight := P2;
  920. if Normalize then
  921. NormalizeRect;
  922. end;
  923. constructor TRectF.Create(Origin: TPointF);
  924. begin
  925. TopLeft := Origin;
  926. BottomRight := Origin;
  927. end;
  928. constructor TRectF.Create(Origin: TPointF; AWidth, AHeight: Single);
  929. begin
  930. TopLeft := Origin;
  931. Width := AWidth;
  932. Height := AHeight;
  933. end;
  934. constructor TRectF.Create(R: TRectF; Normalize: Boolean);
  935. begin
  936. Self := R;
  937. if Normalize then
  938. NormalizeRect;
  939. end;
  940. constructor TRectF.Create(R: TRect; Normalize: Boolean);
  941. begin
  942. Self := R;
  943. if Normalize then
  944. NormalizeRect;
  945. end;
  946. function TRectF.CenterPoint: TPointF;
  947. begin
  948. Result.X := (Right-Left) / 2 + Left;
  949. Result.Y := (Bottom-Top) / 2 + Top;
  950. end;
  951. function TRectF.Contains(Pt: TPointF): Boolean;
  952. begin
  953. Result := (Left <= Pt.X) and (Pt.X < Right) and (Top <= Pt.Y) and (Pt.Y < Bottom);
  954. end;
  955. function TRectF.Contains(R: TRectF): Boolean;
  956. begin
  957. Result := (Left <= R.Left) and (R.Right <= Right) and (Top <= R.Top) and (R.Bottom <= Bottom);
  958. end;
  959. class function TRectF.Empty: TRectF;
  960. begin
  961. Result := TRectF.Create(0,0,0,0);
  962. end;
  963. function TRectF.GetHeight: Single;
  964. begin
  965. result:=bottom-top;
  966. end;
  967. function TRectF.GetLocation: TPointF;
  968. begin
  969. result.x:=Left; result.y:=top;
  970. end;
  971. function TRectF.GetSize: TSizeF;
  972. begin
  973. result.cx:=width; result.cy:=height;
  974. end;
  975. function TRectF.GetWidth: Single;
  976. begin
  977. result:=right-left;
  978. end;
  979. procedure TRectF.Inflate(DX, DY: Single);
  980. begin
  981. Left:=Left-dx;
  982. Top:=Top-dy;
  983. Right:=Right+dx;
  984. Bottom:=Bottom+dy;
  985. end;
  986. procedure TRectF.Intersect(R: TRectF);
  987. begin
  988. Self := Intersect(Self, R);
  989. end;
  990. class function TRectF.Intersect(R1: TRectF; R2: TRectF): TRectF;
  991. begin
  992. Result := R1;
  993. if R2.Left > R1.Left then
  994. Result.Left := R2.Left;
  995. if R2.Top > R1.Top then
  996. Result.Top := R2.Top;
  997. if R2.Right < R1.Right then
  998. Result.Right := R2.Right;
  999. if R2.Bottom < R1.Bottom then
  1000. Result.Bottom := R2.Bottom;
  1001. end;
  1002. function TRectF.IntersectsWith(R: TRectF): Boolean;
  1003. begin
  1004. Result := (Left < R.Right) and (R.Left < Right) and (Top < R.Bottom) and (R.Top < Bottom);
  1005. end;
  1006. function TRectF.IsEmpty: Boolean;
  1007. begin
  1008. Result := (CompareValue(Right,Left)<=0) or (CompareValue(Bottom,Top)<=0);
  1009. end;
  1010. procedure TRectF.NormalizeRect;
  1011. var
  1012. x: Single;
  1013. begin
  1014. if Top>Bottom then
  1015. begin
  1016. x := Top;
  1017. Top := Bottom;
  1018. Bottom := x;
  1019. end;
  1020. if Left>Right then
  1021. begin
  1022. x := Left;
  1023. Left := Right;
  1024. Right := x;
  1025. end
  1026. end;
  1027. procedure TRectF.Inflate(DL, DT, DR, DB: Single);
  1028. begin
  1029. Left:=Left-dl;
  1030. Top:=Top-dt;
  1031. Right:=Right+dr;
  1032. Bottom:=Bottom+db;
  1033. end;
  1034. procedure TRectF.Offset(const dx, dy: Single);
  1035. begin
  1036. left:=left+dx; right:=right+dx;
  1037. bottom:=bottom+dy; top:=top+dy;
  1038. end;
  1039. procedure TRectF.Offset(DP: TPointF);
  1040. begin
  1041. left:=left+DP.x; right:=right+DP.x;
  1042. bottom:=bottom+DP.y; top:=top+DP.y;
  1043. end;
  1044. procedure TRectF.SetHeight(AValue: Single);
  1045. begin
  1046. bottom:=top+avalue;
  1047. end;
  1048. procedure TRectF.SetLocation(X, Y: Single);
  1049. begin
  1050. Offset(X-Left, Y-Top);
  1051. end;
  1052. procedure TRectF.SetLocation(P: TPointF);
  1053. begin
  1054. SetLocation(P.X, P.Y);
  1055. end;
  1056. procedure TRectF.SetSize(AValue: TSizeF);
  1057. begin
  1058. bottom:=top+avalue.cy;
  1059. right:=left+avalue.cx;
  1060. end;
  1061. procedure TRectF.SetWidth(AValue: Single);
  1062. begin
  1063. right:=left+avalue;
  1064. end;
  1065. class function TRectF.Union(const Points: array of TPointF): TRectF;
  1066. var
  1067. i: Integer;
  1068. begin
  1069. if Length(Points) > 0 then
  1070. begin
  1071. Result.TopLeft := Points[Low(Points)];
  1072. Result.BottomRight := Points[Low(Points)];
  1073. for i := Low(Points)+1 to High(Points) do
  1074. begin
  1075. if Points[i].X < Result.Left then Result.Left := Points[i].X;
  1076. if Points[i].X > Result.Right then Result.Right := Points[i].X;
  1077. if Points[i].Y < Result.Top then Result.Top := Points[i].Y;
  1078. if Points[i].Y > Result.Bottom then Result.Bottom := Points[i].Y;
  1079. end;
  1080. end else
  1081. Result := Empty;
  1082. end;
  1083. procedure TRectF.Union(const r: TRectF);
  1084. begin
  1085. left:=min(r.left,left);
  1086. top:=min(r.top,top);
  1087. right:=max(r.right,right);
  1088. bottom:=max(r.bottom,bottom);
  1089. end;
  1090. class function TRectF.Union(R1, R2: TRectF): TRectF;
  1091. begin
  1092. Result:=R1;
  1093. Result.Union(R2);
  1094. end;
  1095. { TPoint3D }
  1096. constructor TPoint3D.Create(const ax,ay,az:single);
  1097. begin
  1098. x:=ax; y:=ay; z:=az;
  1099. end;
  1100. procedure TPoint3D.Offset(const adeltax,adeltay,adeltaz:single);
  1101. begin
  1102. x:=x+adeltax; y:=y+adeltay; z:=z+adeltaz;
  1103. end;
  1104. procedure TPoint3D.Offset(const adelta:TPoint3D);
  1105. begin
  1106. x:=x+adelta.x; y:=y+adelta.y; z:=z+adelta.z;
  1107. end;
  1108. {$ifndef VER3_0}
  1109. generic class procedure TBitConverter.UnsafeFrom<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0);
  1110. begin
  1111. move(ASrcValue, ADestination[AOffset], SizeOf(T));
  1112. end;
  1113. generic class procedure TBitConverter.From<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0);
  1114. begin
  1115. if AOffset < 0 then
  1116. System.Error(reRangeError);
  1117. if IsManagedType(T) then
  1118. System.Error(reInvalidCast);
  1119. if Length(ADestination) < (SizeOf(T) + AOffset) then
  1120. System.Error(reRangeError);
  1121. TBitConverter.specialize UnsafeFrom<T>(ASrcValue, ADestination, AOffset);
  1122. end;
  1123. generic class function TBitConverter.UnsafeInTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T;
  1124. begin
  1125. move(ASource[AOffset], Result, SizeOf(T));
  1126. end;
  1127. generic class function TBitConverter.InTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T;
  1128. begin
  1129. if AOffset < 0 then
  1130. System.Error(reRangeError);
  1131. if IsManagedType(T) then
  1132. System.Error(reInvalidCast);
  1133. if Length(ASource) < (SizeOf(T) + AOffset) then
  1134. System.Error(reRangeError);
  1135. Result := TBitConverter.specialize UnsafeInTo<T>(ASource, AOffset);
  1136. end;
  1137. {$endif}
  1138. end.