strict_flags.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. diff -r e82d852e4fb0 lib/csg_collector.cpp
  2. --- a/lib/csg_collector.cpp Wed Jan 15 13:16:14 2014 +1100
  3. +++ b/lib/csg_collector.cpp Mon Jan 27 17:01:46 2014 +0600
  4. @@ -21,6 +21,7 @@
  5. #include <carve/csg.hpp>
  6. #include <iostream>
  7. +#include "csg_collector.hpp"
  8. #include "intersect_debug.hpp"
  9. #if defined(CARVE_DEBUG_WRITE_PLY_DATA)
  10. diff -r e82d852e4fb0 lib/face.cpp
  11. --- a/lib/face.cpp Wed Jan 15 13:16:14 2014 +1100
  12. +++ b/lib/face.cpp Mon Jan 27 17:01:46 2014 +0600
  13. @@ -21,61 +21,69 @@
  14. #include <carve/poly.hpp>
  15. -double CALC_X(const carve::geom::plane<3> &p, double y, double z) { return -(p.d + p.N.y * y + p.N.z * z) / p.N.x; }
  16. -double CALC_Y(const carve::geom::plane<3> &p, double x, double z) { return -(p.d + p.N.x * x + p.N.z * z) / p.N.y; }
  17. -double CALC_Z(const carve::geom::plane<3> &p, double x, double y) { return -(p.d + p.N.x * x + p.N.y * y) / p.N.z; }
  18. +namespace {
  19. +
  20. + double CALC_X(const carve::geom::plane<3> &p, double y, double z) { return -(p.d + p.N.y * y + p.N.z * z) / p.N.x; }
  21. + double CALC_Y(const carve::geom::plane<3> &p, double x, double z) { return -(p.d + p.N.x * x + p.N.z * z) / p.N.y; }
  22. + double CALC_Z(const carve::geom::plane<3> &p, double x, double y) { return -(p.d + p.N.x * x + p.N.y * y) / p.N.z; }
  23. +
  24. +} // namespace
  25. namespace carve {
  26. namespace poly {
  27. - carve::geom2d::P2 _project_1(const carve::geom3d::Vector &v) {
  28. - return carve::geom::VECTOR(v.z, v.y);
  29. - }
  30. + namespace {
  31. - carve::geom2d::P2 _project_2(const carve::geom3d::Vector &v) {
  32. - return carve::geom::VECTOR(v.x, v.z);
  33. - }
  34. + carve::geom2d::P2 _project_1(const carve::geom3d::Vector &v) {
  35. + return carve::geom::VECTOR(v.z, v.y);
  36. + }
  37. - carve::geom2d::P2 _project_3(const carve::geom3d::Vector &v) {
  38. - return carve::geom::VECTOR(v.y, v.x);
  39. - }
  40. + carve::geom2d::P2 _project_2(const carve::geom3d::Vector &v) {
  41. + return carve::geom::VECTOR(v.x, v.z);
  42. + }
  43. - carve::geom2d::P2 _project_4(const carve::geom3d::Vector &v) {
  44. - return carve::geom::VECTOR(v.y, v.z);
  45. - }
  46. + carve::geom2d::P2 _project_3(const carve::geom3d::Vector &v) {
  47. + return carve::geom::VECTOR(v.y, v.x);
  48. + }
  49. - carve::geom2d::P2 _project_5(const carve::geom3d::Vector &v) {
  50. - return carve::geom::VECTOR(v.z, v.x);
  51. - }
  52. + carve::geom2d::P2 _project_4(const carve::geom3d::Vector &v) {
  53. + return carve::geom::VECTOR(v.y, v.z);
  54. + }
  55. - carve::geom2d::P2 _project_6(const carve::geom3d::Vector &v) {
  56. - return carve::geom::VECTOR(v.x, v.y);
  57. - }
  58. + carve::geom2d::P2 _project_5(const carve::geom3d::Vector &v) {
  59. + return carve::geom::VECTOR(v.z, v.x);
  60. + }
  61. + carve::geom2d::P2 _project_6(const carve::geom3d::Vector &v) {
  62. + return carve::geom::VECTOR(v.x, v.y);
  63. + }
  64. - carve::geom3d::Vector _unproject_1(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  65. - return carve::geom::VECTOR(CALC_X(plane_eqn, p.y, p.x), p.y, p.x);
  66. - }
  67. - carve::geom3d::Vector _unproject_2(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  68. - return carve::geom::VECTOR(p.x, CALC_Y(plane_eqn, p.x, p.y), p.y);
  69. - }
  70. + carve::geom3d::Vector _unproject_1(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  71. + return carve::geom::VECTOR(CALC_X(plane_eqn, p.y, p.x), p.y, p.x);
  72. + }
  73. - carve::geom3d::Vector _unproject_3(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  74. - return carve::geom::VECTOR(p.y, p.x, CALC_Z(plane_eqn, p.y, p.x));
  75. - }
  76. + carve::geom3d::Vector _unproject_2(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  77. + return carve::geom::VECTOR(p.x, CALC_Y(plane_eqn, p.x, p.y), p.y);
  78. + }
  79. - carve::geom3d::Vector _unproject_4(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  80. - return carve::geom::VECTOR(CALC_X(plane_eqn, p.x, p.y), p.x, p.y);
  81. - }
  82. + carve::geom3d::Vector _unproject_3(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  83. + return carve::geom::VECTOR(p.y, p.x, CALC_Z(plane_eqn, p.y, p.x));
  84. + }
  85. - carve::geom3d::Vector _unproject_5(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  86. - return carve::geom::VECTOR(p.y, CALC_Y(plane_eqn, p.y, p.x), p.x);
  87. - }
  88. + carve::geom3d::Vector _unproject_4(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  89. + return carve::geom::VECTOR(CALC_X(plane_eqn, p.x, p.y), p.x, p.y);
  90. + }
  91. - carve::geom3d::Vector _unproject_6(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  92. - return carve::geom::VECTOR(p.x, p.y, CALC_Z(plane_eqn, p.x, p.y));
  93. - }
  94. + carve::geom3d::Vector _unproject_5(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  95. + return carve::geom::VECTOR(p.y, CALC_Y(plane_eqn, p.y, p.x), p.x);
  96. + }
  97. +
  98. + carve::geom3d::Vector _unproject_6(const carve::geom2d::P2 &p, const carve::geom3d::Plane &plane_eqn) {
  99. + return carve::geom::VECTOR(p.x, p.y, CALC_Z(plane_eqn, p.x, p.y));
  100. + }
  101. +
  102. + } // namespace
  103. static carve::geom2d::P2 (*project_tab[2][3])(const carve::geom3d::Vector &) = {
  104. { &_project_1, &_project_2, &_project_3 },
  105. diff -r e82d852e4fb0 lib/geom2d.cpp
  106. --- a/lib/geom2d.cpp Wed Jan 15 13:16:14 2014 +1100
  107. +++ b/lib/geom2d.cpp Mon Jan 27 17:01:46 2014 +0600
  108. @@ -157,9 +157,9 @@
  109. return pointInPoly(points, p2_adapt_ident(), p);
  110. }
  111. - int lineSegmentPolyIntersections(const P2Vector &points,
  112. - LineSegment2 line,
  113. - std::vector<PolyIntersectionInfo> &out) {
  114. + static int lineSegmentPolyIntersections(const P2Vector &points,
  115. + LineSegment2 line,
  116. + std::vector<PolyIntersectionInfo> &out) {
  117. int count = 0;
  118. if (line.v2 < line.v1) { line.flip(); }
  119. @@ -239,9 +239,9 @@
  120. }
  121. };
  122. - int sortedLineSegmentPolyIntersections(const P2Vector &points,
  123. - LineSegment2 line,
  124. - std::vector<PolyIntersectionInfo> &out) {
  125. + static int sortedLineSegmentPolyIntersections(const P2Vector &points,
  126. + LineSegment2 line,
  127. + std::vector<PolyIntersectionInfo> &out) {
  128. bool swapped = line.v2 < line.v1;
  129. diff -r e82d852e4fb0 lib/intersect.cpp
  130. --- a/lib/intersect.cpp Wed Jan 15 13:16:14 2014 +1100
  131. +++ b/lib/intersect.cpp Mon Jan 27 17:01:46 2014 +0600
  132. @@ -1378,9 +1378,9 @@
  133. * @param result_list
  134. * @param shared_edge_ptr
  135. */
  136. -void returnSharedEdges(carve::csg::V2Set &shared_edges,
  137. - std::list<carve::mesh::MeshSet<3> *> &result_list,
  138. - carve::csg::V2Set *shared_edge_ptr) {
  139. +static void returnSharedEdges(carve::csg::V2Set &shared_edges,
  140. + std::list<carve::mesh::MeshSet<3> *> &result_list,
  141. + carve::csg::V2Set *shared_edge_ptr) {
  142. // need to convert shared edges to point into result
  143. typedef std::map<carve::geom3d::Vector, carve::mesh::MeshSet<3>::vertex_t *> remap_type;
  144. remap_type remap;
  145. diff -r e82d852e4fb0 lib/intersect_face_division.cpp
  146. --- a/lib/intersect_face_division.cpp Wed Jan 15 13:16:14 2014 +1100
  147. +++ b/lib/intersect_face_division.cpp Mon Jan 27 17:01:46 2014 +0600
  148. @@ -1455,7 +1455,7 @@
  149. std::vector<carve::mesh::MeshSet<3>::vertex_t *> base_loop;
  150. std::list<std::vector<carve::mesh::MeshSet<3>::vertex_t *> > hole_loops;
  151. - bool face_edge_intersected = assembleBaseLoop(face, data, base_loop, hooks);
  152. + /*bool face_edge_intersected = */assembleBaseLoop(face, data, base_loop, hooks);
  153. detail::FV2SMap::const_iterator fse_iter = data.face_split_edges.find(face);
  154. diff -r e82d852e4fb0 lib/math.cpp
  155. --- a/lib/math.cpp Wed Jan 15 13:16:14 2014 +1100
  156. +++ b/lib/math.cpp Mon Jan 27 17:01:46 2014 +0600
  157. @@ -42,20 +42,21 @@
  158. Root(double r, int m) : root(r), multiplicity(m) {}
  159. };
  160. - void cplx_sqrt(double re, double im,
  161. - double &re_1, double &im_1,
  162. - double &re_2, double &im_2) {
  163. - if (re == 0.0 && im == 0.0) {
  164. - re_1 = re_2 = re;
  165. - im_1 = im_2 = im;
  166. - } else {
  167. - double d = sqrt(re * re + im * im);
  168. - re_1 = sqrt((d + re) / 2.0);
  169. - re_2 = re_1;
  170. - im_1 = fabs(sqrt((d - re) / 2.0));
  171. - im_2 = -im_1;
  172. + namespace {
  173. + void cplx_sqrt(double re, double im,
  174. + double &re_1, double &im_1,
  175. + double &re_2, double &im_2) {
  176. + if (re == 0.0 && im == 0.0) {
  177. + re_1 = re_2 = re;
  178. + im_1 = im_2 = im;
  179. + } else {
  180. + double d = sqrt(re * re + im * im);
  181. + re_1 = sqrt((d + re) / 2.0);
  182. + re_2 = re_1;
  183. + im_1 = fabs(sqrt((d - re) / 2.0));
  184. + im_2 = -im_1;
  185. + }
  186. }
  187. - }
  188. void cplx_cbrt(double re, double im,
  189. double &re_1, double &im_1,
  190. @@ -76,109 +77,110 @@
  191. }
  192. }
  193. - void add_root(std::vector<Root> &roots, double root) {
  194. - for (size_t i = 0; i < roots.size(); ++i) {
  195. - if (roots[i].root == root) {
  196. - roots[i].multiplicity++;
  197. + void add_root(std::vector<Root> &roots, double root) {
  198. + for (size_t i = 0; i < roots.size(); ++i) {
  199. + if (roots[i].root == root) {
  200. + roots[i].multiplicity++;
  201. + return;
  202. + }
  203. + }
  204. + roots.push_back(Root(root));
  205. + }
  206. +
  207. + void linear_roots(double c1, double c0, std::vector<Root> &roots) {
  208. + roots.push_back(Root(c0 / c1));
  209. + }
  210. +
  211. + void quadratic_roots(double c2, double c1, double c0, std::vector<Root> &roots) {
  212. + if (fabs(c2) < EPS) {
  213. + linear_roots(c1, c0, roots);
  214. return;
  215. }
  216. - }
  217. - roots.push_back(Root(root));
  218. - }
  219. - void linear_roots(double c1, double c0, std::vector<Root> &roots) {
  220. - roots.push_back(Root(c0 / c1));
  221. - }
  222. + double p = 0.5 * c1 / c2;
  223. + double dis = p * p - c0 / c2;
  224. - void quadratic_roots(double c2, double c1, double c0, std::vector<Root> &roots) {
  225. - if (fabs(c2) < EPS) {
  226. - linear_roots(c1, c0, roots);
  227. - return;
  228. + if (dis > 0.0) {
  229. + dis = sqrt(dis);
  230. + if (-p - dis != -p + dis) {
  231. + roots.push_back(Root(-p - dis));
  232. + roots.push_back(Root(-p + dis));
  233. + } else {
  234. + roots.push_back(Root(-p, 2));
  235. + }
  236. + }
  237. }
  238. - double p = 0.5 * c1 / c2;
  239. - double dis = p * p - c0 / c2;
  240. + void cubic_roots(double c3, double c2, double c1, double c0, std::vector<Root> &roots) {
  241. + int n_sol = 0;
  242. + double _r[3];
  243. - if (dis > 0.0) {
  244. - dis = sqrt(dis);
  245. - if (-p - dis != -p + dis) {
  246. - roots.push_back(Root(-p - dis));
  247. - roots.push_back(Root(-p + dis));
  248. + if (fabs(c3) < EPS) {
  249. + quadratic_roots(c2, c1, c0, roots);
  250. + return;
  251. + }
  252. +
  253. + if (fabs(c0) < EPS) {
  254. + quadratic_roots(c3, c2, c1, roots);
  255. + add_root(roots, 0.0);
  256. + return;
  257. + }
  258. +
  259. + double xN = -c2 / (3.0 * c3);
  260. + double yN = c0 + xN * (c1 + xN * (c2 + c3 * xN));
  261. +
  262. + double delta_sq = (c2 * c2 - 3.0 * c3 * c1) / (9.0 * c3 * c3);
  263. + double h_sq = 4.0 / 9.0 * (c2 * c2 - 3.0 * c3 * c1) * (delta_sq * delta_sq);
  264. + double dis = yN * yN - h_sq;
  265. +
  266. + if (dis > EPS) {
  267. + // One real root, two complex roots.
  268. +
  269. + double dis_sqrt = sqrt(dis);
  270. + double r_p = yN - dis_sqrt;
  271. + double r_q = yN + dis_sqrt;
  272. + double p = cbrt(fabs(r_p)/(2.0 * c3));
  273. + double q = cbrt(fabs(r_q)/(2.0 * c3));
  274. +
  275. + if (r_p > 0.0) p = -p;
  276. + if (r_q > 0.0) q = -q;
  277. +
  278. + _r[0] = xN + p + q;
  279. + n_sol = 1;
  280. +
  281. + double re = xN - p * .5 - q * .5;
  282. + double im = p * M_SQRT_3_4 - q * M_SQRT_3_4;
  283. +
  284. + // root 2: xN + p * exp(M_2PI_3.i) + q * exp(-M_2PI_3.i);
  285. + // root 3: complex conjugate of root 2
  286. +
  287. + if (im < EPS) {
  288. + _r[1] = _r[2] = re;
  289. + n_sol += 2;
  290. + }
  291. + } else if (dis < -EPS) {
  292. + // Three distinct real roots.
  293. + double theta = acos(-yN / sqrt(h_sq)) / 3.0;
  294. + double delta = sqrt(c2 * c2 - 3.0 * c3 * c1) / (3.0 * c3);
  295. +
  296. + _r[0] = xN + (2.0 * delta) * cos(theta);
  297. + _r[1] = xN + (2.0 * delta) * cos(M_2PI_3 - theta);
  298. + _r[2] = xN + (2.0 * delta) * cos(M_2PI_3 + theta);
  299. + n_sol = 3;
  300. } else {
  301. - roots.push_back(Root(-p, 2));
  302. + // Three real roots (two or three equal).
  303. + double r = yN / (2.0 * c3);
  304. + double delta = cbrt(r);
  305. +
  306. + _r[0] = xN + delta;
  307. + _r[1] = xN + delta;
  308. + _r[2] = xN - 2.0 * delta;
  309. + n_sol = 3;
  310. }
  311. - }
  312. - }
  313. - void cubic_roots(double c3, double c2, double c1, double c0, std::vector<Root> &roots) {
  314. - int n_sol = 0;
  315. - double _r[3];
  316. -
  317. - if (fabs(c3) < EPS) {
  318. - quadratic_roots(c2, c1, c0, roots);
  319. - return;
  320. - }
  321. -
  322. - if (fabs(c0) < EPS) {
  323. - quadratic_roots(c3, c2, c1, roots);
  324. - add_root(roots, 0.0);
  325. - return;
  326. - }
  327. -
  328. - double xN = -c2 / (3.0 * c3);
  329. - double yN = c0 + xN * (c1 + xN * (c2 + c3 * xN));
  330. -
  331. - double delta_sq = (c2 * c2 - 3.0 * c3 * c1) / (9.0 * c3 * c3);
  332. - double h_sq = 4.0 / 9.0 * (c2 * c2 - 3.0 * c3 * c1) * (delta_sq * delta_sq);
  333. - double dis = yN * yN - h_sq;
  334. -
  335. - if (dis > EPS) {
  336. - // One real root, two complex roots.
  337. -
  338. - double dis_sqrt = sqrt(dis);
  339. - double r_p = yN - dis_sqrt;
  340. - double r_q = yN + dis_sqrt;
  341. - double p = cbrt(fabs(r_p)/(2.0 * c3));
  342. - double q = cbrt(fabs(r_q)/(2.0 * c3));
  343. -
  344. - if (r_p > 0.0) p = -p;
  345. - if (r_q > 0.0) q = -q;
  346. -
  347. - _r[0] = xN + p + q;
  348. - n_sol = 1;
  349. -
  350. - double re = xN - p * .5 - q * .5;
  351. - double im = p * M_SQRT_3_4 - q * M_SQRT_3_4;
  352. -
  353. - // root 2: xN + p * exp(M_2PI_3.i) + q * exp(-M_2PI_3.i);
  354. - // root 3: complex conjugate of root 2
  355. -
  356. - if (im < EPS) {
  357. - _r[1] = _r[2] = re;
  358. - n_sol += 2;
  359. + for (int i=0; i < n_sol; i++) {
  360. + add_root(roots, _r[i]);
  361. }
  362. - } else if (dis < -EPS) {
  363. - // Three distinct real roots.
  364. - double theta = acos(-yN / sqrt(h_sq)) / 3.0;
  365. - double delta = sqrt(c2 * c2 - 3.0 * c3 * c1) / (3.0 * c3);
  366. -
  367. - _r[0] = xN + (2.0 * delta) * cos(theta);
  368. - _r[1] = xN + (2.0 * delta) * cos(M_2PI_3 - theta);
  369. - _r[2] = xN + (2.0 * delta) * cos(M_2PI_3 + theta);
  370. - n_sol = 3;
  371. - } else {
  372. - // Three real roots (two or three equal).
  373. - double r = yN / (2.0 * c3);
  374. - double delta = cbrt(r);
  375. -
  376. - _r[0] = xN + delta;
  377. - _r[1] = xN + delta;
  378. - _r[2] = xN - 2.0 * delta;
  379. - n_sol = 3;
  380. - }
  381. -
  382. - for (int i=0; i < n_sol; i++) {
  383. - add_root(roots, _r[i]);
  384. }
  385. }
  386. diff -r e82d852e4fb0 lib/triangulator.cpp
  387. --- a/lib/triangulator.cpp Wed Jan 15 13:16:14 2014 +1100
  388. +++ b/lib/triangulator.cpp Mon Jan 27 17:01:46 2014 +0600
  389. @@ -718,10 +718,10 @@
  390. -bool testCandidateAttachment(const std::vector<std::vector<carve::geom2d::P2> > &poly,
  391. - std::vector<std::pair<size_t, size_t> > &current_f_loop,
  392. - size_t curr,
  393. - carve::geom2d::P2 hole_min) {
  394. +static bool testCandidateAttachment(const std::vector<std::vector<carve::geom2d::P2> > &poly,
  395. + std::vector<std::pair<size_t, size_t> > &current_f_loop,
  396. + size_t curr,
  397. + carve::geom2d::P2 hole_min) {
  398. const size_t SZ = current_f_loop.size();
  399. if (!carve::geom2d::internalToAngle(pvert(poly, current_f_loop[(curr+1) % SZ]),