function_objects.h

来自「CGAL is a collaborative effort of severa」· C头文件 代码 · 共 2,231 行 · 第 1/5 页

H
2,231
字号
// Copyright (c) 1999-2004  Utrecht University (The Netherlands),// ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),// and Tel-Aviv University (Israel).  All rights reserved.//// This file is part of CGAL (www.cgal.org); you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public License as// published by the Free Software Foundation; version 2.1 of the License.// See the file LICENSE.LGPL distributed with CGAL.//// Licensees holding a valid commercial license may use this file in// accordance with the commercial license agreement provided with the software.//// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.//// $Source: /CVSROOT/CGAL/Packages/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h,v $// $Revision: 1.41 $ $Date: 2004/06/23 03:33:16 $// $Name:  $//// Author(s)     : Stefan Schirra, Sylvain Pion, Michael Hoffmann#ifndef CGAL_CARTESIAN_FUNCTION_OBJECTS_H#define CGAL_CARTESIAN_FUNCTION_OBJECTS_H#include <CGAL/Kernel/function_objects.h>#include <CGAL/predicates/kernel_ftC2.h>#include <CGAL/predicates/kernel_ftC3.h>#include <CGAL/constructions/kernel_ftC2.h>#include <CGAL/constructions/kernel_ftC3.h>#include <CGAL/Cartesian/solve_3.h>CGAL_BEGIN_NAMESPACEnamespace CartesianKernelFunctors {  using namespace CommonKernelFunctors;  template <typename K>  class Angle_2  {    typedef typename K::Point_2 Point_2;  public:    typedef Angle            result_type;    typedef Arity_tag< 3 >   Arity;    Angle    operator()(const Point_2& p, const Point_2& q, const Point_2& r) const    { return angleC2(p.x(), p.y(), q.x(), q.y(), r.x(), r.y()); }  };  template <typename K>  class Angle_3  {    typedef typename K::Point_3 Point_3;  public:    typedef Angle            result_type;    typedef Arity_tag< 3 >   Arity;    Angle    operator()(const Point_3& p, const Point_3& q, const Point_3& r) const    {       return angleC3(p.x(), p.y(), p.z(),		     q.x(), q.y(), q.z(),		     r.x(), r.y(), r.z());    }  };  template <typename K>  class Are_parallel_2  {    typedef typename K::Line_2          Line_2;    typedef typename K::Segment_2       Segment_2;    typedef typename K::Ray_2           Ray_2;    public:    typedef bool             result_type;    typedef Arity_tag< 2 >   Arity;    bool    operator()(const Line_2& l1, const Line_2& l2) const    { return parallelC2(l1.a(), l1.b(), l2.a(), l2.b()); }    bool    operator()(const Segment_2& s1, const Segment_2& s2) const    { return parallelC2(s1.source().x(), s1.source().y(),                        s1.target().x(), s1.target().y(),                        s2.source().x(), s2.source().y(),                        s2.target().x(), s2.target().y());    }    bool    operator()(const Ray_2& r1, const Ray_2& r2) const    { return parallelC2(r1.source().x(), r1.source().y(),                        r1.second_point().x(), r1.second_point().y(),                        r2.source().x(), r2.source().y(),                        r2.second_point().x(), r2.second_point().y());    }  };  template <typename K>  class Are_parallel_3  {    typedef typename K::Line_3          Line_3;    typedef typename K::Segment_3       Segment_3;    typedef typename K::Ray_3           Ray_3;    typedef typename K::Plane_3         Plane_3;    public:    typedef bool             result_type;    typedef Arity_tag< 2 >   Arity;    bool    operator()(const Line_3& l1, const Line_3& l2) const    { return parallelC3(                l1.to_vector().x(), l1.to_vector().y(), l1.to_vector().z(),                l2.to_vector().x(), l2.to_vector().y(), l2.to_vector().z());    }    bool    operator()(const Plane_3& h1, const Plane_3& h2) const    { return parallelC3(h1.a(), h1.b(), h1.c(),                        h2.a(), h2.b(), h2.c());    }    bool    operator()(const Segment_3& s1, const Segment_3& s2) const    { return parallelC3(s1.source().x(), s1.source().y(), s1.source().z(),                        s1.target().x(), s1.target().y(), s1.target().z(),                        s2.source().x(), s2.source().y(), s2.source().z(),                        s2.target().x(), s2.target().y(), s2.target().z());    }    bool    operator()(const Ray_3& r1, const Ray_3& r2) const    { return parallelC3(r1.source().x(), r1.source().y(), r1.source().z(),	r1.second_point().x(), r1.second_point().y(), r1.second_point().z(),                        r2.source().x(), r2.source().y(), r2.source().z(),	r2.second_point().x(), r2.second_point().y(), r2.second_point().z());    }  };  template <typename K>  class Bounded_side_3  {    typedef typename K::FT              FT;    typedef typename K::Point_3         Point_3;    typedef typename K::Sphere_3        Sphere_3;    typedef typename K::Tetrahedron_3   Tetrahedron_3;    typedef typename K::Iso_cuboid_3    Iso_cuboid_3;  public:    typedef Bounded_side     result_type;    typedef Arity_tag< 2 >   Arity;    Bounded_side    operator()( const Sphere_3& s, const Point_3& p) const    { return s.bounded_side(p); }    Bounded_side    operator()( const Tetrahedron_3& t, const Point_3& p) const    {      FT alpha, beta, gamma;      solve(t.vertex(1)-t.vertex(0),            t.vertex(2)-t.vertex(0),            t.vertex(3)-t.vertex(0),            p - t.vertex(0), alpha, beta, gamma);      if (   (alpha < 0) || (beta < 0) || (gamma < 0)          || (alpha + beta + gamma > 1) )          return ON_UNBOUNDED_SIDE;      if (   (alpha == 0) || (beta == 0) || (gamma == 0)          || (alpha+beta+gamma == 1) )        return ON_BOUNDARY;      return ON_BOUNDED_SIDE;    }    Bounded_side    operator()( const Iso_cuboid_3& c, const Point_3& p) const    { return c.bounded_side(p); }  };  template <typename K>  class Collinear_are_ordered_along_line_2  {    typedef typename K::Point_2         Point_2;#ifdef CGAL_kernel_exactness_preconditions     typedef typename K::Collinear_2 Collinear_2;    Collinear_2 c;#endif // CGAL_kernel_exactness_preconditions   public:    typedef bool             result_type;    typedef Arity_tag< 3 >   Arity;#ifdef CGAL_kernel_exactness_preconditions     Collinear_are_ordered_along_line_2() {}    Collinear_are_ordered_along_line_2(const Collinear_2& c_) : c(c_) {}#endif // CGAL_kernel_exactness_preconditions     bool    operator()(const Point_2& p, const Point_2& q, const Point_2& r) const    {      CGAL_kernel_exactness_precondition( c(p, q, r) );      return collinear_are_ordered_along_lineC2	(p.x(), p.y(), q.x(), q.y(), r.x(), r.y());    }  };  template <typename K>  class Collinear_are_ordered_along_line_3  {    typedef typename K::Point_3         Point_3;#ifdef CGAL_kernel_exactness_preconditions     typedef typename K::Collinear_3 Collinear_3;    Collinear_3 c;#endif // CGAL_kernel_exactness_preconditions   public:    typedef bool             result_type;    typedef Arity_tag< 3 >   Arity;#ifdef CGAL_kernel_exactness_preconditions     Collinear_are_ordered_along_line_3() {}    Collinear_are_ordered_along_line_3(const Collinear_3& c_) : c(c_) {}#endif // CGAL_kernel_exactness_preconditions     bool    operator()(const Point_3& p, const Point_3& q, const Point_3& r) const    {      CGAL_kernel_exactness_precondition( c(p, q, r) );      return collinear_are_ordered_along_lineC3(p.x(), p.y(), p.z(),						q.x(), q.y(), q.z(),						r.x(), r.y(), r.z());    }    };  template <typename K>  class Collinear_are_strictly_ordered_along_line_2  {    typedef typename K::Point_2         Point_2;#ifdef CGAL_kernel_exactness_preconditions     typedef typename K::Collinear_2 Collinear_2;    Collinear_2 c;#endif // CGAL_kernel_exactness_preconditions   public:    typedef bool             result_type;    typedef Arity_tag< 3 >   Arity;#ifdef CGAL_kernel_exactness_preconditions     Collinear_are_strictly_ordered_along_line_2() {}    Collinear_are_strictly_ordered_along_line_2(const Collinear_2& c_) : c(c_)     {}#endif // CGAL_kernel_exactness_preconditions     bool    operator()(const Point_2& p, const Point_2& q, const Point_2& r) const    {      CGAL_kernel_exactness_precondition( c(p, q, r) );      return collinear_are_strictly_ordered_along_lineC2	(p.x(), p.y(), q.x(), q.y(), r.x(), r.y());    }  };  template <typename K>  class Collinear_are_strictly_ordered_along_line_3  {    typedef typename K::Point_3         Point_3;#ifdef CGAL_kernel_exactness_preconditions     typedef typename K::Collinear_3 Collinear_3;    Collinear_3 c;#endif // CGAL_kernel_exactness_preconditions   public:    typedef bool             result_type;    typedef Arity_tag< 3 >   Arity;#ifdef CGAL_kernel_exactness_preconditions     Collinear_are_strictly_ordered_along_line_3() {}    Collinear_are_strictly_ordered_along_line_3(const Collinear_3& c_) : c(c_)    {}#endif // CGAL_kernel_exactness_preconditions     bool    operator()(const Point_3& p, const Point_3& q, const Point_3& r) const    {      CGAL_kernel_exactness_precondition( c(p, q, r) );      return collinear_are_strictly_ordered_along_lineC3(p.x(), p.y(), p.z(),							 q.x(), q.y(), q.z(),							 r.x(), r.y(), r.z());    }    };  template <typename K>  class Collinear_has_on_2  {    typedef typename K::Point_2               Point_2;    typedef typename K::Ray_2                 Ray_2;    typedef typename K::Segment_2             Segment_2;    typedef typename K::Construct_point_on_2  Construct_point_on_2;    typedef typename K::Compare_x_2           Compare_x_2;    typedef typename K::Compare_y_2           Compare_y_2;    typedef typename K::Collinear_are_ordered_along_line_2      Collinear_are_ordered_along_line_2;    Construct_point_on_2 cp;    Compare_x_2 cx;    Compare_y_2 cy;    Collinear_are_ordered_along_line_2 co;  public:    typedef bool             result_type;    typedef Arity_tag< 2 >   Arity;    Collinear_has_on_2() {}    Collinear_has_on_2(const Construct_point_on_2& cp_,		       const Compare_x_2& cx_,		       const Compare_y_2& cy_,		       const Collinear_are_ordered_along_line_2& co_)       : cp(cp_), cx(cx_), cy(cy_), co(co_)    {}    bool    operator()( const Ray_2& r, const Point_2& p) const    {      Point_2 source = cp(r,0);            Point_2 second = cp(r,1);      switch(cx(source, second)) {      case SMALLER:        return cx(source, p) != LARGER;      case LARGER:        return cx(p, source) != LARGER;      default:        switch(cy(source, second)){        case SMALLER:	  return cy(source, p) != LARGER;        case LARGER:	  return cy(p, source) != LARGER;        default:	  return true; // p == source        }      } // switch    }      bool    operator()( const Segment_2& s, const Point_2& p) const    {       return co(cp(s,0), p, cp(s,1));    }  };  template <typename K>  class Collinear_2  {    typedef typename K::Point_2        Point_2;    typedef typename K::Orientation_2  Orientation_2;    Orientation_2 o;  public:    typedef bool             result_type;    typedef Arity_tag< 3 >   Arity;    Collinear_2() {}    Collinear_2(const Orientation_2 o_) : o(o_) {}    bool    operator()(const Point_2& p, const Point_2& q, const Point_2& r) const    { return o(p, q, r) == COLLINEAR; }  };  template <typename K>  class Collinear_3  {    typedef typename K::Point_3    Point_3;  public:    typedef bool             result_type;    typedef Arity_tag< 3 >   Arity;    bool    operator()(const Point_3& p, const Point_3& q, const Point_3& r) const    {      return collinearC3(p.x(), p.y(), p.z(),			 q.x(), q.y(), q.z(),			 r.x(), r.y(), r.z());    }  };  template <typename K>  class Compare_angle_with_x_axis_2  {    typedef typename K::Direction_2  Direction_2;  public:    typedef Comparison_result        result_type;    typedef Arity_tag< 2 >           Arity;    Comparison_result    operator()(const Direction_2& d1, const Direction_2& d2) const    {      return compare_angle_with_x_axisC2(d1.dx(), d1.dy(), d2.dx(), d2.dy());    }  };  template <typename K>  class Compare_distance_2  {    typedef typename K::Point_2   Point_2;  public:    typedef Comparison_result     result_type;    typedef Arity_tag< 3 >        Arity;    Comparison_result    operator()(const Point_2& p, const Point_2& q, const Point_2& r) const    {      return cmp_dist_to_pointC2(p.x(), p.y(), q.x(), q.y(), r.x(), r.y());    }  };  template <typename K>  class Compare_distance_3  {    typedef typename K::Point_3   Point_3;  public:    typedef Comparison_result     result_type;    typedef Arity_tag< 3 >        Arity;    Comparison_result    operator()(const Point_3& p, const Point_3& q, const Point_3& r) const    {       return cmp_dist_to_pointC3(p.x(), p.y(), p.z(),				 q.x(), q.y(), q.z(),				 r.x(), r.y(), r.z());    }  };  template <typename K>  class Compare_slope_2  {    typedef typename K::Line_2     Line_2;    typedef typename K::Segment_2  Segment_2;  public:    typedef Comparison_result      result_type;    typedef Arity_tag< 2 >         Arity;    Comparison_result    operator()(const Line_2& l1, const Line_2& l2) const    {       return compare_slopesC2(l1.a(), l1.b(), l2.a(), l2.b());    }    Comparison_result    operator()(const Segment_2& s1, const Segment_2& s2) const

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?