types.pp 34 KB

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