types.pp 34 KB

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