types.pp 34 KB

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