types.pp 34 KB

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