MinimumAreaBox2.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/OrientedBox.h>
  9. #include <Mathematics/ConvexHull2.h>
  10. // Compute a minimum-area oriented box containing the specified points. The
  11. // algorithm uses the rotating calipers method.
  12. // http://www-cgrl.cs.mcgill.ca/~godfried/research/calipers.html
  13. // http://cgm.cs.mcgill.ca/~orm/rotcal.html
  14. // The box is supported by the convex hull of the points, so the algorithm
  15. // is really about computing the minimum-area box containing a convex polygon.
  16. // The rotating calipers approach is O(n) in time for n polygon edges.
  17. //
  18. // A detailed description of the algorithm and implementation is found in
  19. // https://www.geometrictools.com/Documentation/MinimumAreaRectangle.pdf
  20. //
  21. // NOTE: This algorithm guarantees a correct output only when ComputeType is
  22. // an exact arithmetic type that supports division. In GTEngine, one such
  23. // type is BSRational<UIntegerAP32> (arbitrary precision). Another such type
  24. // is BSRational<UIntegerFP32<N>> (fixed precision), where N is chosen large
  25. // enough for your input data sets. If you choose ComputeType to be 'float'
  26. // or 'double', the output is not guaranteed to be correct.
  27. //
  28. // See GeometricTools/GTEngine/Samples/Geometrics/MinimumAreaBox2 for an
  29. // example of how to use the code.
  30. namespace WwiseGTE
  31. {
  32. template <typename InputType, typename ComputeType>
  33. class MinimumAreaBox2
  34. {
  35. public:
  36. // The class is a functor to support computing the minimum-area box of
  37. // multiple data sets using the same class object.
  38. MinimumAreaBox2()
  39. :
  40. mNumPoints(0),
  41. mPoints(nullptr),
  42. mSupportIndices{ 0, 0, 0, 0 },
  43. mArea((InputType)0),
  44. mZero(0),
  45. mOne(1),
  46. mNegOne(-1),
  47. mHalf((InputType)0.5)
  48. {
  49. }
  50. // The points are arbitrary, so we must compute the convex hull from
  51. // them in order to compute the minimum-area box. The input
  52. // parameters are necessary for using ConvexHull2. NOTE: ConvexHull2
  53. // guarantees that the hull does not have three consecutive collinear
  54. // points.
  55. OrientedBox2<InputType> operator()(int numPoints,
  56. Vector2<InputType> const* points,
  57. bool useRotatingCalipers = !std::is_floating_point<ComputeType>::value)
  58. {
  59. mNumPoints = numPoints;
  60. mPoints = points;
  61. mHull.clear();
  62. // Get the convex hull of the points.
  63. ConvexHull2<InputType, ComputeType> ch2;
  64. ch2(mNumPoints, mPoints, (InputType)0);
  65. int dimension = ch2.GetDimension();
  66. OrientedBox2<InputType> minBox;
  67. if (dimension == 0)
  68. {
  69. // The points are all effectively the same (using fuzzy
  70. // epsilon).
  71. minBox.center = mPoints[0];
  72. minBox.axis[0] = Vector2<InputType>::Unit(0);
  73. minBox.axis[1] = Vector2<InputType>::Unit(1);
  74. minBox.extent[0] = (InputType)0;
  75. minBox.extent[1] = (InputType)0;
  76. mHull.resize(1);
  77. mHull[0] = 0;
  78. return minBox;
  79. }
  80. if (dimension == 1)
  81. {
  82. // The points effectively lie on a line (using fuzzy epsilon).
  83. // Determine the extreme t-values for the points represented
  84. // as P = origin + t*direction. We know that 'origin' is an
  85. // input vertex, so we can start both t-extremes at zero.
  86. Line2<InputType> const& line = ch2.GetLine();
  87. InputType tmin = (InputType)0, tmax = (InputType)0;
  88. int imin = 0, imax = 0;
  89. for (int i = 0; i < mNumPoints; ++i)
  90. {
  91. Vector2<InputType> diff = mPoints[i] - line.origin;
  92. InputType t = Dot(diff, line.direction);
  93. if (t > tmax)
  94. {
  95. tmax = t;
  96. imax = i;
  97. }
  98. else if (t < tmin)
  99. {
  100. tmin = t;
  101. imin = i;
  102. }
  103. }
  104. minBox.center = line.origin + (InputType)0.5 * (tmin + tmax) * line.direction;
  105. minBox.extent[0] = (InputType)0.5 * (tmax - tmin);
  106. minBox.extent[1] = (InputType)0;
  107. minBox.axis[0] = line.direction;
  108. minBox.axis[1] = -Perp(line.direction);
  109. mHull.resize(2);
  110. mHull[0] = imin;
  111. mHull[1] = imax;
  112. return minBox;
  113. }
  114. mHull = ch2.GetHull();
  115. Vector2<ComputeType> const* queryPoints = ch2.GetQuery().GetVertices();
  116. std::vector<Vector2<ComputeType>> computePoints(mHull.size());
  117. for (size_t i = 0; i < mHull.size(); ++i)
  118. {
  119. computePoints[i] = queryPoints[mHull[i]];
  120. }
  121. RemoveCollinearPoints(computePoints);
  122. Box box;
  123. if (useRotatingCalipers)
  124. {
  125. box = ComputeBoxForEdgeOrderN(computePoints);
  126. }
  127. else
  128. {
  129. box = ComputeBoxForEdgeOrderNSqr(computePoints);
  130. }
  131. ConvertTo(box, computePoints, minBox);
  132. return minBox;
  133. }
  134. // The points already form a counterclockwise, nondegenerate convex
  135. // polygon. If the points directly are the convex polygon, set
  136. // numIndices to 0 and indices to nullptr. If the polygon vertices
  137. // are a subset of the incoming points, that subset is identified by
  138. // numIndices >= 3 and indices having numIndices elements.
  139. OrientedBox2<InputType> operator()(int numPoints,
  140. Vector2<InputType> const* points, int numIndices, int const* indices,
  141. bool useRotatingCalipers = !std::is_floating_point<ComputeType>::value)
  142. {
  143. mHull.clear();
  144. OrientedBox2<InputType> minBox;
  145. if (numPoints < 3 || !points || (indices && numIndices < 3))
  146. {
  147. minBox.center = Vector2<InputType>::Zero();
  148. minBox.axis[0] = Vector2<InputType>::Unit(0);
  149. minBox.axis[1] = Vector2<InputType>::Unit(1);
  150. minBox.extent = Vector2<InputType>::Zero();
  151. return minBox;
  152. }
  153. if (indices)
  154. {
  155. mHull.resize(numIndices);
  156. std::copy(indices, indices + numIndices, mHull.begin());
  157. }
  158. else
  159. {
  160. numIndices = numPoints;
  161. mHull.resize(numIndices);
  162. for (int i = 0; i < numIndices; ++i)
  163. {
  164. mHull[i] = i;
  165. }
  166. }
  167. std::vector<Vector2<ComputeType>> computePoints(numIndices);
  168. for (int i = 0; i < numIndices; ++i)
  169. {
  170. int h = mHull[i];
  171. computePoints[i][0] = (ComputeType)points[h][0];
  172. computePoints[i][1] = (ComputeType)points[h][1];
  173. }
  174. RemoveCollinearPoints(computePoints);
  175. Box box;
  176. if (useRotatingCalipers)
  177. {
  178. box = ComputeBoxForEdgeOrderN(computePoints);
  179. }
  180. else
  181. {
  182. box = ComputeBoxForEdgeOrderNSqr(computePoints);
  183. }
  184. ConvertTo(box, computePoints, minBox);
  185. return minBox;
  186. }
  187. // Member access.
  188. inline int GetNumPoints() const
  189. {
  190. return mNumPoints;
  191. }
  192. inline Vector2<InputType> const* GetPoints() const
  193. {
  194. return mPoints;
  195. }
  196. inline std::vector<int> const& GetHull() const
  197. {
  198. return mHull;
  199. }
  200. inline std::array<int, 4> const& GetSupportIndices() const
  201. {
  202. return mSupportIndices;
  203. }
  204. inline InputType GetArea() const
  205. {
  206. return mArea;
  207. }
  208. private:
  209. // The box axes are U[i] and are usually not unit-length in order to
  210. // allow exact arithmetic. The box is supported by mPoints[index[i]],
  211. // where i is one of the enumerations above. The box axes are not
  212. // necessarily unit length, but they have the same length. They need
  213. // to be normalized for conversion back to InputType.
  214. struct Box
  215. {
  216. Vector2<ComputeType> U[2];
  217. std::array<int, 4> index; // order: bottom, right, top, left
  218. ComputeType sqrLenU0, area;
  219. };
  220. // The rotating calipers algorithm has a loop invariant that requires
  221. // the convex polygon not to have collinear points. Any such points
  222. // must be removed first. The code is also executed for the O(n^2)
  223. // algorithm to reduce the number of process edges.
  224. void RemoveCollinearPoints(std::vector<Vector2<ComputeType>>& vertices)
  225. {
  226. std::vector<Vector2<ComputeType>> tmpVertices = vertices;
  227. int const numVertices = static_cast<int>(vertices.size());
  228. int numNoncollinear = 0;
  229. Vector2<ComputeType> ePrev = tmpVertices[0] - tmpVertices.back();
  230. for (int i0 = 0, i1 = 1; i0 < numVertices; ++i0)
  231. {
  232. Vector2<ComputeType> eNext = tmpVertices[i1] - tmpVertices[i0];
  233. ComputeType dp = DotPerp(ePrev, eNext);
  234. if (dp != mZero)
  235. {
  236. vertices[numNoncollinear++] = tmpVertices[i0];
  237. }
  238. ePrev = eNext;
  239. if (++i1 == numVertices)
  240. {
  241. i1 = 0;
  242. }
  243. }
  244. vertices.resize(numNoncollinear);
  245. }
  246. // This is the slow O(n^2) search.
  247. Box ComputeBoxForEdgeOrderNSqr(std::vector<Vector2<ComputeType>> const& vertices)
  248. {
  249. Box minBox;
  250. minBox.area = mNegOne;
  251. int const numIndices = static_cast<int>(vertices.size());
  252. for (int i0 = numIndices - 1, i1 = 0; i1 < numIndices; i0 = i1++)
  253. {
  254. Box box = SmallestBox(i0, i1, vertices);
  255. if (minBox.area == mNegOne || box.area < minBox.area)
  256. {
  257. minBox = box;
  258. }
  259. }
  260. return minBox;
  261. }
  262. // The fast O(n) search.
  263. Box ComputeBoxForEdgeOrderN(std::vector<Vector2<ComputeType>> const& vertices)
  264. {
  265. // The inputs are assumed to be the vertices of a convex polygon
  266. // that is counterclockwise ordered. The input points must not
  267. // contain three consecutive collinear points.
  268. // When the bounding box corresponding to a polygon edge is
  269. // computed, we mark the edge as visited. If the edge is
  270. // encountered later, the algorithm terminates.
  271. std::vector<bool> visited(vertices.size());
  272. std::fill(visited.begin(), visited.end(), false);
  273. // Start the minimum-area rectangle search with the edge from the
  274. // last polygon vertex to the first. When updating the extremes,
  275. // we want the bottom-most point on the left edge, the top-most
  276. // point on the right edge, the left-most point on the top edge,
  277. // and the right-most point on the bottom edge. The polygon edges
  278. // starting at these points are then guaranteed not to coincide
  279. // with a box edge except when an extreme point is shared by two
  280. // box edges (at a corner).
  281. Box minBox = SmallestBox((int)vertices.size() - 1, 0, vertices);
  282. visited[minBox.index[0]] = true;
  283. // Execute the rotating calipers algorithm.
  284. Box box = minBox;
  285. for (size_t i = 0; i < vertices.size(); ++i)
  286. {
  287. std::array<std::pair<ComputeType, int>, 4> A;
  288. int numA;
  289. if (!ComputeAngles(vertices, box, A, numA))
  290. {
  291. // The polygon is a rectangle, so the search is over.
  292. break;
  293. }
  294. // Indirectly sort the A-array.
  295. std::array<int, 4> sort = SortAngles(A, numA);
  296. // Update the supporting indices (box.index[]) and the box
  297. // axis directions (box.U[]).
  298. if (!UpdateSupport(A, numA, sort, vertices, visited, box))
  299. {
  300. // We have already processed the box polygon edge, so the
  301. // search is over.
  302. break;
  303. }
  304. if (box.area < minBox.area)
  305. {
  306. minBox = box;
  307. }
  308. }
  309. return minBox;
  310. }
  311. // Compute the smallest box for the polygon edge <V[i0],V[i1]>.
  312. Box SmallestBox(int i0, int i1, std::vector<Vector2<ComputeType>> const& vertices)
  313. {
  314. Box box;
  315. box.U[0] = vertices[i1] - vertices[i0];
  316. box.U[1] = -Perp(box.U[0]);
  317. box.index = { i1, i1, i1, i1 };
  318. box.sqrLenU0 = Dot(box.U[0], box.U[0]);
  319. Vector2<ComputeType> const& origin = vertices[i1];
  320. Vector2<ComputeType> support[4];
  321. for (int j = 0; j < 4; ++j)
  322. {
  323. support[j] = { mZero, mZero };
  324. }
  325. int i = 0;
  326. for (auto const& vertex : vertices)
  327. {
  328. Vector2<ComputeType> diff = vertex - origin;
  329. Vector2<ComputeType> v = { Dot(box.U[0], diff), Dot(box.U[1], diff) };
  330. // The right-most vertex of the bottom edge is vertices[i1].
  331. // The assumption of no triple of collinear vertices
  332. // guarantees that box.index[0] is i1, which is the initial
  333. // value assigned at the beginning of this function.
  334. // Therefore, there is no need to test for other vertices
  335. // farther to the right than vertices[i1].
  336. if (v[0] > support[1][0] ||
  337. (v[0] == support[1][0] && v[1] > support[1][1]))
  338. {
  339. // New right maximum OR same right maximum but closer
  340. // to top.
  341. box.index[1] = i;
  342. support[1] = v;
  343. }
  344. if (v[1] > support[2][1] ||
  345. (v[1] == support[2][1] && v[0] < support[2][0]))
  346. {
  347. // New top maximum OR same top maximum but closer
  348. // to left.
  349. box.index[2] = i;
  350. support[2] = v;
  351. }
  352. if (v[0] < support[3][0] ||
  353. (v[0] == support[3][0] && v[1] < support[3][1]))
  354. {
  355. // New left minimum OR same left minimum but closer
  356. // to bottom.
  357. box.index[3] = i;
  358. support[3] = v;
  359. }
  360. ++i;
  361. }
  362. // The comment in the loop has the implication that
  363. // support[0] = { 0, 0 }, so the scaled height
  364. // (support[2][1] - support[0][1]) is simply support[2][1].
  365. ComputeType scaledWidth = support[1][0] - support[3][0];
  366. ComputeType scaledHeight = support[2][1];
  367. box.area = scaledWidth * scaledHeight / box.sqrLenU0;
  368. return box;
  369. }
  370. // Compute (sin(angle))^2 for the polygon edges emanating from the
  371. // support vertices of the box. The return value is 'true' if at
  372. // least one angle is in [0,pi/2); otherwise, the return value is
  373. // 'false' and the original polygon must be a rectangle.
  374. bool ComputeAngles(std::vector<Vector2<ComputeType>> const& vertices,
  375. Box const& box, std::array<std::pair<ComputeType, int>, 4>& A, int& numA) const
  376. {
  377. int const numVertices = static_cast<int>(vertices.size());
  378. numA = 0;
  379. for (int k0 = 3, k1 = 0; k1 < 4; k0 = k1++)
  380. {
  381. if (box.index[k0] != box.index[k1])
  382. {
  383. // The box edges are ordered in k1 as U[0], U[1],
  384. // -U[0], -U[1].
  385. Vector2<ComputeType> D = ((k0 & 2) ? -box.U[k0 & 1] : box.U[k0 & 1]);
  386. int j0 = box.index[k0], j1 = j0 + 1;
  387. if (j1 == numVertices)
  388. {
  389. j1 = 0;
  390. }
  391. Vector2<ComputeType> E = vertices[j1] - vertices[j0];
  392. ComputeType dp = DotPerp(D, E);
  393. ComputeType esqrlen = Dot(E, E);
  394. ComputeType sinThetaSqr = (dp * dp) / esqrlen;
  395. A[numA++] = std::make_pair(sinThetaSqr, k0);
  396. }
  397. }
  398. return numA > 0;
  399. }
  400. // Sort the angles indirectly. The sorted indices are returned.
  401. // This avoids swapping elements of A[], which can be expensive when
  402. // ComputeType is an exact rational type.
  403. std::array<int, 4> SortAngles(std::array<std::pair<ComputeType, int>, 4> const& A, int numA) const
  404. {
  405. std::array<int, 4> sort = { 0, 1, 2, 3 };
  406. if (numA > 1)
  407. {
  408. if (numA == 2)
  409. {
  410. if (A[sort[0]].first > A[sort[1]].first)
  411. {
  412. std::swap(sort[0], sort[1]);
  413. }
  414. }
  415. else if (numA == 3)
  416. {
  417. if (A[sort[0]].first > A[sort[1]].first)
  418. {
  419. std::swap(sort[0], sort[1]);
  420. }
  421. if (A[sort[0]].first > A[sort[2]].first)
  422. {
  423. std::swap(sort[0], sort[2]);
  424. }
  425. if (A[sort[1]].first > A[sort[2]].first)
  426. {
  427. std::swap(sort[1], sort[2]);
  428. }
  429. }
  430. else // numA == 4
  431. {
  432. if (A[sort[0]].first > A[sort[1]].first)
  433. {
  434. std::swap(sort[0], sort[1]);
  435. }
  436. if (A[sort[2]].first > A[sort[3]].first)
  437. {
  438. std::swap(sort[2], sort[3]);
  439. }
  440. if (A[sort[0]].first > A[sort[2]].first)
  441. {
  442. std::swap(sort[0], sort[2]);
  443. }
  444. if (A[sort[1]].first > A[sort[3]].first)
  445. {
  446. std::swap(sort[1], sort[3]);
  447. }
  448. if (A[sort[1]].first > A[sort[2]].first)
  449. {
  450. std::swap(sort[1], sort[2]);
  451. }
  452. }
  453. }
  454. return sort;
  455. }
  456. bool UpdateSupport(std::array<std::pair<ComputeType, int>, 4> const& A,
  457. int numA, std::array<int, 4> const& sort,
  458. std::vector<Vector2<ComputeType>> const& vertices,
  459. std::vector<bool>& visited, Box& box)
  460. {
  461. // Replace the support vertices of those edges attaining minimum
  462. // angle with the other endpoints of the edges.
  463. int const numVertices = static_cast<int>(vertices.size());
  464. auto const& amin = A[sort[0]];
  465. for (int k = 0; k < numA; ++k)
  466. {
  467. auto const& a = A[sort[k]];
  468. if (a.first == amin.first)
  469. {
  470. if (++box.index[a.second] == numVertices)
  471. {
  472. box.index[a.second] = 0;
  473. }
  474. }
  475. else
  476. {
  477. break;
  478. }
  479. }
  480. int bottom = box.index[amin.second];
  481. if (visited[bottom])
  482. {
  483. // We have already processed this polygon edge.
  484. return false;
  485. }
  486. visited[bottom] = true;
  487. // Cycle the vertices so that the bottom support occurs first.
  488. std::array<int, 4> nextIndex;
  489. for (int k = 0; k < 4; ++k)
  490. {
  491. nextIndex[k] = box.index[(amin.second + k) % 4];
  492. }
  493. box.index = nextIndex;
  494. // Compute the box axis directions.
  495. int j1 = box.index[0], j0 = j1 - 1;
  496. if (j0 < 0)
  497. {
  498. j0 = numVertices - 1;
  499. }
  500. box.U[0] = vertices[j1] - vertices[j0];
  501. box.U[1] = -Perp(box.U[0]);
  502. box.sqrLenU0 = Dot(box.U[0], box.U[0]);
  503. // Compute the box area.
  504. Vector2<ComputeType> diff[2] =
  505. {
  506. vertices[box.index[1]] - vertices[box.index[3]],
  507. vertices[box.index[2]] - vertices[box.index[0]]
  508. };
  509. box.area = Dot(box.U[0], diff[0]) * Dot(box.U[1], diff[1]) / box.sqrLenU0;
  510. return true;
  511. }
  512. // Convert the ComputeType box to the InputType box. When the
  513. // ComputeType is an exact rational type, the conversions are
  514. // performed to avoid precision loss until necessary at the last step.
  515. void ConvertTo(Box const& minBox,
  516. std::vector<Vector2<ComputeType>> const& computePoints,
  517. OrientedBox2<InputType>& itMinBox)
  518. {
  519. // The sum, difference, and center are all computed exactly.
  520. Vector2<ComputeType> sum[2] =
  521. {
  522. computePoints[minBox.index[1]] + computePoints[minBox.index[3]],
  523. computePoints[minBox.index[2]] + computePoints[minBox.index[0]]
  524. };
  525. Vector2<ComputeType> difference[2] =
  526. {
  527. computePoints[minBox.index[1]] - computePoints[minBox.index[3]],
  528. computePoints[minBox.index[2]] - computePoints[minBox.index[0]]
  529. };
  530. Vector2<ComputeType> center = mHalf * (
  531. Dot(minBox.U[0], sum[0]) * minBox.U[0] +
  532. Dot(minBox.U[1], sum[1]) * minBox.U[1]) / minBox.sqrLenU0;
  533. // Calculate the squared extent using ComputeType to avoid loss of
  534. // precision before computing a squared root.
  535. Vector2<ComputeType> sqrExtent;
  536. for (int i = 0; i < 2; ++i)
  537. {
  538. sqrExtent[i] = mHalf * Dot(minBox.U[i], difference[i]);
  539. sqrExtent[i] *= sqrExtent[i];
  540. sqrExtent[i] /= minBox.sqrLenU0;
  541. }
  542. for (int i = 0; i < 2; ++i)
  543. {
  544. itMinBox.center[i] = (InputType)center[i];
  545. itMinBox.extent[i] = std::sqrt((InputType)sqrExtent[i]);
  546. // Before converting to floating-point, factor out the maximum
  547. // component using ComputeType to generate rational numbers in
  548. // a range that avoids loss of precision during the conversion
  549. // and normalization.
  550. Vector2<ComputeType> const& axis = minBox.U[i];
  551. ComputeType cmax = std::max(std::fabs(axis[0]), std::fabs(axis[1]));
  552. ComputeType invCMax = mOne / cmax;
  553. for (int j = 0; j < 2; ++j)
  554. {
  555. itMinBox.axis[i][j] = (InputType)(axis[j] * invCMax);
  556. }
  557. Normalize(itMinBox.axis[i]);
  558. }
  559. mSupportIndices = minBox.index;
  560. mArea = (InputType)minBox.area;
  561. }
  562. // The input points to be bound.
  563. int mNumPoints;
  564. Vector2<InputType> const* mPoints;
  565. // The indices into mPoints/mComputePoints for the convex hull
  566. // vertices.
  567. std::vector<int> mHull;
  568. // The support indices for the minimum-area box.
  569. std::array<int, 4> mSupportIndices;
  570. // The area of the minimum-area box. The ComputeType value is
  571. // exact, so the only rounding errors occur in the conversion from
  572. // ComputeType to InputType (default rounding mode is
  573. // round-to-nearest-ties-to-even).
  574. InputType mArea;
  575. // Convenient values that occur regularly in the code. When using
  576. // rational ComputeType, we construct these numbers only once.
  577. ComputeType mZero, mOne, mNegOne, mHalf;
  578. };
  579. }