svd_voronoi_vertex_sqrt_field_h2.h
来自「CGAL is a collaborative effort of severa」· C头文件 代码 · 共 1,028 行 · 第 1/2 页
H
1,028 行
RT a[3], b[3], c[3]; RT cx[3], cy[3], cz[3], sqrt_D[3]; orient_lines(p, q, r, a, b, c); for (int i = 0; i < 3; i++) { cx[i] = c[(i+1)%3] * b[(i+2)%3] - c[(i+2)%3] * b[(i+1)%3]; cy[i] = -(c[(i+1)%3] * a[(i+2)%3] - c[(i+2)%3] * a[(i+1)%3]); cz[i] = -(a[(i+1)%3] * b[(i+2)%3] - a[(i+2)%3] * b[(i+1)%3]); RT d = CGAL::square(a[i]) + CGAL::square(b[i]); sqrt_D[i] = CGAL::sqrt(d); } ux = cx[0] * sqrt_D[0] + cx[1] * sqrt_D[1] + cx[2] * sqrt_D[2]; uy = cy[0] * sqrt_D[0] + cy[1] * sqrt_D[1] + cy[2] * sqrt_D[2]; uz = cz[0] * sqrt_D[0] + cz[1] * sqrt_D[1] + cz[2] * sqrt_D[2]; } //-------------------------------------------------------------------------- void compute_vertex(const Site_2& s1, const Site_2& s2, const Site_2& s3) { if ( s1.is_point() && s2.is_point() && s3.is_point() ) { compute_ppp(s1.point(), s2.point(), s3.point()); } else if ( s1.is_segment() && s2.is_point() && s3.is_point() ) { compute_vertex(s2, s3, s1); pps_idx = 1; } else if ( s1.is_point() && s2.is_segment() && s3.is_point() ) { compute_vertex(s3, s1, s2); pps_idx = 2; } else if ( s1.is_point() && s2.is_point() && s3.is_segment() ) { compute_pps(s1.point(), s2.point(), s3.segment()); pps_idx = 0; } else if ( s1.is_point() && s2.is_segment() && s3.is_segment() ) { compute_pss(s1.point(), s2.segment(), s3.segment()); } else if ( s1.is_segment() && s2.is_point() && s3.is_segment() ) { compute_vertex(s2, s3, s1); } else if ( s1.is_segment() && s2.is_segment() && s3.is_point() ) { compute_vertex(s3, s1, s2); } else { compute_sss(s1.segment(), s2.segment(), s3.segment()); } } //-------------------------------------------------------------------------- bool are_identical(const Point_2& p, const Point_2& q) const { return (p == q); } //-------------------------------------------------------------------------- bool is_endpoint_of(const Point_2& p, const Segment_2& s) const { return ( are_identical(p, s.source()) || are_identical(p, s.target()) ); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // the incircle test //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // the incircle test when the fourth site is a point //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- Sign check_easy_degeneracies(const Point_2& t, PPS_Type, bool& use_result) const { use_result = false; if ( ( p_.is_point() && are_identical(p_.point(),t) ) || ( q_.is_point() && are_identical(q_.point(),t) ) || ( r_.is_point() && are_identical(r_.point(),t) ) ) { use_result = true; return ZERO; } if ( ( p_.is_segment() && is_endpoint_of(t, p_.segment()) ) || ( q_.is_segment() && is_endpoint_of(t, q_.segment()) ) || ( r_.is_segment() && is_endpoint_of(t, r_.segment()) ) ) { use_result = true; return POSITIVE; } return ZERO; } Sign check_easy_degeneracies(const Point_2& t, PSS_Type, bool& use_result) const { return check_easy_degeneracies(t, PPS_Type(), use_result); } Sign check_easy_degeneracies(const Point_2& t, SSS_Type, bool& use_result) const { use_result = false; // ADD THE CASES WHERE t IS AN ENDPOINT OF ONE OF THE SEGMENTS return ZERO; } //-------------------------------------------------------------------------- Sign incircle(const Point_2& t, PPP_Type) const { Oriented_side os = side_of_oriented_circle(p_.point(), q_.point(), r_.point(), t); if ( os == ON_POSITIVE_SIDE ) { return NEGATIVE; } if ( os == ON_NEGATIVE_SIDE ) { return POSITIVE; } return ZERO; } //-------------------------------------------------------------------------- template<class Type> Sign incircle(const Point_2& t, Type type) const { bool use_result(false); Sign s = check_easy_degeneracies(t, type, use_result); if ( use_result ) { return s; } FT r2 = squared_radius(); FT d2 = CGAL::square(x() - t.x()) + CGAL::square(y() - t.y()); return Sign( CGAL::compare(d2, r2) ); } //-------------------------------------------------------------------------- Sign incircle(const Point_2& t) const { if ( is_degenerate_Voronoi_circle() ) { return POSITIVE; } Sign s(ZERO); switch ( v_type ) { case PPP: s = incircle(t, PPP_Type()); break; case PPS: s = incircle(t, PPS_Type()); break; case PSS: s = incircle(t, PSS_Type()); break; case SSS: s = incircle(t, SSS_Type()); break; } return s; } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // the incircle test when the fourth site is a segment //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- Oriented_side oriented_side(const Line_2& l, const Point_2& p) const { Line_2 l1(l.b() * hw(), -l.a() * hw(), l.a() * hy() - l.b() * hx()); if ( hw() < 0 ) { l1 = Line_2(-l1.a(), -l1.b(), -l1.c()); } return oriented_side_of_line(l1, p); } Sign incircle(const Line_2& l) const { FT r2 = squared_radius(); FT n2 = CGAL::square(l.a()) + CGAL::square(l.b()); FT d2 = CGAL::square(l.a() * x() + l.b() * y() + l.c()); return Sign( CGAL::compare(d2, r2 * n2) ); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- Sign incircle1(const Segment_2& t) const { if ( v_type == PPP || v_type == PPS ) { if ( p_.is_point() && q_.is_point() && is_endpoint_of(p_.point(), t) && is_endpoint_of(q_.point(), t) ) { return NEGATIVE; } if ( p_.is_point() && r_.is_point() && is_endpoint_of(p_.point(), t) && is_endpoint_of(r_.point(), t) ){ return NEGATIVE; } if ( q_.is_point() && r_.is_point() && is_endpoint_of(q_.point(), t) && is_endpoint_of(r_.point(), t) ){ return NEGATIVE; } } Sign d1, d2; if ( ( p_.is_point() && are_identical(p_.point(), t.source()) ) || ( q_.is_point() && are_identical(q_.point(), t.source()) ) || ( r_.is_point() && are_identical(r_.point(), t.source()) ) ) { d1 = ZERO; } else { d1 = incircle(t.source()); } if ( d1 == NEGATIVE ) { return NEGATIVE; } if ( ( p_.is_point() && are_identical(p_.point(), t.target()) ) || ( q_.is_point() && are_identical(q_.point(), t.target()) ) || ( r_.is_point() && are_identical(r_.point(), t.target()) ) ) { d2 = ZERO; } else { d2 = incircle(t.target()); } if ( d2 == NEGATIVE ) { return NEGATIVE; } Line_2 l = compute_supporting_line(t); Sign sl = incircle(l); // this is the old code if ( sl == POSITIVE ) { return sl; } Oriented_side os1 = oriented_side(l, t.source()); Oriented_side os2 = oriented_side(l, t.target()); if ( sl == ZERO ) { if ( (os1 == ON_POSITIVE_SIDE && os2 == ON_NEGATIVE_SIDE) || (os1 == ON_NEGATIVE_SIDE && os2 == ON_POSITIVE_SIDE) ) { return ZERO; } return POSITIVE; } return (os1 == os2) ? POSITIVE : NEGATIVE; } //-------------------------------------------------------------------------- Sign incircle(const Segment_2& t) const { if ( is_degenerate_Voronoi_circle() ) { // case 1: the new segment is not adjacent to the center of the // degenerate Voronoi circle if ( !are_identical( p_ref(), t.source() ) && !are_identical( p_ref(), t.target() ) ) { return POSITIVE; } if ( ( r_.is_point() && are_identical(p_ref(),r_.point()) ) || ( q_.is_point() && are_identical(p_ref(),q_.point()) ) || ( p_.is_point() && are_identical(p_ref(),p_.point()) ) ) { Point_2 pr; Segment_2 sp, sq; if ( p_.is_point() ) { CGAL_assertion( q_.is_segment() && r_.is_segment() ); pr = p_.point(); sp = q_.segment(); sq = r_.segment(); } else if ( q_.is_point() ) { CGAL_assertion( r_.is_segment() && p_.is_segment() ); pr = q_.point(); sp = r_.segment(); sq = p_.segment(); } else { CGAL_assertion( p_.is_segment() && q_.is_segment() ); pr = r_.point(); sp = p_.segment(); sq = q_.segment(); } Point_2 pq = sq.source(), pp = sp.source(), pt = t.source(); if ( are_identical(sp.source(),pr) ) { pp = sp.target(); } if ( are_identical(sq.source(),pr) ) { pq = sq.target(); } if ( are_identical( t.source(),pr) ) { pt = t.target(); } 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 = incircle1(t); 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_.point(), q_.segment()) && is_endpoint_of(p_.point(), r_.segment()) ); } else if ( q_.is_point() ) { return ( is_endpoint_of(q_.point(), p_.segment()) && is_endpoint_of(q_.point(), r_.segment()) ); } else { CGAL_assertion( r_.is_point() ); return ( is_endpoint_of(r_.point(), p_.segment()) && is_endpoint_of(r_.point(), q_.segment()) ); } } //--------------------------------------------------------------------------private: //-------------------------------------------------------------------------- // the reference point (valid if v_type != SSS) //-------------------------------------------------------------------------- const Point_2& p_ref() const { CGAL_precondition ( v_type != SSS ); if ( v_type == PPS ) { if ( pps_idx == 0 ) { return p_.point(); } if ( pps_idx == 1 ) { return q_.point(); } return r_.point(); } if ( p_.is_point() ) { return p_.point(); } else if ( q_.is_point() ) { return q_.point(); } else { CGAL_assertion( r_.is_point() ); return r_.point(); } }public: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // access methods //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- FT x() const { return FT(hx()) / FT(hw()); } FT y() const { return FT(hy()) / FT(hw()); } RT hx() const { return ux; } RT hy() const { return uy; } RT hw() const { return uz; } FT squared_radius() const { switch (v_type) { case PPP: case PPS: case PSS: { FT dx2 = CGAL::square(x() - p_ref().x()); FT dy2 = CGAL::square(y() - p_ref().y()); return dx2 + dy2; } break; case SSS: { Line_2 l = compute_supporting_line(p_.segment()); 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 p_ref(); } return Point_2(hx(), hy(), hw()); } Point_2 degenerate_point() const { CGAL_precondition( is_degenerate_Voronoi_circle() ); return p_ref(); } 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: Svd_voronoi_vertex_sqrt_field_H2(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 { if ( t.is_point() ) { return incircle(t.point()); } return incircle(t.segment()); } //-------------------------------------------------------------------------- Orientation orientation(const Line_2& l) const { Sign s_w = CGAL::sign( hw() ); Sign s1 = CGAL::sign(l.a() * hx() + l.b() * hy() + l.c() * hw()); Sign s = Sign(s1 * s_w); if ( s == ZERO ) { return COLLINEAR; } return ( s == POSITIVE ) ? LEFT_TURN : RIGHT_TURN; } 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; RT ux, uy, uz;};CGAL_END_NAMESPACE#endif // CGAL_SEGMENT_VORONOI_DIAGRAM_VORONOI_VEFTEX_SQRT_FIELD_H2_H
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?