Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

521 lines
11 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: epointfl.hxx *
  3. * *
  4. * Energized point consisting of two floats. *
  5. * *
  6. * Created: 11-Jan-1991 13:30:27 *
  7. * Author: Bodin Dresevic [BodinD] *
  8. * *
  9. * Dependencies: *
  10. * *
  11. * Must include efloat.hxx for this file to compile. *
  12. * *
  13. * Copyright (c) 1990-1999 Microsoft Corporation *
  14. \**************************************************************************/
  15. /*********************************Class************************************\
  16. * class POINTFL
  17. *
  18. * point given with the floating point precision
  19. *
  20. *
  21. * History:
  22. * 11-Jan-1991 -by- Bodin Dresevic [BodinD]
  23. * Wrote it.
  24. \**************************************************************************/
  25. class POINTFL
  26. {
  27. public:
  28. EFLOAT x;
  29. EFLOAT y;
  30. };
  31. typedef POINTFL *PPOINTFL;
  32. class VECTORFL : public POINTFL {};
  33. typedef VECTORFL *PVECTORFL;
  34. /*********************************Class************************************\
  35. * class EPOINTFL :public POINTFL
  36. *
  37. * energized version of POINTFL, allows for subtracion, addition etc;
  38. *
  39. *
  40. * History:
  41. * 11-Jan-1991 -by- Bodin Dresevic [BodinD]
  42. * Wrote it.
  43. \**************************************************************************/
  44. class EPOINTFL;
  45. EFLOAT efDet(EPOINTFL& eptfl1,EPOINTFL& eptfl2); // determinant
  46. class EPOINTFL : public POINTFL // eptfl
  47. {
  48. public:
  49. // Constructor -- This one is to allow EPOINTFL inside other classes.
  50. EPOINTFL() {}
  51. // Several constructors -- Initializes EPOINTFL in various ways,
  52. // the assignment operator for EFLOAT is used
  53. EPOINTFL(LONG x1,LONG y1)
  54. {
  55. x = x1;
  56. y = y1;
  57. }
  58. // Constructor -- initializes EPOINTFL using two FLOAT's which is an
  59. // external (to the engine) type, (as oppossed to EFLOAT, which is
  60. // an internal type)
  61. EPOINTFL(FLOATL x1,FLOATL y1)
  62. {
  63. x = x1;
  64. y = y1;
  65. }
  66. // Constructor -- with internal type EFLOAT
  67. EPOINTFL(const EFLOAT& x1,const EFLOAT& y1)
  68. {
  69. x = x1;
  70. y = y1;
  71. }
  72. // Destructor -- Does nothing.
  73. ~EPOINTFL() {}
  74. // Operator= -- Create from a POINTL
  75. VOID operator=(POINTL& ptl)
  76. {
  77. x = ptl.x;
  78. y = ptl.y;
  79. }
  80. // Operator= -- Create from a POINTFIX
  81. VOID operator=(POINTFIX& ptfx)
  82. {
  83. x.vFxToEf(ptfx.x);
  84. y.vFxToEf(ptfx.y);
  85. }
  86. // Operator= -- Create from POINTE
  87. VOID operator=(POINTE& pte)
  88. {
  89. x = pte.x;
  90. y = pte.y;
  91. }
  92. // Operator+= -- Add in another EPOINTFL.
  93. VOID operator+=(EPOINTFL& eptfl)
  94. {
  95. x += eptfl.x;
  96. y += eptfl.y;
  97. }
  98. // Operator-= -- subtract another EPOINTFL.
  99. VOID operator-=(EPOINTFL& eptfl)
  100. {
  101. x -= eptfl.x;
  102. y -= eptfl.y;
  103. }
  104. // Operator*= -- multiply vector by a LONG number
  105. VOID operator*=(LONG l)
  106. {
  107. EFLOAT ef;
  108. ef = l;
  109. x *= ef;
  110. y *= ef;
  111. }
  112. // Operator*= -- multiply vector by an EFLOAT
  113. VOID operator*=(EFLOAT ef)
  114. {
  115. x *= ef;
  116. y *= ef;
  117. }
  118. // Multiply by a LONG.
  119. EPOINTFL& eqMul(EPOINTFL& ptfl,LONG l)
  120. {
  121. EFLOAT ef;
  122. ef = l;
  123. x.eqMul(ptfl.x,ef);
  124. y.eqMul(ptfl.y,ef);
  125. return(*this);
  126. }
  127. // Multiply by an EFLOAT.
  128. EPOINTFL& eqMul(EPOINTFL& ptfl,EFLOAT& ef)
  129. {
  130. x.eqMul(ptfl.x,ef);
  131. y.eqMul(ptfl.y,ef);
  132. return(*this);
  133. }
  134. // Divide by an EFLOAT.
  135. EPOINTFL& eqDiv(EPOINTFL& ptfl,EFLOAT& ef)
  136. {
  137. x.eqDiv(ptfl.x,ef);
  138. y.eqDiv(ptfl.y,ef);
  139. return(*this);
  140. }
  141. VOID operator/=(EFLOAT ef)
  142. {
  143. x /= ef;
  144. y /= ef;
  145. }
  146. // Divide by a LONG.
  147. EPOINTFL& eqDiv(EPOINTFL& ptfl,LONG l)
  148. {
  149. EFLOAT ef;
  150. ef = l;
  151. x.eqDiv(ptfl.x,ef);
  152. y.eqDiv(ptfl.y,ef);
  153. return(*this);
  154. }
  155. // bToPOINTL -- rounds the position to the "nearest" position on
  156. // the integer grid
  157. BOOL bToPOINTL(POINTL& ptl)
  158. {
  159. return(x.bEfToL(ptl.x) && y.bEfToL(ptl.y));
  160. }
  161. // bToPOINTFIX -- converts to the "nearest" position on
  162. // the FIX grid
  163. BOOL bToPOINTFIX(POINTFIX& ptfx)
  164. {
  165. return(x.bEfToFx(ptfx.x) && y.bEfToFx(ptfx.y));
  166. }
  167. // bIsZero() -- checks if This is a null vector
  168. BOOL bIsZero() { return(x.bIsZero() && y.bIsZero()); }
  169. // bBetween(eptfl1,eptfl2) -- checks whether this vector is between
  170. // eptfl1 and eptfl2. The caller must ensure
  171. // that det(eptfl2,eptfl1) >= 0, i.e. if the
  172. // vectors (1,2) are not collinear, they must form
  173. // a basis with right handed orientation.
  174. // Note: In windows we use left handed coords, so that det required to be
  175. // non-negative is det(2,1) rather than det(1,2)
  176. /*
  177. BOOL bBetween(EPOINTFL& eptfl1,EPOINTFL& eptfl2)
  178. {
  179. ASSERTGDI(!bIsZero(), "EPOINTFL::bBetween: this == (0,0)\n");
  180. ASSERTGDI(!eptfl1.bIsZero(), "EPOINTFL::bBetween: eptfl1 == (0,0)\n");
  181. ASSERTGDI(!eptfl2.bIsZero(), "EPOINTFL::bBetween: eptfl2 == (0,0)\n");
  182. EFLOAT efDet21 = efDet(eptfl2, eptfl1);
  183. EFLOAT efDet2This = efDet(eptfl2, *this);
  184. ASSERTGDI(!efDet21.bIsNegative(), "EPOINTFL::bBetween: orientation\n");
  185. if (efDet21.bIsZero() && !(eptfl1 * eptfl2).bIsNegative())
  186. {
  187. // vectors 1 and 2 are colinear AND point in the same direction
  188. if (efDet2This.bIsZero() && !((*this) * eptfl2).bIsNegative())
  189. {
  190. // This is also colinear with 1 and 2 and points in
  191. // the SAME direction as 1 and 2
  192. return(TRUE); // ------->1 , -------->2, -------> this
  193. }
  194. else
  195. {
  196. // This is either NOT colinear with 1 and 2, OR
  197. // This is colinear with 1 and 2 but points opposite from 1 and 2
  198. return(FALSE); // ------->1 , -------->2, <------- this
  199. }
  200. }
  201. else
  202. {
  203. // vectors 1 and 2 are either NOT colinear OR
  204. // are colinear and point in OPPOSITE directions
  205. EFLOAT efDetThis1 = efDet(*this,eptfl1); // must compute it now
  206. if (!efDet2This.bIsNegative() && !efDetThis1.bIsNegative())
  207. return(TRUE); // This lies between 1 and 2
  208. else
  209. return(FALSE);
  210. }
  211. }
  212. */
  213. // vSetToZero -- make the null vetor
  214. VOID vSetToZero()
  215. {
  216. x.vSetToZero();
  217. y.vSetToZero();
  218. }
  219. };
  220. typedef EPOINTFL *PEPOINTFL;
  221. /*********************************Class************************************\
  222. * class EVECTORFL : public EPOINTFL
  223. *
  224. * Energized class for VECTORFL.
  225. *
  226. * History:
  227. * 27-Jan-1992 -by- Wendy Wu [wendywu]
  228. * Wrote it.
  229. \**************************************************************************/
  230. class EVECTORFL : public EPOINTFL
  231. {
  232. public:
  233. // Constructor -- This one is to allow EVECTORFL inside other classes.
  234. EVECTORFL() {}
  235. // Several constructors -- Initializes EVECTORFL in various ways,
  236. // the assignment operator for EFLOAT is used
  237. EVECTORFL(EVECTORFL& evfl)
  238. {
  239. x = evfl.x;
  240. y = evfl.y;
  241. }
  242. EVECTORFL(LONG x1,LONG y1)
  243. {
  244. x = x1;
  245. y = y1;
  246. }
  247. EVECTORFL(EPOINTFL& eptfl)
  248. {
  249. x = eptfl.x;
  250. y = eptfl.y;
  251. }
  252. VOID operator=(POINTL& ptl)
  253. {
  254. x = ptl.x;
  255. y = ptl.y;
  256. }
  257. VOID operator=(POINTE& pte)
  258. {
  259. x = pte.x;
  260. y = pte.y;
  261. }
  262. VOID operator=(EPOINTFL& eptfl)
  263. {
  264. x = eptfl.x;
  265. y = eptfl.y;
  266. }
  267. VOID operator=(EVECTORFL& evfl)
  268. {
  269. x = evfl.x;
  270. y = evfl.y;
  271. }
  272. VOID operator=(VECTORFL& vfl)
  273. {
  274. x = vfl.x;
  275. y = vfl.y;
  276. }
  277. };
  278. /*********************************Class************************************\
  279. * class RECTFL
  280. *
  281. * similar to RECTL, rectangle given with EFLOAT precision
  282. *
  283. * History:
  284. * 04-Mar-1991 -by- Bodin Dresevic [BodinD]
  285. * Wrote it.
  286. \**************************************************************************/
  287. class RECTFL
  288. {
  289. public:
  290. EFLOAT xLeft;
  291. EFLOAT yTop;
  292. EFLOAT xRight;
  293. EFLOAT yBottom;
  294. };
  295. typedef RECTFL *PRECTFL;
  296. /*********************************Class************************************\
  297. * class ERECTFL:public RECTFL
  298. *
  299. * similar to ERECTL, code stolen, based on EFLOAT
  300. *
  301. * History:
  302. * 04-Mar-1991 -by- Bodin Dresevic [BodinD]
  303. * Wrote it.
  304. \**************************************************************************/
  305. class ERECTFL:public RECTFL // ercfl
  306. {
  307. public:
  308. // Constructor -- Allows ERECTFLs inside other classes.
  309. ERECTFL() {}
  310. // Constructor -- Initialize the rectangle.
  311. ERECTFL(LONG x1,LONG y1,LONG x2,LONG y2)
  312. {
  313. xLeft = x1;
  314. yTop = y1;
  315. xRight = x2;
  316. yBottom = y2;
  317. }
  318. // Constructor -- Initialize the rectangle.
  319. ERECTFL(EFLOAT& x1,EFLOAT& y1,EFLOAT& x2,EFLOAT& y2)
  320. {
  321. xLeft = x1;
  322. yTop = y1;
  323. xRight = x2;
  324. yBottom = y2;
  325. }
  326. // Destructor -- Does nothing.
  327. ~ERECTFL() {}
  328. /*
  329. // Constructor -- energize given rectangle so that it can be manipulated
  330. ERECTFL(RECTFL& rcfl)
  331. {
  332. xLeft = rcfl.xLeft ;
  333. yTop = rcfl.yTop ;
  334. xRight = rcfl.xRight ;
  335. yBottom = rcfl.yBottom ;
  336. }
  337. */
  338. // Operator+= -- Offset the ERECTFL.
  339. VOID operator+=(POINTFL& ptfl)
  340. {
  341. xLeft += ptfl.x;
  342. xRight += ptfl.x;
  343. yTop += ptfl.y;
  344. yBottom += ptfl.y;
  345. }
  346. // Operator-= -- Offset the ERECTFL.
  347. VOID operator-=(POINTFL& ptfl)
  348. {
  349. xLeft -= ptfl.x;
  350. xRight -= ptfl.x;
  351. yTop -= ptfl.y;
  352. yBottom -= ptfl.y;
  353. }
  354. // Operator+= -- Add another RECTFL. Only the destination may be empty.
  355. VOID operator+=(RECTFL& rcfl)
  356. {
  357. if ((xLeft == xRight) || (yTop == yBottom))
  358. *((RECTFL *) this) = rcfl;
  359. else
  360. {
  361. if (rcfl.xLeft <= xLeft)
  362. xLeft = rcfl.xLeft;
  363. if (rcfl.yTop <= yTop)
  364. yTop = rcfl.yTop;
  365. if (rcfl.xRight > xRight)
  366. xRight = rcfl.xRight;
  367. if (rcfl.yBottom > yBottom)
  368. yBottom = rcfl.yBottom;
  369. }
  370. }
  371. // Operator*= -- Intersect another RECTFL. The result may be empty.
  372. ERECTFL& operator*= (RECTFL& rcfl)
  373. {
  374. {
  375. if (rcfl.xLeft > xLeft)
  376. xLeft = rcfl.xLeft;
  377. if (rcfl.yTop > yTop)
  378. yTop = rcfl.yTop;
  379. if (rcfl.xRight <= xRight)
  380. xRight = rcfl.xRight;
  381. if (rcfl.yBottom <= yBottom)
  382. yBottom = rcfl.yBottom;
  383. if (xRight <= xLeft)
  384. xLeft = xRight; // Only need to collapse one pair
  385. else
  386. if (yBottom <= yTop)
  387. yTop = yBottom;
  388. }
  389. return(*this);
  390. }
  391. // vOrder -- Make the rectangle well ordered.
  392. VOID vOrder()
  393. {
  394. EFLOAT ef;
  395. if (xLeft > xRight)
  396. {
  397. ef = xLeft;
  398. xLeft = xRight;
  399. xRight = ef;
  400. }
  401. if (yTop > yBottom)
  402. {
  403. ef = yTop;
  404. yTop = yBottom;
  405. yBottom = ef;
  406. }
  407. }
  408. };
  409. typedef ERECTFL *PERECTFL;