diff --git a/Packages/Cartesian_kernel/changes.txt b/Packages/Cartesian_kernel/changes.txt index 0659bd4d6f5..bdbcac44a63 100644 --- a/Packages/Cartesian_kernel/changes.txt +++ b/Packages/Cartesian_kernel/changes.txt @@ -1,3 +1,6 @@ +Version 102.7 (4 December 2003) +- More bisector() functions. + Version 102.6 (3 December 2003) - Add parallel(). diff --git a/Packages/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Packages/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 4b7c0511d79..67bab204666 100644 --- a/Packages/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Packages/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -893,6 +893,16 @@ namespace CartesianKernelFunctors { bisector_of_pointsC2(p.x(), p.y(), q.x(), q.y(), a, b, c); return Line_2(a, b, c); } + + Line_2 + operator()(const Line_2& p, const Line_2& q) const + { + FT a, b, c; + bisector_of_linesC2(p.a(), p.b(), p.c(), + q.a(), q.b(), q.c(), + a, b, c); + return Line_2(a, b, c); + } }; template @@ -914,6 +924,16 @@ namespace CartesianKernelFunctors { a, b, c, d); return Plane_3(a, b, c, d); } + + Plane_3 + operator()(const Plane_3& p, const Plane_3& q) const + { + FT a, b, c, d; + bisector_of_planesC3(p.a(), p.b(), p.c(), p.d(), + q.a(), q.b(), q.c(), q.d(), + a, b, c, d); + return Plane_3(a, b, c, d); + } }; template diff --git a/Packages/Cartesian_kernel/include/CGAL/Cartesian/line_constructions_2.h b/Packages/Cartesian_kernel/include/CGAL/Cartesian/line_constructions_2.h index 9f492469d15..9f902c16437 100644 --- a/Packages/Cartesian_kernel/include/CGAL/Cartesian/line_constructions_2.h +++ b/Packages/Cartesian_kernel/include/CGAL/Cartesian/line_constructions_2.h @@ -47,15 +47,6 @@ line_from_point_direction(const PointC2 &p, return K().construct_line_2_object()(p, d); } -template < class K > -inline -LineC2 -bisector(const PointC2 &p, - const PointC2 &q) -{ - return K().construct_bisector_2_object()(p, q); -} - template < class K > inline LineC2 diff --git a/Packages/Cartesian_kernel/include/CGAL/Cartesian/plane_constructions_3.h b/Packages/Cartesian_kernel/include/CGAL/Cartesian/plane_constructions_3.h index a5c2ca1c90d..4818bb1da41 100644 --- a/Packages/Cartesian_kernel/include/CGAL/Cartesian/plane_constructions_3.h +++ b/Packages/Cartesian_kernel/include/CGAL/Cartesian/plane_constructions_3.h @@ -56,14 +56,6 @@ plane_from_point_direction(const PointC3 &p, return PlaneC3(A, B, C, D); } -template -inline -typename K::Plane_3 -bisector(const PointC3 &p, const PointC3 &q) -{ - return K().construct_bisector_3_object()(p, q); -} - CGAL_END_NAMESPACE #endif // CGAL_CARTESIAN_PLANE_CONSTRUCTIONS_3_H diff --git a/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h b/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h index dee26eb7d5d..a69f4b4a9c9 100644 --- a/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h +++ b/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h @@ -142,6 +142,28 @@ bisector_of_pointsC2(const FT &px, const FT &py, CGAL_NTS square(px) - CGAL_NTS square(py); } +template < class FT > +CGAL_KERNEL_INLINE +void +bisector_of_linesC2(const FT &pa, const FT &pb, const FT &pc, + const FT &qa, const FT &qb, const FT &qc, + FT &a, FT &b, FT &c) +{ + // We normalize the equations of the 2 lines, and we then add them. + FT n1 = CGAL_NTS sqrt(CGAL_NTS square(pa) + CGAL_NTS square(pb)); + FT n2 = CGAL_NTS sqrt(CGAL_NTS square(qa) + CGAL_NTS square(qb)); + a = n2 * pa + n1 * qa; + b = n2 * pb + n1 * qb; + c = n2 * pc + n1 * qc; + + // Care must be taken for the case when this produces a degenerate line. + if (a == 0 && b == 0) { + a = n2 * pa - n1 * qa; + b = n2 * pb - n1 * qb; + c = n2 * pc - n1 * qc; + } +} + template < class FT > inline FT diff --git a/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC3.h b/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC3.h index 53b86ec957c..f41ec19acca 100644 --- a/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC3.h +++ b/Packages/Cartesian_kernel/include/CGAL/constructions/kernel_ftC3.h @@ -398,6 +398,31 @@ bisector_of_pointsC3(const FT &px, const FT &py, const FT &pz, - CGAL_NTS square(px) - CGAL_NTS square(py) - CGAL_NTS square(pz); } +template < class FT > +void +bisector_of_planesC3(const FT &pa, const FT &pb, const FT &pc, const FT &pd, + const FT &qa, const FT &qb, const FT &qc, const FT &qd, + FT &a, FT &b, FT &c, FT &d) +{ + // We normalize the equations of the 2 planes, and we then add them. + FT n1 = CGAL_NTS sqrt(CGAL_NTS square(pa) + CGAL_NTS square(pb) + + CGAL_NTS square(pc)); + FT n2 = CGAL_NTS sqrt(CGAL_NTS square(qa) + CGAL_NTS square(qb) + + CGAL_NTS square(qc)); + a = n2 * pa + n1 * qa; + b = n2 * pb + n1 * qb; + c = n2 * pc + n1 * qc; + d = n2 * pd + n1 * qd; + + // Care must be taken for the case when this produces a degenerate line. + if (a == 0 && b == 0 && c == 0) { + a = n2 * pa - n1 * qa; + b = n2 * pb - n1 * qb; + c = n2 * pc - n1 * qc; + d = n2 * pd - n1 * qd; + } +} + CGAL_END_NAMESPACE #endif // CGAL_CONSTRUCTIONS_KERNEL_FTC3_H diff --git a/Packages/H2/changes.txt b/Packages/H2/changes.txt index 31233fdc813..ad66782904f 100644 --- a/Packages/H2/changes.txt +++ b/Packages/H2/changes.txt @@ -1,3 +1,6 @@ +2.108 (4 December 2003) +- More bisector() functions. + 2.107 (3 December 2003) - Add parallel(). diff --git a/Packages/H2/include/CGAL/Homogeneous/basic_constructionsH2.h b/Packages/H2/include/CGAL/Homogeneous/basic_constructionsH2.h index 9d454c56dd5..19bc9e0d32b 100644 --- a/Packages/H2/include/CGAL/Homogeneous/basic_constructionsH2.h +++ b/Packages/H2/include/CGAL/Homogeneous/basic_constructionsH2.h @@ -42,14 +42,6 @@ gp_linear_intersection(const LineH2& l1, const LineH2& l2) l1.a()*l2.b() - l2.a()*l1.b() ); } -template -CGAL_KERNEL_MEDIUM_INLINE -typename K::Line_2 -bisector( const PointH2& p, const PointH2& q ) -{ - return K().construct_bisector_2_object()(p, q); -} - template CGAL_KERNEL_MEDIUM_INLINE typename R::FT diff --git a/Packages/H2/include/CGAL/Homogeneous/function_objects.h b/Packages/H2/include/CGAL/Homogeneous/function_objects.h index e08ba0b3b51..70ddd648595 100644 --- a/Packages/H2/include/CGAL/Homogeneous/function_objects.h +++ b/Packages/H2/include/CGAL/Homogeneous/function_objects.h @@ -1319,6 +1319,7 @@ namespace HomogeneousKernelFunctors { template class Construct_bisector_2 { + typedef typename K::RT RT; typedef typename K::FT FT; typedef typename K::Point_2 Point_2; typedef typename K::Line_2 Line_2; @@ -1329,8 +1330,6 @@ namespace HomogeneousKernelFunctors { Line_2 operator()(const Point_2& p, const Point_2& q) const { - typedef typename K::RT RT; - // Bisector equation is based on equation // ( X - p.x())^2 + (Y - p.y())^2 == ( X - q.x())^2 + (Y - q.y()) // and x() = hx()/hw() ... @@ -1349,11 +1348,22 @@ namespace HomogeneousKernelFunctors { return Line_2( a, b, c ); } + + Line_2 + operator()(const Line_2& p, const Line_2& q) const + { + RT a, b, c; + bisector_of_linesC2(p.a(), p.b(), p.c(), + q.a(), q.b(), q.c(), + a, b, c); + return Line_2(a, b, c); + } }; template class Construct_bisector_3 { + typedef typename K::RT RT; typedef typename K::FT FT; typedef typename K::Point_3 Point_3; typedef typename K::Plane_3 Plane_3; @@ -1364,8 +1374,6 @@ namespace HomogeneousKernelFunctors { Plane_3 operator()(const Point_3& p, const Point_3& q) const { - typedef typename K::RT RT; - // Bisector equation is based on equation // ( X - p.x())^2 + (Y - p.y())^2 == ( X - q.x())^2 + (Y - q.y()) // and x() = hx()/hw() ... @@ -1387,6 +1395,16 @@ namespace HomogeneousKernelFunctors { return Plane_3( a, b, c, d ); } + + Plane_3 + operator()(const Plane_3& p, const Plane_3& q) const + { + RT a, b, c, d; + bisector_of_planesC3(p.a(), p.b(), p.c(), p.d(), + q.a(), q.b(), q.c(), q.d(), + a, b, c, d); + return Plane_3(a, b, c, d); + } }; diff --git a/Packages/H3/changes.txt b/Packages/H3/changes.txt index 66795ef63ec..712edb8225e 100644 --- a/Packages/H3/changes.txt +++ b/Packages/H3/changes.txt @@ -1,3 +1,6 @@ +2.70 (4 December 2003) +- More bisector() functions. + 2.69 (19 November 2003) - Added bisector(Point_3, Point_3). diff --git a/Packages/H3/include/CGAL/Homogeneous/basic_constructionsH3.h b/Packages/H3/include/CGAL/Homogeneous/basic_constructionsH3.h index ad4b6d98a57..274401597b8 100644 --- a/Packages/H3/include/CGAL/Homogeneous/basic_constructionsH3.h +++ b/Packages/H3/include/CGAL/Homogeneous/basic_constructionsH3.h @@ -95,15 +95,6 @@ typename R::FT squared_distance( PointH3 const& p, PointH3 const& q) { return (p-q)*(p-q); } - -template -CGAL_KERNEL_MEDIUM_INLINE -typename K::Plane_3 -bisector( const PointH3& p, const PointH3& q ) -{ - return K().construct_bisector_3_object()(p, q); -} - template CGAL_KERNEL_MEDIUM_INLINE PointH3 @@ -222,8 +213,10 @@ circumcenter( PointH3 const& p, PointH3 const& r) { return gp_linear_intersection( PlaneH3(p,q,r), - bisector(p,q), - bisector(p,r)); + bisector(static_cast& >(p), + static_cast& >(q)), + bisector(static_cast& >(p), + static_cast& >(r))); } template diff --git a/Packages/Kernel_23/changes.txt b/Packages/Kernel_23/changes.txt index 7ff1b90a69e..4c5bb6e0bd7 100644 --- a/Packages/Kernel_23/changes.txt +++ b/Packages/Kernel_23/changes.txt @@ -1,3 +1,6 @@ +1.94 (4 December 2003) +- More bisector() functions. + 1.93 (2 December 2003) - Add parallel(). diff --git a/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_2.tex b/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_2.tex index e5018d79d8e..39b55bd5480 100644 --- a/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_2.tex +++ b/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_2.tex @@ -9,7 +9,22 @@ A model for this must provide: The bisector is oriented in such a way that \ccc{p} lies on its positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}} +\ccMemberFunction{Kernel::Line_2 operator()(const Kernel::Line_2&l1, + const Kernel::Line_2&l2);} +{constructs the bisector of the two lines $l1$ and $l2$. +In the general case, the bisector has the direction of the vector which +is the sum of the normalized directions of the two lines, and which passes +through the intersection of \ccc{l1} and \ccc{l2}. +If \ccc{l1} and \ccc{l2} are parallel, then the bisector is defined as the line +which has the same direction as \ccc{l1}, and which is at the same distance +from \ccc{l1} and \ccc{l2}. +This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()} +operation.} + \ccRefines AdaptableFunctor (with two arguments) +\ccSeeAlso +\ccRefIdfierPage{CGAL::bisector} + \end{ccRefFunctionObjectConcept} diff --git a/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_3.tex b/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_3.tex index e8914f27dca..001038e4b86 100644 --- a/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_3.tex +++ b/Packages/Kernel_23/doc_tex/kernel/Ref/Kernel_ConstructBisector_3.tex @@ -9,7 +9,22 @@ A model for this must provide: The bisector is oriented in such a way that \ccc{p} lies on its positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}} +\ccMemberFunction{Kernel::Plane_3 operator()(const Kernel::Plane_3&h1, + const Kernel::Plane_3&h2);} +{constructs the bisector of the two planes $h1$ and $h2$. +In the general case, the bisector has a normal vector which has the same +direction as the sum of the normalized normal vectors of the two planes, and +passes through the intersection of \ccc{h1} and \ccc{h2}. +If \ccc{h1} and \ccc{h2} are parallel, then the bisector is defined as the +plane which has the same oriented normal vector as \ccc{l1}, and which is at +the same distance from \ccc{h1} and \ccc{h2}. +This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()} +operation.} + \ccRefines AdaptableFunctor (with two arguments) +\ccSeeAlso +\ccRefIdfierPage{CGAL::bisector} + \end{ccRefFunctionObjectConcept} diff --git a/Packages/Kernel_23/doc_tex/kernel/Ref/bisector.tex b/Packages/Kernel_23/doc_tex/kernel/Ref/bisector.tex index 81ca129ece0..e5979f710a2 100644 --- a/Packages/Kernel_23/doc_tex/kernel/Ref/bisector.tex +++ b/Packages/Kernel_23/doc_tex/kernel/Ref/bisector.tex @@ -6,10 +6,34 @@ The bisector is oriented in such a way that \ccc{p} lies on its positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}} +\ccFunction{Line_2 bisector(const Line_2 &l1, + const Line_2 &l2);} +{constructs the bisector of the two lines $l1$ and $l2$. +In the general case, the bisector has the direction of the vector which +is the sum of the normalized directions of the two lines, and which passes +through the intersection of \ccc{l1} and \ccc{l2}. +If \ccc{l1} and \ccc{l2} are parallel, then the bisector is defined as the line +which has the same direction as \ccc{l1}, and which is at the same distance +from \ccc{l1} and \ccc{l2}. +This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()} +operation.} + \ccFunction{Plane_3 bisector(const Point_3 &p, const Point_3 &q);} {constructs the bisector plane of the two points \ccc{p} and \ccc{q}. The bisector is oriented in such a way that \ccc{p} lies on its positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}} +\ccFunction{Plane_3 bisector(const Plane_3 &h1, + const Plane_3 &h2);} +{constructs the bisector of the two planes $h1$ and $h2$. +In the general case, the bisector has a normal vector which has the same +direction as the sum of the normalized normal vectors of the two planes, and +passes through the intersection of \ccc{h1} and \ccc{h2}. +If \ccc{h1} and \ccc{h2} are parallel, then the bisector is defined as the +plane which has the same oriented normal vector as \ccc{l1}, and which is at +the same distance from \ccc{h1} and \ccc{h2}. +This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()} +operation.} + \end{ccRefFunction} diff --git a/Packages/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Packages/Kernel_23/include/CGAL/Kernel/global_functions_2.h index ebe6047fc18..f2bb046a9af 100644 --- a/Packages/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Packages/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -26,8 +26,44 @@ // Generic functions calling the kernel functor. +#include + CGAL_BEGIN_NAMESPACE +template +inline +typename K::Line_2 +bisector(const typename K::Point_2 &p, + const typename K::Point_2 &q, const K &k) +{ + return k.construct_bisector_2_object()(p, q); +} + +template +inline +typename K::Line_2 +bisector(const typename K::Line_2 &l1, + const typename K::Line_2 &l2, const K &k) +{ + return k.construct_bisector_2_object()(l1, l2); +} + +template +inline +typename K::Line_2 +bisector(const Point_2 &p, const Point_2 &q) +{ + return bisector(p, q, K()); +} + +template +inline +typename K::Line_2 +bisector(const Line_2 &l1, const Line_2 &l2) +{ + return bisector(l1, l2, K()); +} + template inline bool diff --git a/Packages/Kernel_23/include/CGAL/Kernel/global_functions_3.h b/Packages/Kernel_23/include/CGAL/Kernel/global_functions_3.h index beeb6e72f44..c447375a624 100644 --- a/Packages/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Packages/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -28,6 +28,40 @@ CGAL_BEGIN_NAMESPACE +template +inline +typename K::Plane_3 +bisector(const typename K::Point_3 &p, + const typename K::Point_3 &q, const K &k) +{ + return k.construct_bisector_3_object()(p, q); +} + +template +inline +typename K::Plane_3 +bisector(const typename K::Plane_3 &h1, + const typename K::Plane_3 &h2, const K &k) +{ + return k.construct_bisector_3_object()(h1, h2); +} + +template +inline +typename K::Plane_3 +bisector(const Point_3 &p, const Point_3 &q) +{ + return bisector(p, q, K()); +} + +template +inline +typename K::Plane_3 +bisector(const Plane_3 &h1, const Plane_3 &h2) +{ + return bisector(h1, h2, K()); +} + template inline bool diff --git a/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_line_2.h b/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_line_2.h index 8227549a730..ed3702a6cc6 100644 --- a/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_line_2.h +++ b/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_line_2.h @@ -22,6 +22,46 @@ #ifndef CGAL__TEST_FCT_LINE_2_H #define CGAL__TEST_FCT_LINE_2_H +// Accessory function testing functions that require sqrt(). +// Doesn't instantiate anything if RT doesn't support sqrt(). +template +bool +_test_fct_line_sqrt_2(const R&, CGAL::Tag_false) +{ + bool UNTESTED_STUFF_BECAUSE_SQRT_IS_NOT_SUPPORTED; + std::cout << std::endl + << "WARNING : FT doesn't support sqrt()," + " hence some functions are not tested." << std::endl; + return true; +} + +template +bool +_test_fct_line_sqrt_2(const R&, CGAL::Tag_true) +{ + typedef typename R::Point_2 Point_2; + typedef typename R::Line_2 Line_2; + + // bisector of 2 lines (uses sqrt()...) + Point_2 q0(0, 0, 1); + Point_2 q1(1, 0, 1); + Point_2 q2(0, 1, 1); + Point_2 q3(1, 1, 1); + Point_2 q4(2, 0, 1); + + Line_2 ql1 (q0, q1); + Line_2 ql2 (q0, q2); + Line_2 ql3 (q0, q3); + Line_2 ql4 (q0, q4); + Line_2 ql5 (q1, q0); + Line_2 bl3 = CGAL::bisector(ql1, ql2); + + assert( bl3 == ql3 ); + assert( CGAL::bisector(ql4, ql2) == ql3 ); + assert( CGAL::bisector(ql1, ql5) == ql1 ); + + return true; +} template bool @@ -142,6 +182,9 @@ _test_fct_line_2(const R& ) assert(bl1.oriented_side(p2) == CGAL::ON_POSITIVE_SIDE); assert( CGAL::parallel(bl1, bl2) ); + // More tests, that require sqrt(). + _test_fct_line_sqrt_2(R(), typename CGAL::Number_type_traits::Has_sqrt()); + std::cout << "done" << std::endl; return true; } diff --git a/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_plane_3.h b/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_plane_3.h index 5bba9b23d68..beaf30066e3 100644 --- a/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_plane_3.h +++ b/Packages/Kernel_23/test/Kernel/include/CGAL/_test_fct_plane_3.h @@ -21,6 +21,48 @@ #ifndef CGAL__TEST_FCT_PLANE_3_H #define CGAL__TEST_FCT_PLANE_3_H +// Accessory function testing functions that require sqrt(). +// Doesn't instantiate anything if RT doesn't support sqrt(). +template +bool +_test_fct_plane_sqrt_3(const R&, CGAL::Tag_false) +{ + bool UNTESTED_STUFF_BECAUSE_SQRT_IS_NOT_SUPPORTED; + std::cout << std::endl + << "WARNING : FT doesn't support sqrt()," + " hence some functions are not tested." << std::endl; + return true; +} + +template +bool +_test_fct_plane_sqrt_3(const R&, CGAL::Tag_true) +{ + typedef typename R::Point_3 Point_3; + typedef typename R::Plane_3 Plane_3; + + // bisector of 2 planes + Point_3 q0(0, 0, 0, 1); + Point_3 q1(1, 0, 0, 1); + Point_3 q2(0, 1, 0, 1); + Point_3 q3(1, 1, 0, 1); + Point_3 q4(2, 0, 0, 1); + Point_3 q5(0, 0, 1, 1); + + Plane_3 ql1 (q0, q1, q5); + Plane_3 ql2 (q0, q2, q5); + Plane_3 ql3 (q0, q3, q5); + Plane_3 ql4 (q0, q4, q5); + Plane_3 ql5 (q1, q0, q5); + Plane_3 bl3 = CGAL::bisector(ql1, ql2); + + assert( bl3 == ql3 ); + assert( CGAL::bisector(ql4, ql2) == ql3 ); + assert( CGAL::bisector(ql1, ql5) == ql1 ); + + return true; +} + template bool _test_fct_plane_3(const R& ) @@ -59,6 +101,9 @@ _test_fct_plane_3(const R& ) assert( CGAL::parallel(h1, h2) ); assert( ! CGAL::parallel(h1, h5) ); + // More tests, that require sqrt(). + _test_fct_plane_sqrt_3(R(), typename CGAL::Number_type_traits::Has_sqrt()); + std::cout << "done" << std::endl; return true; }