types.pp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833
  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. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit Types;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$modeswitch advancedrecords}
  17. {$modeswitch class}
  18. {$if defined(win32) or defined(win64) or defined(wince)}
  19. uses
  20. {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows;
  21. {$elseif defined(win16)}
  22. uses
  23. {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}WinTypes;
  24. {$endif}
  25. {$if defined(win32) or defined(win64)}
  26. const
  27. RT_RCDATA = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.RT_RCDATA deprecated 'Use Windows.RT_RCDATA instead';
  28. {$elseif defined(win16)}
  29. const
  30. RT_RCDATA = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}WinTypes.RT_RCDATA deprecated 'Use WinTypes.RT_RCDATA instead';
  31. {$endif}
  32. Const
  33. Epsilon: Single = 1E-40;
  34. Epsilon2: Single = 1E-30;
  35. type
  36. TEndian = Objpas.TEndian;
  37. TDirection = (FromBeginning, FromEnd);
  38. TValueRelationship = -1..1;
  39. DWORD = LongWord;
  40. PLongint = System.PLongint;
  41. PSmallInt = System.PSmallInt;
  42. {$ifndef FPUNONE}
  43. PDouble = System.PDouble;
  44. {$endif}
  45. PByte = System.PByte;
  46. Largeint = int64;
  47. LARGE_INT = LargeInt;
  48. PLargeInt = ^LargeInt;
  49. LargeUint = qword;
  50. LARGE_UINT= LargeUInt;
  51. PLargeuInt = ^LargeuInt;
  52. TBooleanDynArray = array of Boolean;
  53. TByteDynArray = array of Byte;
  54. TClassicByteDynArray = TByteDynArray;
  55. TCardinalDynArray = array of Cardinal;
  56. TInt64DynArray = array of Int64;
  57. TIntegerDynArray = array of Integer;
  58. TLongWordDynArray = array of LongWord;
  59. TPointerDynArray = array of Pointer;
  60. TQWordDynArray = array of QWord;
  61. TShortIntDynArray = array of ShortInt;
  62. TSmallIntDynArray = array of SmallInt;
  63. TRTLStringDynArray = array of RTLString;
  64. TAnsiStringDynArray = Array of AnsiString;
  65. TWideStringDynArray = array of WideString;
  66. TUnicodeStringDynArray = array of UnicodeString;
  67. {$if SIZEOF(CHAR)=2}
  68. TStringDynArray = Array of UnicodeString;
  69. {$ELSE}
  70. TStringDynArray = Array of AnsiString;
  71. {$ENDIF}
  72. TClassicStringDynArray = TStringDynArray;
  73. TObjectDynArray = array of TObject;
  74. TWordDynArray = array of Word;
  75. TCurrencyArray = Array of currency;
  76. {$ifndef FPUNONE}
  77. TSingleDynArray = array of Single;
  78. TDoubleDynArray = array of Double;
  79. TExtendedDynArray = array of Extended;
  80. TCompDynArray = array of Comp;
  81. {$endif}
  82. {$if defined(win32) or defined(win64) or defined(wince)}
  83. TArray4IntegerType = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TArray4IntegerType;
  84. TSmallPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TSmallPoint;
  85. PSmallPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PSmallPoint;
  86. TSize = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TSize;
  87. TagSize = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.tagSize deprecated;
  88. PSize = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PSize;
  89. TPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TPoint;
  90. TagPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TagPoint deprecated;
  91. PPoint = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PPoint;
  92. TRect = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TRect;
  93. PRect = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PRect;
  94. TSplitRectType = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TSplitRectType;
  95. const
  96. srLeft = TSplitRectType.srLeft;
  97. srRight = TSplitRectType.srRight;
  98. srTop = TSplitRectType.srTop;
  99. srBottom = TSplitRectType.srBottom;
  100. type
  101. {$else}
  102. {$i typshrdh.inc}
  103. TagSize = tSize deprecated;
  104. TagPoint = TPoint deprecated;
  105. {$endif}
  106. { TPointF }
  107. PPointF = ^TPointF;
  108. TPointF =
  109. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  110. packed
  111. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  112. record
  113. x,y : Single;
  114. public
  115. function Add(const apt: TPoint): TPointF;
  116. function Add(const apt: TPointF): TPointF;
  117. function Distance(const apt : TPointF) : Single;
  118. function DotProduct(const apt : TPointF) : Single;
  119. function IsZero : Boolean;
  120. function Subtract(const apt : TPointF): TPointF;
  121. function Subtract(const apt : TPoint): TPointF;
  122. procedure SetLocation(const apt :TPointF);
  123. procedure SetLocation(const apt :TPoint);
  124. procedure SetLocation(ax,ay : Single);
  125. procedure Offset(const apt :TPointF);
  126. procedure Offset(const apt :TPoint);
  127. procedure Offset(dx,dy : Single);
  128. function EqualsTo(const apt: TPointF; const aEpsilon : Single): Boolean;
  129. function Scale (afactor:Single) : TPointF;
  130. function Ceiling : TPoint;
  131. function Truncate: TPoint;
  132. function Floor : TPoint;
  133. function Round : TPoint;
  134. function Length : Single;
  135. function Rotate(angle: single): TPointF;
  136. function Reflect(const normal: TPointF): TPointF;
  137. function MidPoint(const b: TPointF): TPointF;
  138. class function PointInCircle(const pt, center: TPointF; radius: single): Boolean; static;
  139. class function PointInCircle(const pt, center: TPointF; radius: integer): Boolean; static;
  140. class function Zero: TPointF; inline; static;
  141. function Angle(const b: TPointF): Single;
  142. function AngleCosine(const b: TPointF): single;
  143. function CrossProduct(const apt: TPointF): Single;
  144. function Normalize: TPointF;
  145. class function Create(const ax, ay: Single): TPointF; overload; static; inline;
  146. class function Create(const apt: TPoint): TPointF; overload; static; inline;
  147. class operator = (const apt1, apt2 : TPointF) : Boolean;
  148. class operator <> (const apt1, apt2 : TPointF): Boolean;
  149. class operator + (const apt1, apt2 : TPointF): TPointF;
  150. class operator - (const apt1, apt2 : TPointF): TPointF;
  151. class operator - (const apt1 : TPointF): TPointF;
  152. class operator * (const apt1, apt2: TPointF): TPointF;
  153. class operator * (const apt1: TPointF; afactor: single): TPointF;
  154. class operator * (afactor: single; const apt1: TPointF): TPointF;
  155. class operator / (const apt1: TPointF; afactor: single): TPointF;
  156. class operator := (const apt: TPoint): TPointF;
  157. class operator ** (const apt1, apt2: TPointF): Single; // scalar product
  158. end;
  159. { TSizeF }
  160. PSizeF = ^TSizeF;
  161. TSizeF =
  162. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  163. packed
  164. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  165. record
  166. cx,cy : Single;
  167. public
  168. function Add(const asz: TSize): TSizeF;
  169. function Add(const asz: TSizeF): TSizeF;
  170. function Distance(const asz : TSizeF) : Single;
  171. function IsZero : Boolean;
  172. function Subtract(const asz : TSizeF): TSizeF;
  173. function Subtract(const asz : TSize): TSizeF;
  174. function SwapDimensions:TSizeF;
  175. function Scale (afactor:Single) : TSizeF;
  176. function Ceiling : TSize;
  177. function Truncate: TSize;
  178. function Floor : TSize;
  179. function Round : TSize;
  180. function Length : Single;
  181. class function Create(const ax, ay: Single): TSizeF; overload; static; inline;
  182. class function Create(const asz: TSize): TSizeF; overload; static; inline;
  183. class operator = (const asz1, asz2 : TSizeF) : Boolean;
  184. class operator <> (const asz1, asz2 : TSizeF): Boolean;
  185. class operator + (const asz1, asz2 : TSizeF): TSizeF;
  186. class operator - (const asz1, asz2 : TSizeF): TSizeF;
  187. class operator - (const asz1 : TSizeF): TSizeF;
  188. class operator * (const asz1: TSizeF; afactor: single): TSizeF;
  189. class operator * (afactor: single; const asz1: TSizeF): TSizeF;
  190. class operator := (const apt: TPointF): TSizeF;
  191. class operator := (const asz: TSize): TSizeF;
  192. class operator := (const asz: TSizeF): TPointF;
  193. property Width: Single read cx write cx;
  194. property Height: Single read cy write cy;
  195. end;
  196. {$SCOPEDENUMS ON}
  197. TVertRectAlign = (Center, Top, Bottom);
  198. THorzRectAlign = (Center, Left, Right);
  199. {$SCOPEDENUMS OFF}
  200. { TRectF }
  201. PRectF = ^TRectF;
  202. TRectF =
  203. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  204. packed
  205. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  206. record
  207. private
  208. function GetLocation: TPointF;
  209. function GetSize: TSizeF;
  210. procedure SetSize(AValue: TSizeF);
  211. function GetHeight: Single; inline;
  212. function GetWidth: Single; inline;
  213. procedure SetHeight(AValue: Single);
  214. procedure SetWidth (AValue: Single);
  215. public
  216. constructor Create(Origin: TPointF); // empty rect at given origin
  217. constructor Create(Origin: TPointF; AWidth, AHeight: Single);
  218. constructor Create(ALeft, ATop, ARight, ABottom: Single);
  219. constructor Create(P1, P2: TPointF; Normalize: Boolean = False);
  220. constructor Create(R: TRectF; Normalize: Boolean = False);
  221. constructor Create(R: TRect; Normalize: Boolean = False);
  222. class operator = (L, R: TRectF): Boolean;
  223. class operator <> (L, R: TRectF): Boolean;
  224. class operator + (L, R: TRectF): TRectF; // union
  225. class operator * (L, R: TRectF): TRectF; // intersection
  226. class operator := (const arc: TRect): TRectF;
  227. class function Empty: TRectF; static;
  228. class function Intersect(R1: TRectF; R2: TRectF): TRectF; static;
  229. class function Union(const Points: array of TPointF): TRectF; static;
  230. class function Union(R1, R2: TRectF): TRectF; static;
  231. Function Ceiling : TRectF;
  232. function CenterAt(const Dest: TRectF): TRectF;
  233. function CenterPoint: TPointF;
  234. function Contains(Pt: TPointF): Boolean;
  235. function Contains(R: TRectF): Boolean;
  236. function EqualsTo(const R: TRectF; const Epsilon: Single = 0): Boolean;
  237. function Fit(const Dest: TRectF): Single; deprecated 'Use FitInto';
  238. function FitInto(const Dest: TRectF): TRectF; overload;
  239. function FitInto(const Dest: TRectF; out Ratio: Single): TRectF; overload;
  240. function IntersectsWith(R: TRectF): Boolean;
  241. function IsEmpty: Boolean;
  242. function PlaceInto(const Dest: TRectF; const AHorzAlign: THorzRectAlign = THorzRectAlign.Center; const AVertAlign: TVertRectAlign = TVertRectAlign.Center): TRectF;
  243. function Round: TRect;
  244. function SnapToPixel(AScale: Single; APlaceBetweenPixels: Boolean = True): TRectF;
  245. function Truncate: TRect;
  246. procedure Inflate(DL, DT, DR, DB: Single);
  247. procedure Inflate(DX, DY: Single);
  248. procedure Intersect(R: TRectF);
  249. procedure NormalizeRect;
  250. procedure Offset (const dx,dy : Single); inline;
  251. procedure Offset (DP: TPointF); inline;
  252. procedure SetLocation(P: TPointF);
  253. procedure SetLocation(X, Y: Single);
  254. procedure Union (const r: TRectF); inline;
  255. property Width : Single read GetWidth write SetWidth;
  256. property Height : Single read GetHeight write SetHeight;
  257. property Size : TSizeF read getSize write SetSize;
  258. property Location: TPointF read getLocation write setLocation;
  259. case Integer of
  260. 0: (Left, Top, Right, Bottom: Single);
  261. 1: (TopLeft, BottomRight: TPointF);
  262. end;
  263. TDuplicates = (dupIgnore, dupAccept, dupError);
  264. TPoint3D =
  265. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  266. packed
  267. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  268. record
  269. public
  270. Type TSingle3Array = array[0..2] of single;
  271. constructor Create(const ax,ay,az:single);
  272. procedure Offset(const adeltax,adeltay,adeltaz:single); inline;
  273. procedure Offset(const adelta:TPoint3D); inline;
  274. public
  275. case Integer of
  276. 0: (data:TSingle3Array);
  277. 1: (x,y,z : single);
  278. end;
  279. type
  280. TOleChar = WideChar;
  281. POleStr = PWideChar;
  282. PPOleStr = ^POleStr;
  283. TListCallback = procedure(data,arg:pointer) of object;
  284. TListStaticCallback = procedure(data,arg:pointer);
  285. const
  286. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  287. STGTY_STORAGE = 1;
  288. STGTY_STREAM = 2;
  289. STGTY_LOCKBYTES = 3;
  290. STGTY_PROPERTY = 4;
  291. STREAM_SEEK_SET = 0;
  292. STREAM_SEEK_CUR = 1;
  293. STREAM_SEEK_END = 2;
  294. LOCK_WRITE = 1;
  295. LOCK_EXCLUSIVE = 2;
  296. LOCK_ONLYONCE = 4;
  297. STATFLAG_DEFAULT = 0;
  298. STATFLAG_NONAME = 1;
  299. STATFLAG_NOOPEN = 2;
  300. {$ifndef Wince}
  301. // in Wince these are in unit windows. Under 32/64 in ActiveX.
  302. // for now duplicate them. Not that bad for untyped constants.
  303. E_FAIL = HRESULT($80004005);
  304. E_INVALIDARG = HRESULT($80070057);
  305. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  306. STG_E_FILENOTFOUND = HRESULT($80030002);
  307. STG_E_PATHNOTFOUND = HRESULT($80030003);
  308. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  309. STG_E_ACCESSDENIED = HRESULT($80030005);
  310. STG_E_INVALIDHANDLE = HRESULT($80030006);
  311. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  312. STG_E_INVALIDPOINTER = HRESULT($80030009);
  313. STG_E_NOMOREFILES = HRESULT($80030012);
  314. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  315. STG_E_SEEKERROR = HRESULT($80030019);
  316. STG_E_WRITEFAULT = HRESULT($8003001D);
  317. STG_E_READFAULT = HRESULT($8003001E);
  318. STG_E_SHAREVIOLATION = HRESULT($80030020);
  319. STG_E_LOCKVIOLATION = HRESULT($80030021);
  320. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  321. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  322. STG_E_MEDIUMFULL = HRESULT($80030070);
  323. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  324. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  325. STG_E_INVALIDHEADER = HRESULT($800300FB);
  326. STG_E_INVALIDNAME = HRESULT($800300FC);
  327. STG_E_UNKNOWN = HRESULT($800300FD);
  328. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  329. STG_E_INVALIDFLAG = HRESULT($800300FF);
  330. STG_E_INUSE = HRESULT($80030100);
  331. STG_E_NOTCURRENT = HRESULT($80030101);
  332. STG_E_REVERTED = HRESULT($80030102);
  333. STG_E_CANTSAVE = HRESULT($80030103);
  334. STG_E_OLDFORMAT = HRESULT($80030104);
  335. STG_E_OLDDLL = HRESULT($80030105);
  336. STG_E_SHAREREQUIRED = HRESULT($80030106);
  337. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  338. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  339. STG_E_BADBASEADDRESS = HRESULT($80030110);
  340. STG_E_INCOMPLETE = HRESULT($80030201);
  341. STG_E_TERMINATED = HRESULT($80030202);
  342. STG_S_CONVERTED = $00030200;
  343. STG_S_BLOCK = $00030201;
  344. STG_S_RETRYNOW = $00030202;
  345. STG_S_MONITORING = $00030203;
  346. {$endif}
  347. {$if (not defined(win32)) and (not defined(win64)) and (not defined(wince))}
  348. type
  349. PCLSID = PGUID;
  350. TCLSID = TGUID;
  351. PDWord = ^DWord;
  352. PDisplay = Pointer;
  353. PEvent = Pointer;
  354. TXrmOptionDescRec = record
  355. end;
  356. XrmOptionDescRec = TXrmOptionDescRec;
  357. PXrmOptionDescRec = ^TXrmOptionDescRec;
  358. Widget = Pointer;
  359. WidgetClass = Pointer;
  360. ArgList = Pointer;
  361. Region = Pointer;
  362. _FILETIME =
  363. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  364. packed
  365. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  366. record
  367. dwLowDateTime : DWORD;
  368. dwHighDateTime : DWORD;
  369. end;
  370. TFileTime = _FILETIME;
  371. FILETIME = _FILETIME;
  372. PFileTime = ^TFileTime;
  373. {$else}
  374. type
  375. PCLSID = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PCLSID;
  376. TCLSID = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.CLSID;
  377. TFiletime = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.TFileTime;
  378. Filetime = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.FileTime;
  379. PFiletime = {$IFDEF FPC_DOTTEDUNITS}WinApi.{$ENDIF}Windows.PFileTime;
  380. {$endif Windows}
  381. type
  382. tagSTATSTG = record
  383. pwcsName : POleStr;
  384. dwType : DWord;
  385. cbSize : Large_uint;
  386. mtime : TFileTime;
  387. ctime : TFileTime;
  388. atime : TFileTime;
  389. grfMode : DWord;
  390. grfLocksSupported : DWord;
  391. clsid : TCLSID;
  392. grfStateBits : DWord;
  393. reserved : DWord;
  394. end;
  395. TStatStg = tagSTATSTG;
  396. STATSTG = TStatStg;
  397. PStatStg = ^TStatStg;
  398. { classes depends on these interfaces, we can't use the activex unit in classes though }
  399. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  400. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  401. Function LockServer(fLock : LongBool) : HResult;StdCall;
  402. End;
  403. ISequentialStream = interface(IUnknown)
  404. ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  405. function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
  406. function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
  407. end;
  408. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  409. function Seek(dlibMove : LargeInt; dwOrigin : DWORD; out libNewPosition : LargeUInt) : HResult;stdcall;
  410. function SetSize(libNewSize : LargeUInt) : HRESULT;stdcall;
  411. function CopyTo(stm: IStream;cb : LargeUInt;out cbRead : LargeUInt; out cbWritten : LargeUInt) : HRESULT;stdcall;
  412. function Commit(grfCommitFlags : DWORD) : HRESULT;stdcall;
  413. function Revert : HRESULT;stdcall;
  414. function LockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : DWORD) : HRESULT;stdcall;
  415. function UnlockRegion(libOffset : LargeUInt;cb : LargeUInt; dwLockType : DWORD) : HRESULT;stdcall;
  416. Function Stat(out statstg : TStatStg;grfStatFlag : DWORD) : HRESULT;stdcall;
  417. function Clone(out stm : IStream) : HRESULT;stdcall;
  418. end;
  419. function EqualRect(const r1,r2 : TRect) : Boolean;
  420. function EqualRect(const r1,r2 : TRectF) : Boolean;
  421. function NormalizeRectF(const Pts: array of TPointF): TRectF; overload;
  422. function NormalizeRect(const ARect: TRectF): TRectF; overload;
  423. function Rect(Left,Top,Right,Bottom : Integer) : TRect; inline;
  424. function RectF(Left,Top,Right,Bottom : Single) : TRectF; inline;
  425. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect; inline;
  426. function Point(x,y : Integer) : TPoint; inline;
  427. function PointF(x,y: Single) : TPointF; inline;
  428. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  429. function PtInRect(const Rect : TRectF; const p : TPointF) : Boolean;
  430. function IntersectRect(const Rect1, Rect2: TRect): Boolean;
  431. function IntersectRect(const Rect1, Rect2: TRectF): Boolean;
  432. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  433. function IntersectRect(var Rect : TRectF; const R1,R2 : TRectF) : Boolean;
  434. function RectCenter(var R: TRect; const Bounds: TRect): TRect;
  435. function RectCenter(var R: TRectF; const Bounds: TRectF): TRectF;
  436. function RectHeight(const Rect: TRect): Integer; inline;
  437. function RectHeight(const Rect: TRectF): Single; inline;
  438. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  439. function UnionRect(var Rect : TRectF; const R1,R2 : TRectF) : Boolean;
  440. function UnionRect(const R1,R2 : TRect) : TRect;
  441. function UnionRect(const R1,R2 : TRectF) : TRectF;
  442. function IsRectEmpty(const Rect : TRectF) : Boolean;
  443. function IsRectEmpty(const Rect : TRect) : Boolean;
  444. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  445. function OffsetRect(var Rect : TRectF;DX : Single;DY : Single) : Boolean;
  446. procedure MultiplyRect(var R: TRectF; const DX, DY: Single);
  447. function CenterPoint(const Rect: TRect): TPoint;
  448. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  449. function InflateRect(var Rect: TRectF; dx: single; dy: Single): Boolean;
  450. function Size(AWidth, AHeight: Integer): TSize; inline;
  451. function Size(const ARect: TRect): TSize;
  452. function ScalePoint(const P: TPointF; dX, dY: Single): TPointF; overload;
  453. function ScalePoint(const P: TPoint; dX, dY: Single): TPoint; overload;
  454. function MinPoint(const P1, P2: TPointF): TPointF; overload;
  455. function MinPoint(const P1, P2: TPoint): TPoint; overload;
  456. function SplitRect(const Rect: TRect; SplitType: TSplitRectType; Size: Integer): TRect; overload;
  457. function SplitRect(const Rect: TRect; SplitType: TSplitRectType; Percent: Double): TRect; overload;
  458. function CenteredRect(const SourceRect: TRect; const aCenteredRect: TRect): TRect;
  459. function IntersectRectF(out Rect: TRectF; const R1, R2: TRectF): Boolean;
  460. function UnionRectF(out Rect: TRectF; const R1, R2: TRectF): Boolean;
  461. {$ifndef VER3_0}
  462. type
  463. TBitConverter = class
  464. generic class procedure UnsafeFrom<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0); static; {inline;}
  465. generic class procedure From<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0); static;
  466. generic class function UnsafeInTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T; static; {inline;}
  467. generic class function InTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T; static;
  468. end;
  469. {$endif}
  470. implementation
  471. {$IFDEF FPC_DOTTEDUNITS}
  472. Uses System.Math;
  473. {$ELSE FPC_DOTTEDUNITS}
  474. Uses Math;
  475. {$ENDIF FPC_DOTTEDUNITS}
  476. {$if (not defined(win32)) and (not defined(win64)) and (not defined(wince))}
  477. {$i typshrd.inc}
  478. {$endif}
  479. function SmallPoint(X, Y: Integer): TSmallPoint; inline; overload;
  480. begin
  481. Result.X:=X;
  482. Result.Y:=Y;
  483. end;
  484. function SmallPoint(XY: LongWord): TSmallPoint; overload;
  485. begin
  486. Result.X:=SmallInt(XY and $0000FFFF);
  487. Result.Y:=SmallInt(XY shr 16);
  488. end;
  489. function MinPoint(const P1, P2: TPointF): TPointF; overload;
  490. begin
  491. Result:=P1;
  492. if (P2.Y<P1.Y)
  493. or ((P2.Y=P1.Y) and (P2.X<P1.X)) then
  494. Result:=P2;
  495. end;
  496. function MinPoint(const P1, P2: TPoint): TPoint; overload;
  497. begin
  498. Result:=P1;
  499. if (P2.Y<P1.Y)
  500. or ((P2.Y=P1.Y) and (P2.X<P1.X)) then
  501. Result:=P2;
  502. end;
  503. function ScalePoint(const P: TPointF; dX, dY: Single): TPointF; overload;
  504. begin
  505. Result.X:=P.X*dX;
  506. Result.Y:=P.Y*dY;
  507. end;
  508. function ScalePoint(const P: TPoint; dX, dY: Single): TPoint; overload;
  509. begin
  510. Result.X:=Round(P.X*dX);
  511. Result.Y:=Round(P.Y*dY);
  512. end;
  513. function NormalizeRectF(const Pts: array of TPointF): TRectF;
  514. var
  515. Pt: TPointF;
  516. begin
  517. Result.Left:=$FFFF;
  518. Result.Top:=$FFFF;
  519. Result.Right:=-$FFFF;
  520. Result.Bottom:=-$FFFF;
  521. for Pt in Pts do
  522. begin
  523. Result.Left:=Min(Pt.X,Result.left);
  524. Result.Top:=Min(Pt.Y,Result.Top);
  525. Result.Right:=Max(Pt.X,Result.Right);
  526. Result.Bottom:=Max(Pt.Y,Result.Bottom);
  527. end;
  528. end;
  529. function NormalizeRect(const aRect : TRectF): TRectF;
  530. begin
  531. With aRect do
  532. Result:=NormalizeRectF([PointF(Left,Top),
  533. PointF(Right,Top),
  534. PointF(Right,Bottom),
  535. PointF(Left,Bottom)]);
  536. end;
  537. function EqualRect(const r1,r2 : TRect) : Boolean;
  538. begin
  539. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  540. end;
  541. function EqualRect(const r1,r2 : TRectF) : Boolean;
  542. begin
  543. EqualRect:=r1.EqualsTo(r2);
  544. end;
  545. function Rect(Left,Top,Right,Bottom : Integer) : TRect; inline;
  546. begin
  547. Rect.Left:=Left;
  548. Rect.Top:=Top;
  549. Rect.Right:=Right;
  550. Rect.Bottom:=Bottom;
  551. end;
  552. function RectF(Left,Top,Right,Bottom : Single) : TRectF; inline;
  553. begin
  554. RectF.Left:=Left;
  555. RectF.Top:=Top;
  556. RectF.Right:=Right;
  557. RectF.Bottom:=Bottom;
  558. end;
  559. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect; inline;
  560. begin
  561. Bounds.Left:=ALeft;
  562. Bounds.Top:=ATop;
  563. Bounds.Right:=ALeft+AWidth;
  564. Bounds.Bottom:=ATop+AHeight;
  565. end;
  566. function Point(x,y : Integer) : TPoint; inline;
  567. begin
  568. Point.x:=x;
  569. Point.y:=y;
  570. end;
  571. function PointF(x,y: Single) : TPointF; inline;
  572. begin
  573. PointF.x:=x;
  574. PointF.y:=y;
  575. end;
  576. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  577. begin
  578. PtInRect:=(p.y>=Rect.Top) and
  579. (p.y<Rect.Bottom) and
  580. (p.x>=Rect.Left) and
  581. (p.x<Rect.Right);
  582. end;
  583. function PtInRect(const Rect : TRectF;const p : TPointF) : Boolean;
  584. begin
  585. PtInRect:=(p.y>=Rect.Top) and
  586. (p.y<Rect.Bottom) and
  587. (p.x>=Rect.Left) and
  588. (p.x<Rect.Right);
  589. end;
  590. function IntersectRectF(out Rect: TRectF; const R1, R2: TRectF): Boolean;
  591. begin
  592. Result:=IntersectRect(Rect,R1,R2);
  593. end;
  594. function UnionRectF(out Rect: TRectF; const R1, R2: TRectF): Boolean;
  595. begin
  596. Result:=UnionRect(Rect,R1,R2);
  597. end;
  598. function IntersectRect(const Rect1, Rect2: TRect): Boolean;
  599. begin
  600. Result:=(Rect1.Left<Rect2.Right)
  601. and (Rect1.Right>Rect2.Left)
  602. and (Rect1.Top<Rect2.Bottom)
  603. and (Rect1.Bottom>Rect2.Top);
  604. end;
  605. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  606. var
  607. lRect: TRect;
  608. begin
  609. lRect := R1;
  610. if R2.Left > R1.Left then
  611. lRect.Left := R2.Left;
  612. if R2.Top > R1.Top then
  613. lRect.Top := R2.Top;
  614. if R2.Right < R1.Right then
  615. lRect.Right := R2.Right;
  616. if R2.Bottom < R1.Bottom then
  617. lRect.Bottom := R2.Bottom;
  618. // The var parameter is only assigned in the end to avoid problems
  619. // when passing the same rectangle in the var and const parameters.
  620. // See http://bugs.freepascal.org/view.php?id=17722
  621. Result:=not IsRectEmpty(lRect);
  622. if Result then
  623. Rect := lRect
  624. else
  625. FillChar(Rect,SizeOf(Rect),0);
  626. end;
  627. function IntersectRect(const Rect1, Rect2: TRectF): Boolean;
  628. begin
  629. Result:=(Rect1.Left<Rect2.Right)
  630. and (Rect1.Right>Rect2.Left)
  631. and (Rect1.Top<Rect2.Bottom)
  632. and (Rect1.Bottom>Rect2.Top);
  633. end;
  634. function IntersectRect(var Rect : TRectF;const R1,R2 : TRectF) : Boolean;
  635. var
  636. lRect: TRectF;
  637. begin
  638. lRect := R1;
  639. if R2.Left > R1.Left then
  640. lRect.Left := R2.Left;
  641. if R2.Top > R1.Top then
  642. lRect.Top := R2.Top;
  643. if R2.Right < R1.Right then
  644. lRect.Right := R2.Right;
  645. if R2.Bottom < R1.Bottom then
  646. lRect.Bottom := R2.Bottom;
  647. // The var parameter is only assigned in the end to avoid problems
  648. // when passing the same rectangle in the var and const parameters.
  649. // See http://bugs.freepascal.org/view.php?id=17722
  650. Result:=not IsRectEmpty(lRect);
  651. if Result then
  652. Rect := lRect
  653. else
  654. FillChar(Rect,SizeOf(Rect),0);
  655. end;
  656. function SplitRect(const Rect: TRect; SplitType: TSplitRectType; Size: Integer): TRect; overload;
  657. begin
  658. Result:=Rect.SplitRect(SplitType,Size);
  659. end;
  660. function SplitRect(const Rect: TRect; SplitType: TSplitRectType; Percent: Double): TRect; overload;
  661. begin
  662. Result:=Rect.SplitRect(SplitType,Percent);
  663. end;
  664. function CenteredRect(const SourceRect: TRect; const aCenteredRect: TRect): TRect;
  665. var
  666. W,H: Integer;
  667. Center : TPoint;
  668. begin
  669. W:=aCenteredRect.Width;
  670. H:=aCenteredRect.Height;
  671. Center:=SourceRect.CenterPoint;
  672. With Center do
  673. Result:= Rect(X-(W div 2),Y-(H div 2),X+((W+1) div 2),Y+((H+1) div 2));
  674. end;
  675. function RectWidth(const Rect: TRect): Integer;
  676. begin
  677. Result:=Rect.Width;
  678. end;
  679. function RectWidth(const Rect: TRectF): Single;
  680. begin
  681. Result:=Rect.Width;
  682. end;
  683. function RectHeight(const Rect: TRect): Integer; inline;
  684. begin
  685. Result:=Rect.Height;
  686. end;
  687. function RectHeight(const Rect: TRectF): Single; inline;
  688. begin
  689. Result:=Rect.Height
  690. end;
  691. function RectCenter(var R: TRect; const Bounds: TRect): TRect;
  692. var
  693. C : TPoint;
  694. CS : TPoint;
  695. begin
  696. C:=Bounds.CenterPoint;
  697. CS:=R.CenterPoint;
  698. OffsetRect(R,C.X-CS.X,C.Y-CS.Y);
  699. Result:=R;
  700. end;
  701. function RectCenter(var R: TRectF; const Bounds: TRectF): TRectF;
  702. Var
  703. C,CS : TPointF;
  704. begin
  705. C:=Bounds.CenterPoint;
  706. CS:=R.CenterPoint;
  707. OffsetRect(R,C.X-CS.X,C.Y-CS.Y);
  708. Result:=R;
  709. end;
  710. procedure MultiplyRect(var R: TRectF; const DX, DY: Single);
  711. begin
  712. R.Left:=DX*R.Left;
  713. R.Right:=DX*R.Right;
  714. R.Top:=DY*R.Top;
  715. R.Bottom:=DY*R.Bottom;
  716. end;
  717. function UnionRect(const R1,R2 : TRect) : TRect;
  718. begin
  719. Result:=Default(TRect);
  720. UnionRect(Result,R1,R2);
  721. end;
  722. function UnionRect(const R1,R2 : TRectF) : TRectF;
  723. begin
  724. Result:=Default(TRectF);
  725. UnionRect(Result,R1,R2);
  726. end;
  727. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  728. var
  729. lRect: TRect;
  730. begin
  731. lRect:=R1;
  732. if R2.Left<R1.Left then
  733. lRect.Left:=R2.Left;
  734. if R2.Top<R1.Top then
  735. lRect.Top:=R2.Top;
  736. if R2.Right>R1.Right then
  737. lRect.Right:=R2.Right;
  738. if R2.Bottom>R1.Bottom then
  739. lRect.Bottom:=R2.Bottom;
  740. Result:=not IsRectEmpty(lRect);
  741. if Result then
  742. Rect := lRect
  743. else
  744. FillChar(Rect,SizeOf(Rect),0);
  745. end;
  746. function UnionRect(var Rect : TRectF;const R1,R2 : TRectF) : Boolean;
  747. var
  748. lRect: TRectF;
  749. begin
  750. lRect:=R1;
  751. if R2.Left<R1.Left then
  752. lRect.Left:=R2.Left;
  753. if R2.Top<R1.Top then
  754. lRect.Top:=R2.Top;
  755. if R2.Right>R1.Right then
  756. lRect.Right:=R2.Right;
  757. if R2.Bottom>R1.Bottom then
  758. lRect.Bottom:=R2.Bottom;
  759. Result:=not IsRectEmpty(lRect);
  760. if Result then
  761. Rect := lRect
  762. else
  763. FillChar(Rect,SizeOf(Rect),0);
  764. end;
  765. function IsRectEmpty(const Rect : TRect) : Boolean;
  766. begin
  767. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  768. end;
  769. function IsRectEmpty(const Rect : TRectF) : Boolean;
  770. begin
  771. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  772. end;
  773. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  774. begin
  775. Result:=assigned(@Rect);
  776. if Result then
  777. with Rect do
  778. begin
  779. inc(Left,dx);
  780. inc(Top,dy);
  781. inc(Right,dx);
  782. inc(Bottom,dy);
  783. end;
  784. end;
  785. function Avg(a, b: Longint): Longint;
  786. begin
  787. if a < b then
  788. Result := a + ((b - a) shr 1)
  789. else
  790. Result := b + ((a - b) shr 1);
  791. end;
  792. function OffsetRect(var Rect: TRectF; DX: Single; DY: Single): Boolean;
  793. begin
  794. Result:=assigned(@Rect);
  795. if Result then
  796. with Rect do
  797. begin
  798. Left:=Left+dx;
  799. Right:=Right+dx;
  800. Top:=Top+dy;
  801. Bottom:=Bottom+dy;
  802. end;
  803. end;
  804. function CenterPoint(const Rect: TRect): TPoint;
  805. begin
  806. with Rect do
  807. begin
  808. Result.X := Avg(Left, Right);
  809. Result.Y := Avg(Top, Bottom);
  810. end;
  811. end;
  812. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  813. begin
  814. Result:=assigned(@Rect);
  815. if Result then
  816. with Rect do
  817. begin
  818. dec(Left, dx);
  819. dec(Top, dy);
  820. inc(Right, dx);
  821. inc(Bottom, dy);
  822. end;
  823. end;
  824. function InflateRect(var Rect: TRectF; dx: Single; dy: Single): Boolean;
  825. begin
  826. Result:=assigned(@Rect);
  827. if Result then
  828. with Rect do
  829. begin
  830. Left:=Left-dx;
  831. Top:=Top-dy;
  832. Right:=Right+dx;
  833. Bottom:=Bottom+dy;
  834. end;
  835. end;
  836. function Size(AWidth, AHeight: Integer): TSize; inline;
  837. begin
  838. Result.cx := AWidth;
  839. Result.cy := AHeight;
  840. end;
  841. function Size(const ARect: TRect): TSize; inline;
  842. begin
  843. Result.cx := ARect.Right - ARect.Left;
  844. Result.cy := ARect.Bottom - ARect.Top;
  845. end;
  846. { TPointF}
  847. function TPointF.Add(const apt: TPoint): TPointF;
  848. begin
  849. result.x:=x+apt.x;
  850. result.y:=y+apt.y;
  851. end;
  852. function TPointF.Add(const apt: TPointF): TPointF;
  853. begin
  854. result.x:=x+apt.x;
  855. result.y:=y+apt.y;
  856. end;
  857. function TPointF.Subtract(const apt : TPointF): TPointF;
  858. begin
  859. result.x:=x-apt.x;
  860. result.y:=y-apt.y;
  861. end;
  862. function TPointF.Subtract(const apt: TPoint): TPointF;
  863. begin
  864. result.x:=x-apt.x;
  865. result.y:=y-apt.y;
  866. end;
  867. function TPointF.Distance(const apt : TPointF) : Single;
  868. begin
  869. result:=sqrt(sqr(apt.x-x)+sqr(apt.y-y));
  870. end;
  871. function TPointF.DotProduct(const apt: TPointF): Single;
  872. begin
  873. result:=x*apt.x+y*apt.y;
  874. end;
  875. function TPointF.IsZero : Boolean;
  876. begin
  877. result:=SameValue(x,0.0) and SameValue(y,0.0);
  878. end;
  879. procedure TPointF.Offset(const apt :TPointF);
  880. begin
  881. x:=x+apt.x;
  882. y:=y+apt.y;
  883. end;
  884. procedure TPointF.Offset(const apt: TPoint);
  885. begin
  886. x:=x+apt.x;
  887. y:=y+apt.y;
  888. end;
  889. procedure TPointF.Offset(dx,dy : Single);
  890. begin
  891. x:=x+dx;
  892. y:=y+dy;
  893. end;
  894. function TPointF.EqualsTo(const apt: TPointF; const aEpsilon: Single): Boolean;
  895. function Eq(a,b : single) : boolean; inline;
  896. begin
  897. result:=abs(a-b)<=aEpsilon;
  898. end;
  899. begin
  900. Result:=Eq(X,apt.X) and Eq(Y,apt.Y);
  901. end;
  902. function TPointF.Scale(afactor: Single): TPointF;
  903. begin
  904. result.x:=afactor*x;
  905. result.y:=afactor*y;
  906. end;
  907. function TPointF.Ceiling: TPoint;
  908. begin
  909. result.x:=ceil(x);
  910. result.y:=ceil(y);
  911. end;
  912. function TPointF.Truncate: TPoint;
  913. begin
  914. result.x:=trunc(x);
  915. result.y:=trunc(y);
  916. end;
  917. function TPointF.Floor: TPoint;
  918. begin
  919. result.x:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(x);
  920. result.y:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(y);
  921. end;
  922. function TPointF.Round: TPoint;
  923. begin
  924. result.x:=System.round(x);
  925. result.y:=System.round(y);
  926. end;
  927. function TPointF.Length: Single;
  928. begin
  929. result:=sqrt(sqr(x)+sqr(y));
  930. end;
  931. function TPointF.Rotate(angle: single): TPointF;
  932. var
  933. sina, cosa: single;
  934. begin
  935. sincos(angle, sina, cosa);
  936. result.x := x * cosa - y * sina;
  937. result.y := x * sina + y * cosa;
  938. end;
  939. function TPointF.Reflect(const normal: TPointF): TPointF;
  940. begin
  941. result := self + (-2 * normal ** self) * normal;
  942. end;
  943. function TPointF.MidPoint(const b: TPointF): TPointF;
  944. begin
  945. result.x := 0.5 * (x + b.x);
  946. result.y := 0.5 * (y + b.y);
  947. end;
  948. class function TPointF.Zero: TPointF;
  949. begin
  950. Result.X:=0;
  951. Result.Y:=0;
  952. end;
  953. class function TPointF.PointInCircle(const pt, center: TPointF; radius: single): Boolean;
  954. begin
  955. result := sqr(center.x - pt.x) + sqr(center.y - pt.y) < sqr(radius);
  956. end;
  957. class function TPointF.PointInCircle(const pt, center: TPointF; radius: integer): Boolean;
  958. begin
  959. result := sqr(center.x - pt.x) + sqr(center.y - pt.y) < sqr(single(radius));
  960. end;
  961. function TPointF.Angle(const b: TPointF): Single;
  962. begin
  963. result := ArcTan2(y - b.y, x - b.x);
  964. end;
  965. function TPointF.AngleCosine(const b: TPointF): single;
  966. begin
  967. result := EnsureRange((self ** b) / sqrt((sqr(x) + sqr(y)) * (sqr(b.x) + sqr(b.y))), -1, 1);
  968. end;
  969. class operator TPointF.= (const apt1, apt2 : TPointF) : Boolean;
  970. begin
  971. result:=SameValue(apt1.x,apt2.x) and SameValue(apt1.y,apt2.y);
  972. end;
  973. class operator TPointF.<> (const apt1, apt2 : TPointF): Boolean;
  974. begin
  975. result:=NOT (SameValue(apt1.x,apt2.x) and Samevalue(apt1.y,apt2.y));
  976. end;
  977. class operator TPointF. * (const apt1, apt2: TPointF): TPointF;
  978. begin
  979. result.x:=apt1.x*apt2.x;
  980. result.y:=apt1.y*apt2.y;
  981. end;
  982. class operator TPointF. * (afactor: single; const apt1: TPointF): TPointF;
  983. begin
  984. result:=apt1.Scale(afactor);
  985. end;
  986. class operator TPointF. * (const apt1: TPointF; afactor: single): TPointF;
  987. begin
  988. result:=apt1.Scale(afactor);
  989. end;
  990. class operator TPointF. ** (const apt1, apt2: TPointF): Single;
  991. begin
  992. result:=apt1.x*apt2.x + apt1.y*apt2.y;
  993. end;
  994. class operator TPointF.+ (const apt1, apt2 : TPointF): TPointF;
  995. begin
  996. result.x:=apt1.x+apt2.x;
  997. result.y:=apt1.y+apt2.y;
  998. end;
  999. class operator TPointF.- (const apt1, apt2 : TPointF): TPointF;
  1000. begin
  1001. result.x:=apt1.x-apt2.x;
  1002. result.y:=apt1.y-apt2.y;
  1003. end;
  1004. class operator TPointF. - (const apt1: TPointF): TPointF;
  1005. begin
  1006. Result.x:=-apt1.x;
  1007. Result.y:=-apt1.y;
  1008. end;
  1009. class operator TPointF. / (const apt1: TPointF; afactor: single): TPointF;
  1010. begin
  1011. result:=apt1.Scale(1/afactor);
  1012. end;
  1013. class operator TPointF. := (const apt: TPoint): TPointF;
  1014. begin
  1015. Result.x:=apt.x;
  1016. Result.y:=apt.y;
  1017. end;
  1018. procedure TPointF.SetLocation(const apt :TPointF);
  1019. begin
  1020. x:=apt.x; y:=apt.y;
  1021. end;
  1022. procedure TPointF.SetLocation(const apt: TPoint);
  1023. begin
  1024. x:=apt.x; y:=apt.y;
  1025. end;
  1026. procedure TPointF.SetLocation(ax,ay : Single);
  1027. begin
  1028. x:=ax; y:=ay;
  1029. end;
  1030. class function TPointF.Create(const ax, ay: Single): TPointF;
  1031. begin
  1032. Result.x := ax;
  1033. Result.y := ay;
  1034. end;
  1035. class function TPointF.Create(const apt: TPoint): TPointF;
  1036. begin
  1037. Result.x := apt.X;
  1038. Result.y := apt.Y;
  1039. end;
  1040. function TPointF.CrossProduct(const apt: TPointF): Single;
  1041. begin
  1042. Result:=X*apt.Y-Y*apt.X;
  1043. end;
  1044. function TPointF.Normalize: TPointF;
  1045. var
  1046. L: Single;
  1047. begin
  1048. L:=Sqrt(Sqr(X)+Sqr(Y));
  1049. if SameValue(L,0,Epsilon) then
  1050. Result:=Self
  1051. else
  1052. begin
  1053. Result.X:=X/L;
  1054. Result.Y:=Y/L;
  1055. end;
  1056. end;
  1057. { TSizeF }
  1058. function TSizeF.Add(const asz: TSize): TSizeF;
  1059. begin
  1060. result.cx:=cx+asz.cx;
  1061. result.cy:=cy+asz.cy;
  1062. end;
  1063. function TSizeF.Add(const asz: TSizeF): TSizeF;
  1064. begin
  1065. result.cx:=cx+asz.cx;
  1066. result.cy:=cy+asz.cy;
  1067. end;
  1068. function TSizeF.Subtract(const asz : TSizeF): TSizeF;
  1069. begin
  1070. result.cx:=cx-asz.cx;
  1071. result.cy:=cy-asz.cy;
  1072. end;
  1073. function TSizeF.SwapDimensions:TSizeF;
  1074. begin
  1075. result.cx:=cy;
  1076. result.cy:=cx;
  1077. end;
  1078. function TSizeF.Subtract(const asz: TSize): TSizeF;
  1079. begin
  1080. result.cx:=cx-asz.cx;
  1081. result.cy:=cy-asz.cy;
  1082. end;
  1083. function TSizeF.Distance(const asz : TSizeF) : Single;
  1084. begin
  1085. result:=sqrt(sqr(asz.cx-cx)+sqr(asz.cy-cy));
  1086. end;
  1087. function TSizeF.IsZero : Boolean;
  1088. begin
  1089. result:=SameValue(cx,0.0) and SameValue(cy,0.0);
  1090. end;
  1091. function TSizeF.Scale(afactor: Single): TSizeF;
  1092. begin
  1093. result.cx:=afactor*cx;
  1094. result.cy:=afactor*cy;
  1095. end;
  1096. function TSizeF.Ceiling: TSize;
  1097. begin
  1098. result.cx:=ceil(cx);
  1099. result.cy:=ceil(cy);
  1100. end;
  1101. function TSizeF.Truncate: TSize;
  1102. begin
  1103. result.cx:=trunc(cx);
  1104. result.cy:=trunc(cy);
  1105. end;
  1106. function TSizeF.Floor: TSize;
  1107. begin
  1108. result.cx:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(cx);
  1109. result.cy:={$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Math.floor(cy);
  1110. end;
  1111. function TSizeF.Round: TSize;
  1112. begin
  1113. result.cx:=System.round(cx);
  1114. result.cy:=System.round(cy);
  1115. end;
  1116. function TSizeF.Length: Single;
  1117. begin //distance(self) ?
  1118. result:=sqrt(sqr(cx)+sqr(cy));
  1119. end;
  1120. class operator TSizeF.= (const asz1, asz2 : TSizeF) : Boolean;
  1121. begin
  1122. result:=SameValue(asz1.cx,asz2.cx) and SameValue(asz1.cy,asz2.cy);
  1123. end;
  1124. class operator TSizeF.<> (const asz1, asz2 : TSizeF): Boolean;
  1125. begin
  1126. result:=NOT (SameValue(asz1.cx,asz2.cx) and Samevalue(asz1.cy,asz2.cy));
  1127. end;
  1128. class operator TSizeF. * (afactor: single; const asz1: TSizeF): TSizeF;
  1129. begin
  1130. result:=asz1.Scale(afactor);
  1131. end;
  1132. class operator TSizeF. * (const asz1: TSizeF; afactor: single): TSizeF;
  1133. begin
  1134. result:=asz1.Scale(afactor);
  1135. end;
  1136. class operator TSizeF.+ (const asz1, asz2 : TSizeF): TSizeF;
  1137. begin
  1138. result.cx:=asz1.cx+asz2.cx;
  1139. result.cy:=asz1.cy+asz2.cy;
  1140. end;
  1141. class operator TSizeF.- (const asz1, asz2 : TSizeF): TSizeF;
  1142. begin
  1143. result.cx:=asz1.cx-asz2.cx;
  1144. result.cy:=asz1.cy-asz2.cy;
  1145. end;
  1146. class operator TSizeF. - (const asz1: TSizeF): TSizeF;
  1147. begin
  1148. Result.cx:=-asz1.cx;
  1149. Result.cy:=-asz1.cy;
  1150. end;
  1151. class operator TSizeF. := (const apt: TPointF): TSizeF;
  1152. begin
  1153. Result.cx:=apt.x;
  1154. Result.cy:=apt.y;
  1155. end;
  1156. class operator TSizeF. := (const asz: TSize): TSizeF;
  1157. begin
  1158. Result.cx := asz.cx;
  1159. Result.cy := asz.cy;
  1160. end;
  1161. class operator TSizeF. := (const asz: TSizeF): TPointF;
  1162. begin
  1163. Result.x := asz.cx;
  1164. Result.y := asz.cy;
  1165. end;
  1166. class function TSizeF.Create(const ax, ay: Single): TSizeF;
  1167. begin
  1168. Result.cx := ax;
  1169. Result.cy := ay;
  1170. end;
  1171. class function TSizeF.Create(const asz: TSize): TSizeF;
  1172. begin
  1173. Result.cx := asz.cX;
  1174. Result.cy := asz.cY;
  1175. end;
  1176. { TRectF }
  1177. class operator TRectF. * (L, R: TRectF): TRectF;
  1178. begin
  1179. Result := TRectF.Intersect(L, R);
  1180. end;
  1181. class operator TRectF. + (L, R: TRectF): TRectF;
  1182. begin
  1183. Result := TRectF.Union(L, R);
  1184. end;
  1185. class operator TRectF. := (const arc: TRect): TRectF;
  1186. begin
  1187. Result.Left:=arc.Left;
  1188. Result.Top:=arc.Top;
  1189. Result.Right:=arc.Right;
  1190. Result.Bottom:=arc.Bottom;
  1191. end;
  1192. class operator TRectF. <> (L, R: TRectF): Boolean;
  1193. begin
  1194. Result := not(L=R);
  1195. end;
  1196. class operator TRectF. = (L, R: TRectF): Boolean;
  1197. begin
  1198. Result :=
  1199. SameValue(L.Left,R.Left) and SameValue(L.Right,R.Right) and
  1200. SameValue(L.Top,R.Top) and SameValue(L.Bottom,R.Bottom);
  1201. end;
  1202. constructor TRectF.Create(ALeft, ATop, ARight, ABottom: Single);
  1203. begin
  1204. Left := ALeft;
  1205. Top := ATop;
  1206. Right := ARight;
  1207. Bottom := ABottom;
  1208. end;
  1209. constructor TRectF.Create(P1, P2: TPointF; Normalize: Boolean);
  1210. begin
  1211. TopLeft := P1;
  1212. BottomRight := P2;
  1213. if Normalize then
  1214. NormalizeRect;
  1215. end;
  1216. constructor TRectF.Create(Origin: TPointF);
  1217. begin
  1218. TopLeft := Origin;
  1219. BottomRight := Origin;
  1220. end;
  1221. constructor TRectF.Create(Origin: TPointF; AWidth, AHeight: Single);
  1222. begin
  1223. TopLeft := Origin;
  1224. Width := AWidth;
  1225. Height := AHeight;
  1226. end;
  1227. constructor TRectF.Create(R: TRectF; Normalize: Boolean);
  1228. begin
  1229. Self := R;
  1230. if Normalize then
  1231. NormalizeRect;
  1232. end;
  1233. constructor TRectF.Create(R: TRect; Normalize: Boolean);
  1234. begin
  1235. Self := R;
  1236. if Normalize then
  1237. NormalizeRect;
  1238. end;
  1239. function TRectF.CenterPoint: TPointF;
  1240. begin
  1241. Result.X := (Right-Left) / 2 + Left;
  1242. Result.Y := (Bottom-Top) / 2 + Top;
  1243. end;
  1244. function TRectF.Ceiling: TRectF;
  1245. begin
  1246. Result.BottomRight:=BottomRight.Ceiling;
  1247. Result.TopLeft:=TopLeft.Ceiling;
  1248. end;
  1249. function TRectF.CenterAt(const Dest: TRectF): TRectF;
  1250. begin
  1251. Result:=Self;
  1252. RectCenter(Result,Dest);
  1253. end;
  1254. function TRectF.Fit(const Dest: TRectF): Single;
  1255. var
  1256. R : TRectF;
  1257. begin
  1258. R:=FitInto(Dest,Result);
  1259. Self:=R;
  1260. end;
  1261. function TRectF.FitInto(const Dest: TRectF; out Ratio: Single): TRectF;
  1262. begin
  1263. if (Dest.Width<=0) or (Dest.Height<=0) then
  1264. begin
  1265. Ratio:=1.0;
  1266. exit(Self);
  1267. end;
  1268. Ratio:=Max(Self.Width / Dest.Width, Self.Height / Dest.Height);
  1269. if Ratio=0 then
  1270. exit(Self);
  1271. Result.Width:=Self.Width / Ratio;
  1272. Result.Height:=Self.Height / Ratio;
  1273. Result.Left:=Self.Left + (Self.Width - Result.Width) / 2;
  1274. Result.Top:=Self.Top + (Self.Height - Result.Height) / 2;
  1275. end;
  1276. function TRectF.FitInto(const Dest: TRectF): TRectF;
  1277. var
  1278. Ratio: Single;
  1279. begin
  1280. Result:=FitInto(Dest,Ratio);
  1281. end;
  1282. function TRectF.PlaceInto(const Dest: TRectF; const AHorzAlign: THorzRectAlign = THorzRectAlign.Center; const AVertAlign: TVertRectAlign = TVertRectAlign.Center): TRectF;
  1283. var
  1284. R : TRectF;
  1285. X,Y : Single;
  1286. D : TRectF absolute dest;
  1287. begin
  1288. if (Height>Dest.Height) or (Width>Dest.Width) then
  1289. R:=FitInto(Dest)
  1290. else
  1291. R:=Self;
  1292. case AHorzAlign of
  1293. THorzRectAlign.Left:
  1294. X:=D.Left;
  1295. THorzRectAlign.Center:
  1296. X:=(D.Left+D.Right-R.Width)/2;
  1297. THorzRectAlign.Right:
  1298. X:=D.Right-R.Width;
  1299. end;
  1300. case AVertAlign of
  1301. TVertRectAlign.Top:
  1302. Y:=D.Top;
  1303. TVertRectAlign.Center:
  1304. Y:=(D.Top+D.Bottom-R.Height)/2;
  1305. TVertRectAlign.Bottom:
  1306. Y:=D.Bottom-R.Height;
  1307. end;
  1308. R.SetLocation(PointF(X,Y));
  1309. Result:=R;
  1310. end;
  1311. function TRectF.SnapToPixel(AScale: Single; APlaceBetweenPixels: Boolean): TRectF;
  1312. function sc (S : single) : single; inline;
  1313. begin
  1314. Result:=System.Trunc(S*AScale)/AScale;
  1315. end;
  1316. var
  1317. R : TRectF;
  1318. Off: Single;
  1319. begin
  1320. if AScale<=0 then
  1321. AScale := 1;
  1322. R.Top:=Sc(Top);
  1323. R.Left:=Sc(Left);
  1324. R.Width:=Sc(Width);
  1325. R.Height:=Sc(Height);
  1326. if APlaceBetweenPixels then
  1327. begin
  1328. Off:=1/(2*aScale);
  1329. R.Offset(Off,Off);
  1330. end;
  1331. Result:=R;
  1332. end;
  1333. function TRectF.Contains(Pt: TPointF): Boolean;
  1334. begin
  1335. Result := (Left <= Pt.X) and (Pt.X < Right) and (Top <= Pt.Y) and (Pt.Y < Bottom);
  1336. end;
  1337. function TRectF.Contains(R: TRectF): Boolean;
  1338. begin
  1339. Result := (Left <= R.Left) and (R.Right <= Right) and (Top <= R.Top) and (R.Bottom <= Bottom);
  1340. end;
  1341. class function TRectF.Empty: TRectF;
  1342. begin
  1343. Result := TRectF.Create(0,0,0,0);
  1344. end;
  1345. function TRectF.EqualsTo(const R: TRectF; const Epsilon: Single): Boolean;
  1346. begin
  1347. Result:=TopLeft.EqualsTo(R.TopLeft,Epsilon);
  1348. Result:=Result and BottomRight.EqualsTo(R.BottomRight,Epsilon);
  1349. end;
  1350. function TRectF.GetHeight: Single;
  1351. begin
  1352. result:=bottom-top;
  1353. end;
  1354. function TRectF.GetLocation: TPointF;
  1355. begin
  1356. result.x:=Left; result.y:=top;
  1357. end;
  1358. function TRectF.GetSize: TSizeF;
  1359. begin
  1360. result.cx:=width; result.cy:=height;
  1361. end;
  1362. function TRectF.GetWidth: Single;
  1363. begin
  1364. result:=right-left;
  1365. end;
  1366. procedure TRectF.Inflate(DX, DY: Single);
  1367. begin
  1368. Left:=Left-dx;
  1369. Top:=Top-dy;
  1370. Right:=Right+dx;
  1371. Bottom:=Bottom+dy;
  1372. end;
  1373. procedure TRectF.Intersect(R: TRectF);
  1374. begin
  1375. Self := Intersect(Self, R);
  1376. end;
  1377. class function TRectF.Intersect(R1: TRectF; R2: TRectF): TRectF;
  1378. begin
  1379. Result := R1;
  1380. if R2.Left > R1.Left then
  1381. Result.Left := R2.Left;
  1382. if R2.Top > R1.Top then
  1383. Result.Top := R2.Top;
  1384. if R2.Right < R1.Right then
  1385. Result.Right := R2.Right;
  1386. if R2.Bottom < R1.Bottom then
  1387. Result.Bottom := R2.Bottom;
  1388. end;
  1389. function TRectF.IntersectsWith(R: TRectF): Boolean;
  1390. begin
  1391. Result := (Left < R.Right) and (R.Left < Right) and (Top < R.Bottom) and (R.Top < Bottom);
  1392. end;
  1393. function TRectF.IsEmpty: Boolean;
  1394. begin
  1395. Result := (CompareValue(Right,Left)<=0) or (CompareValue(Bottom,Top)<=0);
  1396. end;
  1397. procedure TRectF.NormalizeRect;
  1398. var
  1399. x: Single;
  1400. begin
  1401. if Top>Bottom then
  1402. begin
  1403. x := Top;
  1404. Top := Bottom;
  1405. Bottom := x;
  1406. end;
  1407. if Left>Right then
  1408. begin
  1409. x := Left;
  1410. Left := Right;
  1411. Right := x;
  1412. end
  1413. end;
  1414. procedure TRectF.Inflate(DL, DT, DR, DB: Single);
  1415. begin
  1416. Left:=Left-dl;
  1417. Top:=Top-dt;
  1418. Right:=Right+dr;
  1419. Bottom:=Bottom+db;
  1420. end;
  1421. procedure TRectF.Offset(const dx, dy: Single);
  1422. begin
  1423. left:=left+dx; right:=right+dx;
  1424. bottom:=bottom+dy; top:=top+dy;
  1425. end;
  1426. procedure TRectF.Offset(DP: TPointF);
  1427. begin
  1428. left:=left+DP.x; right:=right+DP.x;
  1429. bottom:=bottom+DP.y; top:=top+DP.y;
  1430. end;
  1431. function TRectF.Truncate: TRect;
  1432. begin
  1433. Result.BottomRight:=BottomRight.Truncate;
  1434. Result.TopLeft:=TopLeft.Truncate;
  1435. end;
  1436. function TRectF.Round: TRect;
  1437. begin
  1438. Result.BottomRight:=BottomRight.Round;
  1439. Result.TopLeft:=TopLeft.Round;
  1440. end;
  1441. procedure TRectF.SetHeight(AValue: Single);
  1442. begin
  1443. bottom:=top+avalue;
  1444. end;
  1445. procedure TRectF.SetLocation(X, Y: Single);
  1446. begin
  1447. Offset(X-Left, Y-Top);
  1448. end;
  1449. procedure TRectF.SetLocation(P: TPointF);
  1450. begin
  1451. SetLocation(P.X, P.Y);
  1452. end;
  1453. procedure TRectF.SetSize(AValue: TSizeF);
  1454. begin
  1455. bottom:=top+avalue.cy;
  1456. right:=left+avalue.cx;
  1457. end;
  1458. procedure TRectF.SetWidth(AValue: Single);
  1459. begin
  1460. right:=left+avalue;
  1461. end;
  1462. class function TRectF.Union(const Points: array of TPointF): TRectF;
  1463. var
  1464. i: Integer;
  1465. begin
  1466. if Length(Points) > 0 then
  1467. begin
  1468. Result.TopLeft := Points[Low(Points)];
  1469. Result.BottomRight := Points[Low(Points)];
  1470. for i := Low(Points)+1 to High(Points) do
  1471. begin
  1472. if Points[i].X < Result.Left then Result.Left := Points[i].X;
  1473. if Points[i].X > Result.Right then Result.Right := Points[i].X;
  1474. if Points[i].Y < Result.Top then Result.Top := Points[i].Y;
  1475. if Points[i].Y > Result.Bottom then Result.Bottom := Points[i].Y;
  1476. end;
  1477. end else
  1478. Result := Empty;
  1479. end;
  1480. procedure TRectF.Union(const r: TRectF);
  1481. begin
  1482. left:=min(r.left,left);
  1483. top:=min(r.top,top);
  1484. right:=max(r.right,right);
  1485. bottom:=max(r.bottom,bottom);
  1486. end;
  1487. class function TRectF.Union(R1, R2: TRectF): TRectF;
  1488. begin
  1489. Result:=R1;
  1490. Result.Union(R2);
  1491. end;
  1492. { TPoint3D }
  1493. constructor TPoint3D.Create(const ax,ay,az:single);
  1494. begin
  1495. x:=ax; y:=ay; z:=az;
  1496. end;
  1497. procedure TPoint3D.Offset(const adeltax,adeltay,adeltaz:single);
  1498. begin
  1499. x:=x+adeltax; y:=y+adeltay; z:=z+adeltaz;
  1500. end;
  1501. procedure TPoint3D.Offset(const adelta:TPoint3D);
  1502. begin
  1503. x:=x+adelta.x; y:=y+adelta.y; z:=z+adelta.z;
  1504. end;
  1505. {$ifndef VER3_0}
  1506. generic class procedure TBitConverter.UnsafeFrom<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0);
  1507. begin
  1508. move(ASrcValue, ADestination[AOffset], SizeOf(T));
  1509. end;
  1510. generic class procedure TBitConverter.From<T>(const ASrcValue: T; var ADestination: Array of Byte; AOffset: Integer = 0);
  1511. begin
  1512. if AOffset < 0 then
  1513. System.Error(reRangeError);
  1514. if IsManagedType(T) then
  1515. System.Error(reInvalidCast);
  1516. if Length(ADestination) < (SizeOf(T) + AOffset) then
  1517. System.Error(reRangeError);
  1518. TBitConverter.specialize UnsafeFrom<T>(ASrcValue, ADestination, AOffset);
  1519. end;
  1520. generic class function TBitConverter.UnsafeInTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T;
  1521. begin
  1522. move(ASource[AOffset], Result, SizeOf(T));
  1523. end;
  1524. generic class function TBitConverter.InTo<T>(const ASource: Array of Byte; AOffset: Integer = 0): T;
  1525. begin
  1526. if AOffset < 0 then
  1527. System.Error(reRangeError);
  1528. if IsManagedType(T) then
  1529. System.Error(reInvalidCast);
  1530. if Length(ASource) < (SizeOf(T) + AOffset) then
  1531. System.Error(reRangeError);
  1532. Result := TBitConverter.specialize UnsafeInTo<T>(ASource, AOffset);
  1533. end;
  1534. {$endif}
  1535. end.