types.pp 34 KB

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