⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voronoi_vertex_ring_c2.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 3 页
字号:
    if ( cr == SMALLER ) { return NEGATIVE; }    return ZERO;  }  //--------------------------------------------------------------------------  Sign incircle(const Line_2& l, PPS_Type) const  {    Point_2 pref = p_ref().point();    Sqrt_1 vx = ux_pps - pref.x() * uz_pps;    Sqrt_1 vy = uy_pps - pref.y() * uz_pps;    Sqrt_1 Rs = CGAL::square(vx) + CGAL::square(vy);        RT Ns = CGAL::square(l.a()) + CGAL::square(l.b());    Sqrt_1 Ls =      CGAL::square(l.a() * ux_pps + l.b() * uy_pps + l.c() * uz_pps);    return CGAL::sign(Ls - Rs * Ns);  }  //--------------------------------------------------------------------------  Sign incircle(const Line_2& l, PSS_Type) const  {    Sqrt_1 Zero(RT(0), RT(0), ux.a().c());    Point_2 pref = p_ref().point();    Sqrt_3 vx = ux - (pref.x() + Zero) * uz;    Sqrt_3 vy = uy - (pref.y() + Zero) * uz;    Sqrt_3 Rs = CGAL::square(vx) + CGAL::square(vy);    Sqrt_1 a = l.a() + Zero;    Sqrt_1 b = l.b() + Zero;    Sqrt_1 c = l.c() + Zero;    Sqrt_1 Ns = CGAL::square(a) + CGAL::square(b);    Sqrt_3 Ls = CGAL::square(a * ux + b * uy + c * uz);    return CGAL::sign(Ls - Rs * Ns);  }  //--------------------------------------------------------------------------  Sign incircle(const Line_2& l, SSS_Type) const  {    Sqrt_1 Zero(RT(0), RT(0), ux.a().c());    RT a1, b1, c1;    compute_supporting_line(p_.supporting_site(), a1, b1, c1);    Sqrt_1 a = a1 + Zero;    Sqrt_1 b = b1 + Zero;    Sqrt_1 c = c1 + Zero;    Sqrt_1 Ns = CGAL::square(a) + CGAL::square(b);    Sqrt_1 la = l.a() + Zero;    Sqrt_1 lb = l.b() + Zero;    Sqrt_1 lc = l.c() + Zero;    Sqrt_1 Ns1 = CGAL::square(la) + CGAL::square(lb);    Sqrt_3 Ls = CGAL::square(a * ux + b * uy + c * uz);    Sqrt_3 Ls1 =      CGAL::square(la * ux + lb * uy + lc * uz);    return CGAL::sign(Ls1 * Ns - Ls * Ns1);  }  //--------------------------------------------------------------------------  //--------------------------------------------------------------------------  template<class Type>  Sign incircle_s(const Site_2& t, Type type) const  {    CGAL_precondition( t.is_segment() );    if ( v_type == PPP || v_type == PPS ) {      if (  p_.is_point() && q_.is_point() &&	    is_endpoint_of(p_, t) && is_endpoint_of(q_, t)  ) {	return NEGATIVE;      }      if (  p_.is_point() && r_.is_point() &&	    is_endpoint_of(p_, t) && is_endpoint_of(r_, t)  ){	return NEGATIVE;      }      if (  q_.is_point() && r_.is_point() &&	    is_endpoint_of(q_, t) && is_endpoint_of(r_, t)  ){	return NEGATIVE;      }    }    if ( v_type == PSS ) {      if ( p_.is_segment() &&	   same_segments(p_.supporting_site(),			 t.supporting_site()) ) {	return POSITIVE;      }      if ( q_.is_segment() &&	   same_segments(q_.supporting_site(),			 t.supporting_site()) ) {	return POSITIVE;      }      if ( r_.is_segment() &&	   same_segments(r_.supporting_site(),			 t.supporting_site()) ) {	return POSITIVE;      }    }    return incircle_s_no_easy(t, type);  }  template<class Type>  Sign incircle_s_no_easy(const Site_2& t, Type type) const  {    Sign d1, d2;    if (  ( p_.is_point() && same_points(p_, t.source_site()) ) ||	  ( q_.is_point() && same_points(q_, t.source_site()) ) ||	  ( r_.is_point() && same_points(r_, t.source_site()) )  ) {      d1 = ZERO;    } else {      d1 = incircle_p(t.source_site());    }    if ( d1 == NEGATIVE ) { return NEGATIVE; }    if (  ( p_.is_point() && same_points(p_, t.target_site()) ) ||	  ( q_.is_point() && same_points(q_, t.target_site()) ) ||	  ( r_.is_point() && same_points(r_, t.target_site()) )  ) {      d2 = ZERO;    } else {      d2 = incircle_p(t.target_site());    }    if ( d2 == NEGATIVE ) { return NEGATIVE; }    Line_2 l = compute_supporting_line(t.supporting_site());    Sign sl = incircle(l, type);    if ( sl == POSITIVE ) { return sl; }    if ( sl == ZERO && (d1 == ZERO || d2 == ZERO) ) { return ZERO; }    Oriented_side os1 = oriented_side(l, t.source(), type);    Oriented_side os2 = oriented_side(l, t.target(), type);    if ( sl == ZERO ) {      if (os1 == ON_ORIENTED_BOUNDARY || os2 == ON_ORIENTED_BOUNDARY) {	return ZERO;      }      return ( os1 == os2 ) ? POSITIVE : ZERO;    }    return (os1 == os2) ? POSITIVE : NEGATIVE;  }  //--------------------------------------------------------------------------    Sign incircle_s(const Site_2& t) const   {    CGAL_precondition( t.is_segment() );    if ( is_degenerate_Voronoi_circle() ) {      // case 1: the new segment is not adjacent to the center of the      //         degenerate Voronoi circle      if (  !same_points( p_ref(), t.source_site() ) &&	    !same_points( p_ref(), t.target_site() )  ) {	return POSITIVE;      }      CGAL_assertion( v_type == PSS );      if ( p_.is_segment() &&	   same_segments(p_.supporting_site(),			 t.supporting_site()) ) {	return ZERO;      }      if ( q_.is_segment() &&	   same_segments(q_.supporting_site(),			 t.supporting_site()) ) {	return ZERO;      }      if ( r_.is_segment() &&	   same_segments(r_.supporting_site(),			 t.supporting_site()) ) {	return ZERO;      }      Site_2 pr;      Site_2 sp, sq;      if ( p_.is_point() ) {	CGAL_assertion( q_.is_segment() && r_.is_segment() );	pr = p_;	sp = q_;	sq = r_;      } else if ( q_.is_point() ) {	CGAL_assertion( r_.is_segment() && p_.is_segment() );	pr = q_;	sp = r_;	sq = p_;      } else {	CGAL_assertion( p_.is_segment() && q_.is_segment() );	pr = r_;	sp = p_;	sq = q_;      }      Point_2 pq = sq.source(), pp = sp.source(), pt = t.source();      if ( same_points(sp.source_site(), pr) ) { pp = sp.target(); }      if ( same_points(sq.source_site(), pr) ) { pq = sq.target(); }      if ( same_points( t.source_site(), pr) ) { pt =  t.target(); }      Point_2 pr_ = pr.point();      if ( CGAL::orientation(pr_, pp, pt) == LEFT_TURN &&	   CGAL::orientation(pr_, pq, pt) == RIGHT_TURN ) {	return NEGATIVE;      }      return ZERO;    } // if ( is_degenerate_Voronoi_circle() )    Sign s(ZERO);    switch ( v_type ) {    case PPP:      s = incircle_s(t, PPP_Type());      break;    case PPS:      s = incircle_s(t, PPS_Type());      break;    case PSS:      s = incircle_s(t, PSS_Type());      break;    case SSS:      s = incircle_s(t, SSS_Type());      break;    }    return s;  }  Sign incircle_s_no_easy(const Site_2& t) const  {    Sign s(ZERO);    switch ( v_type ) {    case PPP:      s = incircle_s_no_easy(t, PPP_Type());      break;    case PPS:      s = incircle_s_no_easy(t, PPS_Type());      break;    case PSS:      s = incircle_s_no_easy(t, PSS_Type());      break;    case SSS:      s = incircle_s_no_easy(t, SSS_Type());      break;    }    return s;  }  //--------------------------------------------------------------------------  //  subpredicates for the incircle test  //--------------------------------------------------------------------------public:  bool is_degenerate_Voronoi_circle() const  {    if ( v_type != PSS ) { return false; }    if ( p_.is_point() ) {      return ( is_endpoint_of(p_, q_) && is_endpoint_of(p_, r_) );    } else if ( q_.is_point() ) {      return ( is_endpoint_of(q_, p_) && is_endpoint_of(q_, r_) );    } else {      CGAL_assertion( r_.is_point() );      return ( is_endpoint_of(r_, p_) && is_endpoint_of(r_, q_) );    }  }  //--------------------------------------------------------------------------private:  //--------------------------------------------------------------------------  //  the reference point (valid if v_type != SSS)  //--------------------------------------------------------------------------  Site_2 p_ref() const  {    CGAL_precondition ( v_type != SSS );    if ( v_type == PPS ) {      if ( pps_idx == 0 ) { return p_; }      if ( pps_idx == 1 ) { return q_; }      return r_;    }    if ( p_.is_point() ) {      return p_;    } else if ( q_.is_point() ) {      return q_;    } else {      CGAL_assertion( r_.is_point() );      return r_;    }  }public:  //--------------------------------------------------------------------------  //--------------------------------------------------------------------------  //                           access methods  //--------------------------------------------------------------------------  //--------------------------------------------------------------------------  inline FT x(Integral_domain_without_division_tag) const {    return CGAL::to_double(hx()) / CGAL::to_double(hw());  }  inline FT y(Integral_domain_without_division_tag) const {    return CGAL::to_double(hy()) / CGAL::to_double(hw());  }  inline FT x(Field_tag) const { return hx() / hw(); }  inline FT y(Field_tag) const { return hy() / hw(); }  inline FT x() const {      typedef Algebraic_structure_traits<FT> AST;      return x(typename AST::Algebraic_category());  }      inline FT y() const {      typedef Algebraic_structure_traits<FT> AST;      return y(typename AST::Algebraic_category());  }  FT hx() const {    if ( v_type == PPP ) { return ux_ppp; }    if ( v_type == PPS ) { return to_ft(ux_pps); }    return to_ft(ux);  }  FT hy() const {    if ( v_type == PPP ) { return uy_ppp; }    if ( v_type == PPS ) { return to_ft(uy_pps); }    return to_ft(uy);  }  FT hw() const {    if ( v_type == PPP ) { return uz_ppp; }    if ( v_type == PPS ) { return to_ft(uz_pps); }    return to_ft(uz);  }  FT squared_radius() const {    switch (v_type) {    case PPP:    case PPS:    case PSS:      {	Point_2 pref = p_ref().point();	FT dx2 = CGAL::square(x() - pref.x());	FT dy2 = CGAL::square(y() - pref.y());	return dx2 + dy2;      }      break;    case SSS:      {	Line_2 l = compute_supporting_line(p_.supporting_site());	Homogeneous_point_2 q = compute_projection(l, point());	FT dx2 = CGAL::square(x() - q.x());	FT dy2 = CGAL::square(y() - q.y());	return dx2 + dy2;      }      break;    default:      return FT(0);    }  }  Point_2 point() const {    if ( is_degenerate_Voronoi_circle() ) {      return degenerate_point();    }        return Point_2(x(), y());  }  Point_2 degenerate_point() const  {    CGAL_precondition( is_degenerate_Voronoi_circle() );    return p_ref().point();  }  typename K::Circle_2 circle() const  {    typedef typename K::Circle_2  K_Circle_2;    return K_Circle_2(point(), squared_radius());  }  vertex_t type() const { return v_type; }public:  Voronoi_vertex_ring_C2(const Site_2& p,			 const Site_2& q,			 const Site_2& r)    : p_(p), q_(q), r_(r)  {    compute_vertex(p, q, r);  }  //--------------------------------------------------------------------------  Sign incircle(const Site_2& t) const   {    Sign s;    if ( t.is_point() ) {      s = incircle_p(t);    } else {      s = incircle_s(t);    }    return s;  }  Sign incircle_no_easy(const Site_2& t) const   {    Sign s;    if ( t.is_point() ) {      s = incircle_p_no_easy(t);    } else {      s = incircle_s_no_easy(t);    }    return s;  }  //--------------------------------------------------------------------------  Orientation orientation(const Line_2& l) const   {    Orientation o(COLLINEAR);    switch ( v_type ) {    case PPP:      o = orientation(l, PPP_Type());      break;    case PPS:      o = orientation(l, PPS_Type());      break;    case PSS:      o = orientation(l, PSS_Type());      break;    case SSS:      o = orientation(l, SSS_Type());      break;    }    return o;  }  Oriented_side oriented_side(const Line_2& l) const  {    Orientation o = orientation(l);    if ( o == COLLINEAR ) { return ON_ORIENTED_BOUNDARY; }    return ( o == LEFT_TURN ) ? ON_POSITIVE_SIDE : ON_NEGATIVE_SIDE;  }  //--------------------------------------------------------------------------private:  const Site_2& p_, q_, r_;  vertex_t v_type;  // index that indicates the refence point for the case PPS  short pps_idx;  // the case ppp  RT ux_ppp, uy_ppp, uz_ppp;  // the case pps  Sqrt_1 ux_pps, uy_pps, uz_pps;  // the case pss and sss  Sqrt_3 ux, uy, uz;};CGAL_SEGMENT_DELAUNAY_GRAPH_2_END_NAMESPACECGAL_END_NAMESPACE#endif // CGAL_SEGMENT_DELAUNAY_GRAPH_2_VORONOI_VERTEX_RING_C2_H

⌨️ 快捷键说明

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