// 3D intersection tests. // We want to check that no division is performed for interface macro Do_intersect_3_RT #define CGAL_NO_MPZF_DIVISION_OPERATOR // Plane_3_X with X < Plane (lexicographically) are tested in other files #include #include #include #include #include #include #include #include #include "intersection_test_helper.h" #include #include #include #include #include #include #include template struct Plane_3_intersection_tester : public Intersection_3_tester { typedef Intersection_3_tester Base; typedef typename K::FT FT; typedef CGAL::Circle_3 C; typedef CGAL::Iso_cuboid_3 Cub; typedef CGAL::Line_3 L; typedef CGAL::Point_3 P; typedef CGAL::Plane_3 Pl; typedef CGAL::Ray_3 R; typedef CGAL::Segment_3 S; typedef CGAL::Sphere_3 Sph; typedef CGAL::Tetrahedron_3 Tet; typedef CGAL::Triangle_3 Tr; typedef CGAL::Vector_3 V; using Base::p; using Base::pl; using Base::random_point; using Base::check_do_intersect; using Base::check_do_not_intersect; using Base::check_intersection; using Base::check_no_intersection; private: int N = 1000; public: Plane_3_intersection_tester(CGAL::Random& r, const bool has_exact_p = false, const bool has_exact_c = false) : Base(r, has_exact_p, has_exact_c) { } public: void Pl_Pl() { std::cout << "Plane - Plane\n"; // No intersection check_no_intersection(pl(2,1,3,4), pl(6,3,9,3)); // Self check_intersection(pl(2,1,3,4), pl(2,1,3,4), pl(2,1,3,4)); Base::template check_intersection(Pl(p(0,1,8), p(4,3,7), p(2,9,1)), Pl(p(4,3,7), p(0,1,8), p(2,9,1))); // Line (directed...) check_intersection(pl(0,0,1,0), pl(0,1,0,0), L(P(0,0,0), P(-1,0,0)), false /*do_opposite*/); check_intersection(pl(0,1,0,0), pl(0,0,1,0), L(P(-85,0,0), P(0,0,0)), false /*do_opposite*/); check_intersection(pl(2,3,7,5), pl(9,7,1,3), L(P(2,-3,0), P(-3908,5182,-1105)), false /*do_opposite*/); check_intersection(pl(9,7,1,3), pl(2,3,7,5), L(P(-3908,5182,-1105), P(2,-3,0)), false /*do_opposite*/); // generic for(int i=0; ihas_exact_c) { assert(l.has_on(pl1)); assert(l.has_on(pl2)); } } } // Plane Base::template check_intersection(pl(0,0,1,1), pl(0,0,3,3)); Base::template check_intersection(pl(2,1,3,4), pl(6,3,9,12)); } void Pl_P() { std::cout << "Plane - Point\n"; // no intersection check_no_intersection(Pl(p(5,3,2), p(1,1,1), p(0,0,0)), P(99,98,99)); check_intersection(Pl(p(5,3,2), p(1,1,1), p(0,0,0)), P(99,99,99), P(99,99,99)); // Homogeneous projections are broken if(this->has_exact_c && std::is_same::value) { for(int i=0; i (pl(0,0,1,-1), R(p(1,1,1), p(2,3,1))); check_intersection(pl(0,0,1,-1), R(p(1,1,1), p(2,3,1)), R(p(1,1,1), p(2,3,1))); } void Pl_S() { std::cout << "Plane - Segment\n"; // No intersection check_no_intersection (pl(1,1,1,0), S(p(1,1,1), p(2,3,4))); check_no_intersection (pl(0,0,1,-2), S(p(1,1,1), p(2,3,1))); check_no_intersection (pl(1,0,1,3), S(p(1,1,1), p(2,3,-1))); check_no_intersection (pl(1,2,4,7), S(p(1,1,1), p(2,3,4))); // Point check_intersection (pl(0,0,1,0), S(p(1,1,-1), p(-1,-1,1)), P(0,0,0)); check_intersection (pl(0,0,1,0), S(p(7,1,0), p(83,1,-4)), p(7,1,0)); check_intersection (pl(0,0,1,0), S(p(12,6,-4), p(7,25,0)), p(7,25,0)); // Segment Base::template check_intersection(pl(0,0,1,-1), S(p(1,1,1), p(2,3,1))); } // see also circle_other.cpp void Pl_Sph() { std::cout << "Plane - Sphere\n"; // No intersection check_no_intersection(pl(1,1,1,0), Sph(p(4,3,1), 1)); // Point check_intersection (pl(0,10,0,0), Sph(p(4,-2,1), 4), p(4,0,1)); check_intersection (pl(1,1,0,0), Sph(p(4,4,-10), 32), p(0,0,-10)); // generic check_intersection (pl(0,0,1,-1), Sph(p(0,0,2), 4), C(pl(0,0,1,-1), Sph(p(0,0,2), 4))); if(this->has_exact_c) { for(int i=0; ihas_exact_c) { check_intersection(tet, Pl(P(0,0.5,0), P(1,0.5,-5), P(0.5,0.5,0.5)), Tr(P(0,0.5,0), P(0.5,0.5,0), P(0,0.5,0.5))); Pl pln(P(0,0.9,0), P(0.9,0,0), P(0.9,0.01,0.06)); // Don't have the right values to test further. auto res = CGAL::intersection(tet, pln); const std::vector

* poly = std::get_if >(&*res); assert(poly != nullptr); assert(poly->size() == 4); } for(int i=0; i os; os.insert(pln.oriented_side(tet0)); os.insert(pln.oriented_side(tet1)); os.insert(pln.oriented_side(tet2)); os.insert(pln.oriented_side(tet3)); if(os.size() == 1 && (*os.begin() != CGAL::ZERO)) check_no_intersection(pln, t); else check_do_intersect(pln, t); } } void Pl_Tr() { std::cout << "Plane - Triangle\n"; // No intersection // Point check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(0,0,0), p(1,0,1), p(0,1,1)), p(0,0,0)); // Segment check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(0,0,0), p(1,0,0), p(0,1,1)), S(p(0,0,0), p(1,0,0))); check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(1,0,-1), p(-1,0,-1), p(0,0,1)), S(P(0.5,0,0), P(-0.5,0,0))); // Triangle check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(0,0,0), p(1,0,0), p(0,1,0)), Tr(p(0,0,0), p(1,0,0), p(0,1,0))); for(int i=0; i(pln, Tr(pl0, pl3, pl4)); } } } void Pl_Pl_Pl() { std::cout << "Plane - Plane - Plane\n"; Pl pl1(1,0,0,0); Pl pl2(0,1,0,0); Pl pl3(0,0,1,0); Pl pl4(1,0,0,1); // pl4 is parallel to pl1. // No intersection check_no_intersection(pl1, pl2, pl4); check_no_intersection(pl1, pl4, pl2); check_no_intersection(pl4, pl2, pl1); check_no_intersection(Pl(p(0,0,0),p(1,1,1),p(1,1,0)), Pl(p(0,0,0),p(1,-1,1),p(1,-1,-2)), Pl(1,0,0,-5)); // Intersection in a line. Pl pl5(1,1,0,0); // pl1, pl2, pl5 intersect in the line l. L l; assert(CGAL::do_intersect(pl1, pl2, pl5)); CGAL::Object o4 = CGAL::intersection(pl1, pl2, pl5); assert(assign(l, o4)); assert(l == L(P(0,0,0), P(0,0,1))); // Intersection in a plane. assert(CGAL::do_intersect(pl1, pl1, pl1)); CGAL::Object o5 = CGAL::intersection(pl1, pl1, pl1); Pl pln; assert(assign(pln, o5)); assert(pln == pl1); // Generic intersection. assert(CGAL::do_intersect(pl1, pl2, pl3)); CGAL::Object o = CGAL::intersection(pl1, pl2, pl3); P pt; assert(assign(pt, o)); assert(pt == P(0,0,0)); } void run() { std::cout << "3D Plane Intersection tests\n"; Pl_Pl(); Pl_P(); Pl_R(); Pl_S(); Pl_Sph(); Pl_Tet(); Pl_Tr(); Pl_Pl_Pl(); } }; int main(int, char**) { std::cout.precision(17); std::cerr.precision(17); CGAL::Set_ieee_double_precision pfr; CGAL::Random r; std::cout << "random seed = " << r.get_seed() << std::endl; std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; Plane_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); // Homogeneous is broken for projection and Pln-Sphere // std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; // Plane_3_intersection_tester< CGAL::Homogeneous >(r).run(); std::cout << " |||||||| Test EPICK ||||||||" << std::endl; Plane_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); std::cout << " |||||||| Test EPECK ||||||||" << std::endl; Plane_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); // See above // std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; // Plane_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); std::cout << "OK!" << std::endl; }