types.pp 47 KB

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