Last active
September 25, 2024 23:36
-
-
Save Hermann-SW/3fbb577ab0ef2abb0e89fb06965c3256 to your computer and use it in GitHub Desktop.
C++ code for CGAL issue 8359
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CGAL/Homogeneous.h> | |
#include <CGAL/Width_default_traits_3.h> | |
#include <CGAL/Width_3.h> | |
#include <iostream> | |
#include <cassert> | |
#include <vector> | |
typedef CGAL::Gmpz _RT; | |
typedef CGAL::Homogeneous<_RT> _Kernel; | |
typedef _Kernel::Point_3 _Point_3; | |
typedef _Kernel::Vector_3 _Vector_3; | |
typedef _Kernel::Plane_3 _Plane_3; | |
typedef CGAL::Width_default_traits_3<_Kernel> _Width_traits; | |
typedef CGAL::Width_3<_Width_traits> _Width; | |
void print_vec(const std::vector<_Vector_3>& vec) | |
{ | |
for (std::vector<_Vector_3>::const_iterator it = vec.begin(); | |
it != vec.end(); ++ it) | |
std::cerr << *it << std::endl; | |
} | |
std::vector<_Point_3> one = {{1, 0, 0}, {2, -1, 0}, {2, 0, -1}, {3, 0, 0}, {2, 1, 0}, {2, 0, 1}}; | |
std::vector<_Point_3> two = {{725, -65, -11}, {736, -66, -11}, {336, -30, -5}, {347, -31, -5}, {1225, -110, -19}, {1269, -114, -19}, {-331, 30, 5}, {-287, 26, 5}, {1747, -157, -27}, {947, -85, -15}, {1780, -160, -27}, {-220, 20, 3}, {1024, -92, -15}, {-976, 88, 15}, {-143, 13, 3}, {-943, 85, 15}, {1869, -168, -29}, {1069, -96, -17}, {1913, -172, -29}, {-487, 44, 7}, {1157, -104, -17}, {-1243, 112, 19}, {-399, 36, 7}, {-1199, 108, 19}, {1591, -143, -25}, {1668, -150, -25}, {-1132, 102, 17}, {-1055, 95, 17}, {2268, -204, -35}, {268, -24, -5}, {2279, -205, -35}, {-121, 11, 1}, {389, -35, -5}, {-2011, 181, 31}, {0, 0, 1}, {-2000, 180, 31}, {1579, -142, -25}, {1667, -150, -25}, {-1533, 138, 23}, {-1445, 130, 23}, {1712, -154, -27}, {1312, -118, -21}, {2123, -191, -33}, {523, -47, -9}, {2156, -194, -33}, {-644, 58, 9}, {1789, -161, -27}, {-1411, 127, 21}, {1411, -127, -21}, {-1789, 161, 27}, {644, -58, -9}, {-2156, 194, 33}, {-523, 47, 9}, {-2123, 191, 33}, {-1312, 118, 21}, {-1712, 154, 27}, {1445, -130, -23}, {1533, -138, -23}, {-1667, 150, 25}, {-1579, 142, 25}, {2000, -180, -31}, {0, 0, -1}, {2011, -181, -31}, {-389, 35, 5}, {121, -11, -1}, {-2279, 205, 35}, {-268, 24, 5}, {-2268, 204, 35}, {1055, -95, -17}, {1132, -102, -17}, {-1668, 150, 25}, {-1591, 143, 25}, {1199, -108, -19}, {399, -36, -7}, {1243, -112, -19}, {-1157, 104, 17}, {487, -44, -7}, {-1913, 172, 29}, {-1069, 96, 17}, {-1869, 168, 29}, {943, -85, -15}, {143, -13, -3}, {976, -88, -15}, {-1024, 92, 15}, {220, -20, -3}, {-1780, 160, 27}, {-947, 85, 15}, {-1747, 157, 27}, {287, -26, -5}, {331, -30, -5}, {-1269, 114, 19}, {-1225, 110, 19}, {-347, 31, 5}, {-336, 30, 5}, {-736, 66, 11}, {-725, 65, 11}}; | |
void demo(std::vector<_Point_3>& pts) { | |
_Width _simplex(pts.begin(), pts.end()); | |
std::vector<_Vector_3> _dir; | |
_simplex.get_all_build_directions(_dir); | |
std::cerr << "opt: " << _simplex.get_number_of_optimal_solutions() | |
<< " (should be " | |
<< (pts.size()==6 ? 4 : 1) << ")" << std::endl; | |
// workaround | |
for (std::vector<_Vector_3>::iterator it = _dir.begin(); | |
it != _dir.end(); ++ it) | |
if (it->hx()<0 || (it->hx()==0 && it->hy()<0) | |
|| (it->hx()==0 && it->hy()==0 && it->hz()<0)) | |
*it = - *it; | |
struct | |
{ | |
bool operator()(_Vector_3 a, _Vector_3 b) const { | |
if (a.hx() != b.hx()) return a.hx() < b.hx(); | |
if (a.hy() != b.hy()) return a.hy() < b.hy(); | |
return a.hz() < b.hz(); | |
} | |
} | |
customLess; | |
struct | |
{ | |
bool operator()(_Vector_3 a, _Vector_3 b) const { | |
return a.hx()==b.hx() && a.hy()==b.hy() && a.hz()==b.hz(); | |
} | |
} | |
customEqual; | |
std::sort(_dir.begin(), _dir.end(), customLess); | |
std::vector<_Vector_3> res(_dir.begin(), | |
std::unique(_dir.begin(), _dir.end(), customEqual)); | |
print_vec(res); | |
std::cerr << std::endl; | |
} | |
int main() { | |
demo(one); | |
demo(two); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it working with latest revision: