diff --git a/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h b/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h index bc7e134ceef..83a314daf2a 100644 --- a/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h +++ b/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h @@ -475,7 +475,39 @@ radical_axisC2(const RT &px, const RT &py, const We &pw, +RT(pw) - RT(qw); } +template< class FT > +CGAL_KERNEL_MEDIUM_INLINE +FT +squared_radius_orthogonal_circleC2(const FT &px, const FT &py, const FT &pw, + const FT &qx, const FT &qy, const FT &qw, + const FT &rx, const FT &ry, const FT &rw) +{ + FT FT4(4); + FT dpx = px - rx; + FT dpy = py - ry; + FT dqx = qx - rx; + FT dqy = qy - ry; + FT dpp = CGAL_NTS square(dpx) + CGAL_NTS square(dpy) - pw + rw; + FT dqq = CGAL_NTS square(dqx) + CGAL_NTS square(dqy) - qw + rw; + FT det0 = determinant(dpx, dpy, dqx, dqy); + FT det1 = determinant(dpp, dpy, dqq, dqy); + FT det2 = determinant(dpx, dpp, dqx, dqq); + + return (CGAL_NTS square(det1) + CGAL_NTS square(det2)) / + (FT4 * CGAL_NTS square(det0)) - rw; +} + +template< class FT > +CGAL_KERNEL_MEDIUM_INLINE +FT +squared_radius_smallest_orthogonal_circleC2(const FT &px, const FT &py, const FT &pw, + const FT &qx, const FT &qy, const FT &qw) +{ + FT FT4(4); + FT dpz = CGAL_NTS square(px - qx) + CGAL_NTS square(py - qy); + return (CGAL_NTS square(dpz - pw + qw) / (FT4 * dpz) - qw); +} } //namespace CGAL diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index fa8116b69b5..17a8d076381 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -2410,43 +2410,6 @@ public: /// @} }; -/*! -\ingroup PkgKernel23ConceptsFunctionObjects -\cgalConcept - -\sa `CGAL::Weighted_point_3` -\sa `ComputePowerProduct_3` for the definition of orthogonal sphere - -\cgalRefines `AdaptableFunctor` - -*/ -class ComputeSquaredRadiusSmallestOrthogonalSphere_3 { -public: - /// \name Operations - /// A model of this concept must provide: - /// @{ - - /*! - returns the squared radius of the - smallest sphere orthogonal to the argument(s). - */ - Kernel::FT operator() (const Kernel::Weighted_point_3& pw, - const Kernel::Weighted_point_3& qw, - const Kernel::Weighted_point_3& rw, - const Kernel::Weighted_point_3& sw) const; - - Kernel::FT operator() (const Kernel::Weighted_point_3& pw, - const Kernel::Weighted_point_3& qw, - const Kernel::Weighted_point_3& rw) const; - - Kernel::FT operator() (const Kernel::Weighted_point_3& pw, - const Kernel::Weighted_point_3& qw) const; - - Kernel::FT operator() (const Kernel::Weighted_point_3& pw) const; - - /// @} -}; - /*! \ingroup PkgKernel23ConceptsFunctionObjects \cgalConcept @@ -2894,6 +2857,75 @@ public: }; /* end Kernel::ComputeSquaredRadius_3 */ +/*! +\ingroup PkgKernel23ConceptsFunctionObjects +\cgalConcept + +\sa `CGAL::Weighted_point_2` +\sa `ComputePowerProduct_3` for the definition of orthogonality for power distances. + +\cgalRefines `AdaptableFunctor` + +*/ +class ComputeSquaredRadiusSmallestOrthogonalCircle_2 { +public: + /// \name Operations + /// A model of this concept must provide: + /// @{ + + /*! + returns the squared radius of the + smallest sphere circle to the argument(s). + */ + Kernel::FT operator() (const Kernel::Weighted_point_2& pw, + const Kernel::Weighted_point_2& qw, + const Kernel::Weighted_point_2& rw) const; + + Kernel::FT operator() (const Kernel::Weighted_point_2& pw, + const Kernel::Weighted_point_2& qw) const; + + Kernel::FT operator() (const Kernel::Weighted_point_2& pw) const; + + /// @} +}; /* end Kernel::ComputeSquaredRadiusSmallestOrthogonalCircle_2 */ + +/*! +\ingroup PkgKernel23ConceptsFunctionObjects +\cgalConcept + +\sa `CGAL::Weighted_point_3` +\sa `ComputePowerProduct_3` for the definition of orthogonal sphere + +\cgalRefines `AdaptableFunctor` + +*/ +class ComputeSquaredRadiusSmallestOrthogonalSphere_3 { +public: + /// \name Operations + /// A model of this concept must provide: + /// @{ + + /*! + returns the squared radius of the + smallest sphere orthogonal to the argument(s). + */ + Kernel::FT operator() (const Kernel::Weighted_point_3& pw, + const Kernel::Weighted_point_3& qw, + const Kernel::Weighted_point_3& rw, + const Kernel::Weighted_point_3& sw) const; + + Kernel::FT operator() (const Kernel::Weighted_point_3& pw, + const Kernel::Weighted_point_3& qw, + const Kernel::Weighted_point_3& rw) const; + + Kernel::FT operator() (const Kernel::Weighted_point_3& pw, + const Kernel::Weighted_point_3& qw) const; + + Kernel::FT operator() (const Kernel::Weighted_point_3& pw) const; + + /// @} +}; /* end Kernel::ComputeSquaredRadiusSmallestOrthogonalSphere_3 */ + /*! \ingroup PkgKernel23ConceptsFunctionObjects \cgalConcept diff --git a/Kernel_23/doc/Kernel_23/Concepts/GeomObjects.h b/Kernel_23/doc/Kernel_23/Concepts/GeomObjects.h index 29eb609b587..8c37f2fde31 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/GeomObjects.h +++ b/Kernel_23/doc/Kernel_23/Concepts/GeomObjects.h @@ -790,6 +790,7 @@ A type representing weighted points in two dimensions. \sa `ConstructWeightedPoint_2` \sa `ComparePowerDistance_2` +\sa `ComputeSquaredRadiusSmallestOrthogonalCircle_2` \sa `ConstructRadicalAxis_2` \sa `ConstructWeightedCircumcenter_2` \sa `PowerSideOfOrientedPowerCircle_2` diff --git a/Kernel_23/doc/Kernel_23/Concepts/Kernel.h b/Kernel_23/doc/Kernel_23/Concepts/Kernel.h index a28102de64d..ee60f94ec74 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/Kernel.h +++ b/Kernel_23/doc/Kernel_23/Concepts/Kernel.h @@ -527,6 +527,11 @@ public: */ typedef unspecified_type Compute_squared_radius_2; + /*! + a model of `Kernel::ComputeSquaredRadiusSmallestOrthogonalCircle_2` + */ + typedef unspecified_type Compute_squared_radius_smallest_orthogonal_circle_2; + /*! a model of `Kernel::ComputeArea_2` */ diff --git a/Kernel_23/doc/Kernel_23/PackageDescription.txt b/Kernel_23/doc/Kernel_23/PackageDescription.txt index eac34bf9a9f..82835327897 100644 --- a/Kernel_23/doc/Kernel_23/PackageDescription.txt +++ b/Kernel_23/doc/Kernel_23/PackageDescription.txt @@ -321,6 +321,7 @@ - `Kernel::ComputeSquaredLengthDividedByPiSquare_3` - `Kernel::ComputeSquaredRadius_2` - `Kernel::ComputeSquaredRadius_3` +- `Kernel::ComputeSquaredRadiusSmallestOrthogonalCircle_2` - `Kernel::ComputeSquaredRadiusSmallestOrthogonalSphere_3` - `Kernel::ComputeVolume_3` - `Kernel::ComputeWeight_2` diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index 01df5baaadb..12b35259091 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -538,6 +538,37 @@ public: }; +template < typename K > +class Compute_squared_radius_smallest_orthogonal_circle_2 +{ +public: + typedef typename K::Weighted_point_2 Weighted_point_2; + typedef typename K::FT FT; + + typedef FT result_type; + + FT operator()(const Weighted_point_2& p, + const Weighted_point_2& q, + const Weighted_point_2& r) const + { + return squared_radius_orthogonal_circleC2(p.x(), p.y(), p.weight(), + q.x(), q.y(), q.weight(), + r.x(), r.y(), r.weight()); + } + + FT operator()(const Weighted_point_2& p, + const Weighted_point_2& q) const + { + return squared_radius_smallest_orthogonal_circleC2(p.x(), p.y(), p.weight(), + q.x(), q.y(), q.weight()); + } + + FT operator()(const Weighted_point_2& p) const + { + return - p.weight(); + } +}; + template < typename K > class Compute_squared_radius_smallest_orthogonal_sphere_3 { diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index 3d47d12099c..0f770919989 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -1069,6 +1069,33 @@ squared_radius(const Point_2& p, const Point_2& q, const Point_2& r) return internal::squared_radius(p, q, r, K()); } +template < class K > +inline +typename K::FT +squared_radius_smallest_orthogonal_circle(const Weighted_point_2 &p) +{ + return internal::squared_radius_smallest_orthogonal_circle(p, K()); +} + +template < class K > +inline +typename K::FT +squared_radius_smallest_orthogonal_circle(const Weighted_point_2 &p, + const Weighted_point_2 &q) +{ + return internal::squared_radius_smallest_orthogonal_circle(p, q, K()); +} + +template < class K > +inline +typename K::FT +squared_radius_smallest_orthogonal_circle(const Weighted_point_2 &p, + const Weighted_point_2 &q, + const Weighted_point_2 &r) +{ + return internal::squared_radius_smallest_orthogonal_circle(p, q, r, K()); +} + template < class K > inline typename K::Point_2 diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h index 44abff3c9f7..f4e8ad55691 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -970,6 +970,36 @@ squared_radius(const typename K::Point_2 &p, return k.compute_squared_radius_2_object()(p, q, r); } +template < class K > +inline +typename K::FT +squared_radius_smallest_orthogonal_circle(const typename K::Weighted_point_2 &p, + const K &k) +{ + return k.compute_squared_radius_smallest_orthogonal_circle_2_object()(p); +} + +template < class K > +inline +typename K::FT +squared_radius_smallest_orthogonal_circle(const typename K::Weighted_point_2 &p, + const typename K::Weighted_point_2 &q, + const K &k) +{ + return k.compute_squared_radius_smallest_orthogonal_circle_2_object()(p, q); +} + +template < class K > +inline +typename K::FT +squared_radius_smallest_orthogonal_circle(const typename K::Weighted_point_2 &p, + const typename K::Weighted_point_2 &q, + const typename K::Weighted_point_2 &r, + const K &k) +{ + return k.compute_squared_radius_smallest_orthogonal_circle_2_object()(p, q, r); +} + template < class K > inline typename K::Point_2 diff --git a/Kernel_23/include/CGAL/Kernel/interface_macros.h b/Kernel_23/include/CGAL/Kernel/interface_macros.h index 4099c70f652..de1802ce0bc 100644 --- a/Kernel_23/include/CGAL/Kernel/interface_macros.h +++ b/Kernel_23/include/CGAL/Kernel/interface_macros.h @@ -300,6 +300,8 @@ CGAL_Kernel_cons(Construct_weighted_circumcenter_3, construct_weighted_circumcenter_3_object) CGAL_Kernel_cons(Compute_power_product_3, compute_power_product_3_object) +CGAL_Kernel_cons(Compute_squared_radius_smallest_orthogonal_circle_2, + compute_squared_radius_smallest_orthogonal_circle_2_object) CGAL_Kernel_cons(Compute_squared_radius_smallest_orthogonal_sphere_3, compute_squared_radius_smallest_orthogonal_sphere_3_object) CGAL_Kernel_cons(Compute_power_distance_to_power_sphere_3, diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_weighted_point_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_weighted_point_2.h index 3bf609d0e69..ac695e5d282 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_weighted_point_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_weighted_point_2.h @@ -69,6 +69,13 @@ _test_fct_weighted_point_2(const R& ) CGAL::Weighted_point_2 wp8_b( p8, 6); CGAL::Weighted_point_2 wp10_b( p10, -8); + CGAL::Point_2 p_00(RT(0), RT(0) ); // 0, 0 + CGAL::Point_2 p_10(RT(4), RT(0), RT(1) ); // 4,0 + CGAL::Point_2 p_01(RT(0), RT(5), RT(1) ); // 0,5 + CGAL::Weighted_point_2 wp_00( p_00, RT(0) ); + CGAL::Weighted_point_2 wp_10( p_10, RT(16) ); + CGAL::Weighted_point_2 wp_01( p_01, RT(25) ); + assert( CGAL::compare_power_distance(p1, wp1, wp1) == CGAL::compare_distance(p1, p1, p1)); assert( CGAL::compare_power_distance(p1, wp2, wp4) == CGAL::compare_distance(p1, p2, p4)); @@ -109,6 +116,22 @@ _test_fct_weighted_point_2(const R& ) assert(power_side_of_oriented_power_circle(wp1_b, wp4_b, wp5_b, wp5_b) == CGAL::ON_ORIENTED_BOUNDARY ); assert(power_side_of_oriented_power_circle(wp1_b, wp4_b, wp5_b, wp6_b) == CGAL::ON_NEGATIVE_SIDE ); + std::cout << "."; + + assert( CGAL::squared_radius_smallest_orthogonal_circle(wp1) == RT(0) ); + assert( CGAL::squared_radius_smallest_orthogonal_circle(wp1_b) == -wp1_b.weight() ); + + std::cout << CGAL::squared_radius_smallest_orthogonal_circle(wp1_b, wp3_b) << std::endl; + + assert( CGAL::squared_radius_smallest_orthogonal_circle(wp3, wp8) == RT(1) ); + assert( CGAL::squared_radius_smallest_orthogonal_circle(wp1_b, wp3_b) == RT(-3)); + + std::cout << CGAL::weighted_circumcenter(wp_00, wp_10, wp_01) << std::endl; + + assert( CGAL::squared_radius_smallest_orthogonal_circle(wp1, wp3, wp5) + == CGAL::squared_radius(p1, p3, p5)); + assert( CGAL::squared_radius_smallest_orthogonal_circle(wp_00, wp_10, wp_01) == RT(0)); + std::cout << "done" << std::endl; return true; } diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h index 9baa8d6dab0..90629f8c9f5 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_new_2.h @@ -387,6 +387,14 @@ test_new_2(const R& rep) tmp23b = Compute_squared_radius(p3, p4); tmp23b = Compute_squared_radius(p3, p4, p5); + typename R::Compute_squared_radius_smallest_orthogonal_circle_2 + compute_squared_radius_smallest_orthogonal_circle + = rep.compute_squared_radius_smallest_orthogonal_circle_2_object(); + tmp23b = compute_squared_radius_smallest_orthogonal_circle(wp4); + tmp23b = compute_squared_radius_smallest_orthogonal_circle(wp4, wp5); + tmp23b = compute_squared_radius_smallest_orthogonal_circle(wp4, wp5, wp6); + (void) tmp23b; + typename R::Equal_2 equal = rep.equal_2_object(); bool tmp24 = equal(p2,p3);