types.pp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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. TClassicByteDynArray = TByteDynArray;
  50. TCardinalDynArray = array of Cardinal;
  51. TInt64DynArray = array of Int64;
  52. TIntegerDynArray = array of Integer;
  53. TLongWordDynArray = array of LongWord;
  54. TPointerDynArray = array of Pointer;
  55. TQWordDynArray = array of QWord;
  56. TShortIntDynArray = array of ShortInt;
  57. TSmallIntDynArray = array of SmallInt;
  58. TRTLStringDynArray = array of Ansistring;
  59. TAnsiStringDynArray = Array of AnsiString;
  60. TWideStringDynArray = array of WideString;
  61. TUnicodeStringDynArray = array of UnicodeString;
  62. {$if SIZEOF(CHAR)=2}
  63. TStringDynArray = Array of UnicodeString;
  64. {$ELSE}
  65. TStringDynArray = Array of AnsiString;
  66. {$ENDIF}
  67. TClassicStringDynArray = TStringDynArray;
  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 = Windows.TArray4IntegerType;
  79. TSmallPoint = Windows.TSmallPoint;
  80. PSmallPoint = Windows.PSmallPoint;
  81. TSize = Windows.TSize;
  82. TagSize = Windows.tagSize deprecated;
  83. PSize = Windows.PSize;
  84. TPoint = Windows.TPoint;
  85. TagPoint = Windows.TagPoint deprecated;
  86. PPoint = Windows.PPoint;
  87. TRect = Windows.TRect;
  88. PRect = Windows.PRect;
  89. TSplitRectType = 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 : Single);
  120. procedure Offset(const apt :TPointF);
  121. procedure Offset(const apt :TPoint);
  122. procedure Offset(dx,dy : Single);
  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 = Windows.PCLSID;
  353. TCLSID = Windows.CLSID;
  354. TFiletime = Windows.TFileTime;
  355. Filetime = Windows.FileTime;
  356. PFiletime = 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. Uses Math;
  422. {$if (not defined(win32)) and (not defined(win64)) and (not defined(wince))}
  423. {$i typshrd.inc}
  424. {$endif}
  425. function EqualRect(const r1,r2 : TRect) : Boolean;
  426. begin
  427. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  428. end;
  429. function Rect(Left,Top,Right,Bottom : Integer) : TRect; inline;
  430. begin
  431. Rect.Left:=Left;
  432. Rect.Top:=Top;
  433. Rect.Right:=Right;
  434. Rect.Bottom:=Bottom;
  435. end;
  436. function RectF(Left,Top,Right,Bottom : Single) : TRectF; inline;
  437. begin
  438. RectF.Left:=Left;
  439. RectF.Top:=Top;
  440. RectF.Right:=Right;
  441. RectF.Bottom:=Bottom;
  442. end;
  443. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect; inline;
  444. begin
  445. Bounds.Left:=ALeft;
  446. Bounds.Top:=ATop;
  447. Bounds.Right:=ALeft+AWidth;
  448. Bounds.Bottom:=ATop+AHeight;
  449. end;
  450. function Point(x,y : Integer) : TPoint; inline;
  451. begin
  452. Point.x:=x;
  453. Point.y:=y;
  454. end;
  455. function PointF(x,y: Single) : TPointF; inline;
  456. begin
  457. PointF.x:=x;
  458. PointF.y:=y;
  459. end;
  460. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  461. begin
  462. PtInRect:=(p.y>=Rect.Top) and
  463. (p.y<Rect.Bottom) and
  464. (p.x>=Rect.Left) and
  465. (p.x<Rect.Right);
  466. end;
  467. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  468. var
  469. lRect: TRect;
  470. begin
  471. lRect := R1;
  472. if R2.Left > R1.Left then
  473. lRect.Left := R2.Left;
  474. if R2.Top > R1.Top then
  475. lRect.Top := R2.Top;
  476. if R2.Right < R1.Right then
  477. lRect.Right := R2.Right;
  478. if R2.Bottom < R1.Bottom then
  479. lRect.Bottom := R2.Bottom;
  480. // The var parameter is only assigned in the end to avoid problems
  481. // when passing the same rectangle in the var and const parameters.
  482. // See http://bugs.freepascal.org/view.php?id=17722
  483. Result:=not IsRectEmpty(lRect);
  484. if Result then
  485. Rect := lRect
  486. else
  487. FillChar(Rect,SizeOf(Rect),0);
  488. end;
  489. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  490. var
  491. lRect: TRect;
  492. begin
  493. lRect:=R1;
  494. if R2.Left<R1.Left then
  495. lRect.Left:=R2.Left;
  496. if R2.Top<R1.Top then
  497. lRect.Top:=R2.Top;
  498. if R2.Right>R1.Right then
  499. lRect.Right:=R2.Right;
  500. if R2.Bottom>R1.Bottom then
  501. lRect.Bottom:=R2.Bottom;
  502. Result:=not IsRectEmpty(lRect);
  503. if Result then
  504. Rect := lRect
  505. else
  506. FillChar(Rect,SizeOf(Rect),0);
  507. end;
  508. function IsRectEmpty(const Rect : TRect) : Boolean;
  509. begin
  510. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  511. end;
  512. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  513. begin
  514. Result:=assigned(@Rect);
  515. if Result then
  516. with Rect do
  517. begin
  518. inc(Left,dx);
  519. inc(Top,dy);
  520. inc(Right,dx);
  521. inc(Bottom,dy);
  522. end;
  523. end;
  524. function Avg(a, b: Longint): Longint;
  525. begin
  526. if a < b then
  527. Result := a + ((b - a) shr 1)
  528. else
  529. Result := b + ((a - b) shr 1);
  530. end;
  531. function CenterPoint(const Rect: TRect): TPoint;
  532. begin
  533. with Rect do
  534. begin
  535. Result.X := Avg(Left, Right);
  536. Result.Y := Avg(Top, Bottom);
  537. end;
  538. end;
  539. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  540. begin
  541. Result:=assigned(@Rect);
  542. if Result then
  543. with Rect do
  544. begin
  545. dec(Left, dx);
  546. dec(Top, dy);
  547. inc(Right, dx);
  548. inc(Bottom, dy);
  549. end;
  550. end;
  551. function Size(AWidth, AHeight: Integer): TSize; inline;
  552. begin
  553. Result.cx := AWidth;
  554. Result.cy := AHeight;
  555. end;
  556. function Size(const ARect: TRect): TSize; inline;
  557. begin
  558. Result.cx := ARect.Right - ARect.Left;
  559. Result.cy := ARect.Bottom - ARect.Top;
  560. end;
  561. { TPointF}
  562. function TPointF.Add(const apt: TPoint): TPointF;
  563. begin
  564. result.x:=x+apt.x;
  565. result.y:=y+apt.y;
  566. end;
  567. function TPointF.Add(const apt: TPointF): TPointF;
  568. begin
  569. result.x:=x+apt.x;
  570. result.y:=y+apt.y;
  571. end;
  572. function TPointF.Subtract(const apt : TPointF): TPointF;
  573. begin
  574. result.x:=x-apt.x;
  575. result.y:=y-apt.y;
  576. end;
  577. function TPointF.Subtract(const apt: TPoint): TPointF;
  578. begin
  579. result.x:=x-apt.x;
  580. result.y:=y-apt.y;
  581. end;
  582. function TPointF.Distance(const apt : TPointF) : Single;
  583. begin
  584. result:=sqrt(sqr(apt.x-x)+sqr(apt.y-y));
  585. end;
  586. function TPointF.DotProduct(const apt: TPointF): Single;
  587. begin
  588. result:=x*apt.x+y*apt.y;
  589. end;
  590. function TPointF.IsZero : Boolean;
  591. begin
  592. result:=SameValue(x,0.0) and SameValue(y,0.0);
  593. end;
  594. procedure TPointF.Offset(const apt :TPointF);
  595. begin
  596. x:=x+apt.x;
  597. y:=y+apt.y;
  598. end;
  599. procedure TPointF.Offset(const apt: TPoint);
  600. begin
  601. x:=x+apt.x;
  602. y:=y+apt.y;
  603. end;
  604. procedure TPointF.Offset(dx,dy : Single);
  605. begin
  606. x:=x+dx;
  607. y:=y+dy;
  608. end;
  609. function TPointF.Scale(afactor: Single): TPointF;
  610. begin
  611. result.x:=afactor*x;
  612. result.y:=afactor*y;
  613. end;
  614. function TPointF.Ceiling: TPoint;
  615. begin
  616. result.x:=ceil(x);
  617. result.y:=ceil(y);
  618. end;
  619. function TPointF.Truncate: TPoint;
  620. begin
  621. result.x:=trunc(x);
  622. result.y:=trunc(y);
  623. end;
  624. function TPointF.Floor: TPoint;
  625. begin
  626. result.x:=Math.floor(x);
  627. result.y:=Math.floor(y);
  628. end;
  629. function TPointF.Round: TPoint;
  630. begin
  631. result.x:=System.round(x);
  632. result.y:=System.round(y);
  633. end;
  634. function TPointF.Length: Single;
  635. begin
  636. result:=sqrt(sqr(x)+sqr(y));
  637. end;
  638. function TPointF.Rotate(angle: single): TPointF;
  639. var
  640. sina, cosa: single;
  641. begin
  642. sincos(angle, sina, cosa);
  643. result.x := x * cosa - y * sina;
  644. result.y := x * sina + y * cosa;
  645. end;
  646. function TPointF.Reflect(const normal: TPointF): TPointF;
  647. begin
  648. result := self + (-2 * normal ** self) * normal;
  649. end;
  650. function TPointF.MidPoint(const b: TPointF): TPointF;
  651. begin
  652. result.x := 0.5 * (x + b.x);
  653. result.y := 0.5 * (y + b.y);
  654. end;
  655. class function TPointF.PointInCircle(const pt, center: TPointF; radius: single): Boolean;
  656. begin
  657. result := sqr(center.x - pt.x) + sqr(center.y - pt.y) < sqr(radius);
  658. end;
  659. class function TPointF.PointInCircle(const pt, center: TPointF; radius: integer): Boolean;
  660. begin
  661. result := sqr(center.x - pt.x) + sqr(center.y - pt.y) < sqr(single(radius));
  662. end;
  663. function TPointF.Angle(const b: TPointF): Single;
  664. begin
  665. result := ArcTan2(y - b.y, x - b.x);
  666. end;
  667. function TPointF.AngleCosine(const b: TPointF): single;
  668. begin
  669. result := EnsureRange((self ** b) / sqrt((sqr(x) + sqr(y)) * (sqr(b.x) + sqr(b.y))), -1, 1);
  670. end;
  671. class operator TPointF.= (const apt1, apt2 : TPointF) : Boolean;
  672. begin
  673. result:=SameValue(apt1.x,apt2.x) and SameValue(apt1.y,apt2.y);
  674. end;
  675. class operator TPointF.<> (const apt1, apt2 : TPointF): Boolean;
  676. begin
  677. result:=NOT (SameValue(apt1.x,apt2.x) and Samevalue(apt1.y,apt2.y));
  678. end;
  679. class operator TPointF. * (const apt1, apt2: TPointF): TPointF;
  680. begin
  681. result.x:=apt1.x*apt2.x;
  682. result.y:=apt1.y*apt2.y;
  683. end;
  684. class operator TPointF. * (afactor: single; const apt1: TPointF): TPointF;
  685. begin
  686. result:=apt1.Scale(afactor);
  687. end;
  688. class operator TPointF. * (const apt1: TPointF; afactor: single): TPointF;
  689. begin
  690. result:=apt1.Scale(afactor);
  691. end;
  692. class operator TPointF. ** (const apt1, apt2: TPointF): Single;
  693. begin
  694. result:=apt1.x*apt2.x + apt1.y*apt2.y;
  695. end;
  696. class operator TPointF.+ (const apt1, apt2 : TPointF): TPointF;
  697. begin
  698. result.x:=apt1.x+apt2.x;
  699. result.y:=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. - (const apt1: TPointF): TPointF;
  707. begin
  708. Result.x:=-apt1.x;
  709. Result.y:=-apt1.y;
  710. end;
  711. class operator TPointF. / (const apt1: TPointF; afactor: single): TPointF;
  712. begin
  713. result:=apt1.Scale(1/afactor);
  714. end;
  715. class operator TPointF. := (const apt: TPoint): TPointF;
  716. begin
  717. Result.x:=apt.x;
  718. Result.y:=apt.y;
  719. end;
  720. procedure TPointF.SetLocation(const apt :TPointF);
  721. begin
  722. x:=apt.x; y:=apt.y;
  723. end;
  724. procedure TPointF.SetLocation(const apt: TPoint);
  725. begin
  726. x:=apt.x; y:=apt.y;
  727. end;
  728. procedure TPointF.SetLocation(ax,ay : Single);
  729. begin
  730. x:=ax; y:=ay;
  731. end;
  732. class function TPointF.Create(const ax, ay: Single): TPointF;
  733. begin
  734. Result.x := ax;
  735. Result.y := ay;
  736. end;
  737. class function TPointF.Create(const apt: TPoint): TPointF;
  738. begin
  739. Result.x := apt.X;
  740. Result.y := apt.Y;
  741. end;
  742. { TSizeF }
  743. function TSizeF.Add(const asz: TSize): TSizeF;
  744. begin
  745. result.cx:=cx+asz.cx;
  746. result.cy:=cy+asz.cy;
  747. end;
  748. function TSizeF.Add(const asz: TSizeF): TSizeF;
  749. begin
  750. result.cx:=cx+asz.cx;
  751. result.cy:=cy+asz.cy;
  752. end;
  753. function TSizeF.Subtract(const asz : TSizeF): TSizeF;
  754. begin
  755. result.cx:=cx-asz.cx;
  756. result.cy:=cy-asz.cy;
  757. end;
  758. function TSizeF.SwapDimensions:TSizeF;
  759. begin
  760. result.cx:=cy;
  761. result.cy:=cx;
  762. end;
  763. function TSizeF.Subtract(const asz: TSize): TSizeF;
  764. begin
  765. result.cx:=cx-asz.cx;
  766. result.cy:=cy-asz.cy;
  767. end;
  768. function TSizeF.Distance(const asz : TSizeF) : Single;
  769. begin
  770. result:=sqrt(sqr(asz.cx-cx)+sqr(asz.cy-cy));
  771. end;
  772. function TSizeF.IsZero : Boolean;
  773. begin
  774. result:=SameValue(cx,0.0) and SameValue(cy,0.0);
  775. end;
  776. function TSizeF.Scale(afactor: Single): TSizeF;
  777. begin
  778. result.cx:=afactor*cx;
  779. result.cy:=afactor*cy;
  780. end;
  781. function TSizeF.Ceiling: TSize;
  782. begin
  783. result.cx:=ceil(cx);
  784. result.cy:=ceil(cy);
  785. end;
  786. function TSizeF.Truncate: TSize;
  787. begin
  788. result.cx:=trunc(cx);
  789. result.cy:=trunc(cy);
  790. end;
  791. function TSizeF.Floor: TSize;
  792. begin
  793. result.cx:=Math.floor(cx);
  794. result.cy:=Math.floor(cy);
  795. end;
  796. function TSizeF.Round: TSize;
  797. begin
  798. result.cx:=System.round(cx);
  799. result.cy:=System.round(cy);
  800. end;
  801. function TSizeF.Length: Single;
  802. begin //distance(self) ?
  803. result:=sqrt(sqr(cx)+sqr(cy));
  804. end;
  805. class operator TSizeF.= (const asz1, asz2 : TSizeF) : Boolean;
  806. begin
  807. result:=SameValue(asz1.cx,asz2.cx) and SameValue(asz1.cy,asz2.cy);
  808. end;
  809. class operator TSizeF.<> (const asz1, asz2 : TSizeF): Boolean;
  810. begin
  811. result:=NOT (SameValue(asz1.cx,asz2.cx) and Samevalue(asz1.cy,asz2.cy));
  812. end;
  813. class operator TSizeF. * (afactor: single; const asz1: TSizeF): TSizeF;
  814. begin
  815. result:=asz1.Scale(afactor);
  816. end;
  817. class operator TSizeF. * (const asz1: TSizeF; afactor: single): TSizeF;
  818. begin
  819. result:=asz1.Scale(afactor);
  820. end;
  821. class operator TSizeF.+ (const asz1, asz2 : TSizeF): TSizeF;
  822. begin
  823. result.cx:=asz1.cx+asz2.cx;
  824. result.cy:=asz1.cy+asz2.cy;
  825. end;
  826. class operator TSizeF.- (const asz1, asz2 : TSizeF): TSizeF;
  827. begin
  828. result.cx:=asz1.cx-asz2.cx;
  829. result.cy:=asz1.cy-asz2.cy;
  830. end;
  831. class operator TSizeF. - (const asz1: TSizeF): TSizeF;
  832. begin
  833. Result.cx:=-asz1.cx;
  834. Result.cy:=-asz1.cy;
  835. end;
  836. class operator TSizeF. := (const apt: TPointF): TSizeF;
  837. begin
  838. Result.cx:=apt.x;
  839. Result.cy:=apt.y;
  840. end;
  841. class operator TSizeF. := (const asz: TSize): TSizeF;
  842. begin
  843. Result.cx := asz.cx;
  844. Result.cy := asz.cy;
  845. end;
  846. class operator TSizeF. := (const asz: TSizeF): TPointF;
  847. begin
  848. Result.x := asz.cx;
  849. Result.y := asz.cy;
  850. end;
  851. class function TSizeF.Create(const ax, ay: Single): TSizeF;
  852. begin
  853. Result.cx := ax;
  854. Result.cy := ay;
  855. end;
  856. class function TSizeF.Create(const asz: TSize): TSizeF;
  857. begin
  858. Result.cx := asz.cX;
  859. Result.cy := asz.cY;
  860. end;
  861. { TRectF }
  862. class operator TRectF. * (L, R: TRectF): TRectF;
  863. begin
  864. Result := TRectF.Intersect(L, R);
  865. end;
  866. class operator TRectF. + (L, R: TRectF): TRectF;
  867. begin
  868. Result := TRectF.Union(L, R);
  869. end;
  870. class operator TRectF. := (const arc: TRect): TRectF;
  871. begin
  872. Result.Left:=arc.Left;
  873. Result.Top:=arc.Top;
  874. Result.Right:=arc.Right;
  875. Result.Bottom:=arc.Bottom;
  876. end;
  877. class operator TRectF. <> (L, R: TRectF): Boolean;
  878. begin
  879. Result := not(L=R);
  880. end;
  881. class operator TRectF. = (L, R: TRectF): Boolean;
  882. begin
  883. Result :=
  884. SameValue(L.Left,R.Left) and SameValue(L.Right,R.Right) and
  885. SameValue(L.Top,R.Top) and SameValue(L.Bottom,R.Bottom);
  886. end;
  887. constructor TRectF.Create(ALeft, ATop, ARight, ABottom: Single);
  888. begin
  889. Left := ALeft;
  890. Top := ATop;
  891. Right := ARight;
  892. Bottom := ABottom;
  893. end;
  894. constructor TRectF.Create(P1, P2: TPointF; Normalize: Boolean);
  895. begin
  896. TopLeft := P1;
  897. BottomRight := P2;
  898. if Normalize then
  899. NormalizeRect;
  900. end;
  901. constructor TRectF.Create(Origin: TPointF);
  902. begin
  903. TopLeft := Origin;
  904. BottomRight := Origin;
  905. end;
  906. constructor TRectF.Create(Origin: TPointF; AWidth, AHeight: Single);
  907. begin
  908. TopLeft := Origin;
  909. Width := AWidth;
  910. Height := AHeight;
  911. end;
  912. constructor TRectF.Create(R: TRectF; Normalize: Boolean);
  913. begin
  914. Self := R;
  915. if Normalize then
  916. NormalizeRect;
  917. end;
  918. constructor TRectF.Create(R: TRect; Normalize: Boolean);
  919. begin
  920. Self := R;
  921. if Normalize then
  922. NormalizeRect;
  923. end;
  924. function TRectF.CenterPoint: TPointF;
  925. begin
  926. Result.X := (Right-Left) / 2 + Left;
  927. Result.Y := (Bottom-Top) / 2 + Top;
  928. end;
  929. function TRectF.Contains(Pt: TPointF): Boolean;
  930. begin
  931. Result := (Left <= Pt.X) and (Pt.X < Right) and (Top <= Pt.Y) and (Pt.Y < Bottom);
  932. end;
  933. function TRectF.Contains(R: TRectF): Boolean;
  934. begin
  935. Result := (Left <= R.Left) and (R.Right <= Right) and (Top <= R.Top) and (R.Bottom <= Bottom);
  936. end;
  937. class function TRectF.Empty: TRectF;
  938. begin
  939. Result := TRectF.Create(0,0,0,0);
  940. end;
  941. function TRectF.GetHeight: Single;
  942. begin
  943. result:=bottom-top;
  944. end;
  945. function TRectF.GetLocation: TPointF;
  946. begin
  947. result.x:=Left; result.y:=top;
  948. end;
  949. function TRectF.GetSize: TSizeF;
  950. begin
  951. result.cx:=width; result.cy:=height;
  952. end;
  953. function TRectF.GetWidth: Single;
  954. begin
  955. result:=right-left;
  956. end;
  957. procedure TRectF.Inflate(DX, DY: Single);
  958. begin
  959. Left:=Left-dx;
  960. Top:=Top-dy;
  961. Right:=Right+dx;
  962. Bottom:=Bottom+dy;
  963. end;
  964. procedure TRectF.Intersect(R: TRectF);
  965. begin
  966. Self := Intersect(Self, R);
  967. end;
  968. class function TRectF.Intersect(R1: TRectF; R2: TRectF): TRectF;
  969. begin
  970. Result := R1;
  971. if R2.Left > R1.Left then
  972. Result.Left := R2.Left;
  973. if R2.Top > R1.Top then
  974. Result.Top := R2.Top;
  975. if R2.Right < R1.Right then
  976. Result.Right := R2.Right;
  977. if R2.Bottom < R1.Bottom then
  978. Result.Bottom := R2.Bottom;
  979. end;
  980. function TRectF.IntersectsWith(R: TRectF): Boolean;
  981. begin
  982. Result := (Left < R.Right) and (R.Left < Right) and (Top < R.Bottom) and (R.Top < Bottom);
  983. end;
  984. function TRectF.IsEmpty: Boolean;
  985. begin
  986. Result := (CompareValue(Right,Left)<=0) or (CompareValue(Bottom,Top)<=0);
  987. end;
  988. procedure TRectF.NormalizeRect;
  989. var
  990. x: Single;
  991. begin
  992. if Top>Bottom then
  993. begin
  994. x := Top;
  995. Top := Bottom;
  996. Bottom := x;
  997. end;
  998. if Left>Right then
  999. begin
  1000. x := Left;
  1001. Left := Right;
  1002. Right := x;
  1003. end
  1004. end;
  1005. procedure TRectF.Inflate(DL, DT, DR, DB: Single);
  1006. begin
  1007. Left:=Left-dl;
  1008. Top:=Top-dt;
  1009. Right:=Right+dr;
  1010. Bottom:=Bottom+db;
  1011. end;
  1012. procedure TRectF.Offset(const dx, dy: Single);
  1013. begin
  1014. left:=left+dx; right:=right+dx;
  1015. bottom:=bottom+dy; top:=top+dy;
  1016. end;
  1017. procedure TRectF.Offset(DP: TPointF);
  1018. begin
  1019. left:=left+DP.x; right:=right+DP.x;
  1020. bottom:=bottom+DP.y; top:=top+DP.y;
  1021. end;
  1022. procedure TRectF.SetHeight(AValue: Single);
  1023. begin
  1024. bottom:=top+avalue;
  1025. end;
  1026. procedure TRectF.SetLocation(X, Y: Single);
  1027. begin
  1028. Offset(X-Left, Y-Top);
  1029. end;
  1030. procedure TRectF.SetLocation(P: TPointF);
  1031. begin
  1032. SetLocation(P.X, P.Y);
  1033. end;
  1034. procedure TRectF.SetSize(AValue: TSizeF);
  1035. begin
  1036. bottom:=top+avalue.cy;
  1037. right:=left+avalue.cx;
  1038. end;
  1039. procedure TRectF.SetWidth(AValue: Single);
  1040. begin
  1041. right:=left+avalue;
  1042. end;
  1043. class function TRectF.Union(const Points: array of TPointF): TRectF;
  1044. var
  1045. i: Integer;
  1046. begin
  1047. if Length(Points) > 0 then
  1048. begin
  1049. Result.TopLeft := Points[Low(Points)];
  1050. Result.BottomRight := Points[Low(Points)];
  1051. for i := Low(Points)+1 to High(Points) do
  1052. begin
  1053. if Points[i].X < Result.Left then Result.Left := Points[i].X;
  1054. if Points[i].X > Result.Right then Result.Right := Points[i].X;
  1055. if Points[i].Y < Result.Top then Result.Top := Points[i].Y;
  1056. if Points[i].Y > Result.Bottom then Result.Bottom := Points[i].Y;
  1057. end;
  1058. end else
  1059. Result := Empty;
  1060. end;
  1061. procedure TRectF.Union(const r: TRectF);
  1062. begin
  1063. left:=min(r.left,left);
  1064. top:=min(r.top,top);
  1065. right:=max(r.right,right);
  1066. bottom:=max(r.bottom,bottom);
  1067. end;
  1068. class function TRectF.Union(R1, R2: TRectF): TRectF;
  1069. begin
  1070. Result:=R1;
  1071. Result.Union(R2);
  1072. end;
  1073. { TPoint3D }
  1074. constructor TPoint3D.Create(const ax,ay,az:single);
  1075. begin
  1076. x:=ax; y:=ay; z:=az;
  1077. end;
  1078. procedure TPoint3D.Offset(const adeltax,adeltay,adeltaz:single);
  1079. begin
  1080. x:=x+adeltax; y:=y+adeltay; z:=z+adeltaz;
  1081. end;
  1082. procedure TPoint3D.Offset(const adelta:TPoint3D);
  1083. begin
  1084. x:=x+adelta.x; y:=y+adelta.y; z:=z+adelta.z;
  1085. end;
  1086. {$ifndef VER3_0}
  1087. generic class procedure TBitConverter.UnsafeFrom<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0);
  1088. begin
  1089. move(ASrcValue, ADestination[AOffset], SizeOf(T));
  1090. end;
  1091. generic class procedure TBitConverter.From<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0);
  1092. begin
  1093. if AOffset < 0 then
  1094. System.Error(reRangeError);
  1095. if IsManagedType(T) then
  1096. System.Error(reInvalidCast);
  1097. if Length(ADestination) < (SizeOf(T) + AOffset) then
  1098. System.Error(reRangeError);
  1099. TBitConverter.specialize UnsafeFrom<T>(ASrcValue, ADestination, AOffset);
  1100. end;
  1101. generic class function TBitConverter.UnsafeInTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T;
  1102. begin
  1103. move(ASource[AOffset], Result, SizeOf(T));
  1104. end;
  1105. generic class function TBitConverter.InTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T;
  1106. begin
  1107. if AOffset < 0 then
  1108. System.Error(reRangeError);
  1109. if IsManagedType(T) then
  1110. System.Error(reInvalidCast);
  1111. if Length(ASource) < (SizeOf(T) + AOffset) then
  1112. System.Error(reRangeError);
  1113. Result := TBitConverter.specialize UnsafeInTo<T>(ASource, AOffset);
  1114. end;
  1115. {$endif}
  1116. end.