types.pp 33 KB

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