types.pp 36 KB

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