cleaned-up the code for the various segment Voronoi diagram site classes

This commit is contained in:
Menelaos Karavelas 2004-02-18 02:05:50 +00:00
parent 04f6530163
commit 9b9984eab5
6 changed files with 289 additions and 328 deletions

View File

@ -1017,9 +1017,11 @@ insert_intersecting_segment_with_tag(const Storage_site_2& ss,
return v;
}
Storage_site_2 ssx(ss.supporting_segment_handle(),
v->storage_site().supporting_segment_handle());
// Storage_site_2 ssx(ss.supporting_segment_handle(),
// v->storage_site().supporting_segment_handle());
Storage_site_2 ssitev = v->storage_site();
Storage_site_2 ssx( ss.point_handle(0), ss.point_handle(1),
ssitev.point_handle(0), ssitev.point_handle(1) );
Site_2 sitev(v->site());
Site_2 sx(t.point(0), t.point(1), sitev.point(0), sitev.point(1));
@ -1069,15 +1071,20 @@ insert_intersecting_segment_with_tag(const Storage_site_2& ss,
if ( sitev.is_exact(0) ) {
sv1.set_segment(sitev.point(0), sitev.point(1),
t.point(0), t.point(1), true);
ssv1.set_segment(ssitev.supporting_segment_handle(),
ss.supporting_segment_handle(), true);
// ssv1.set_segment(ssitev.supporting_segment_handle(),
// ss.supporting_segment_handle(), true);
ssv1.set_segment(ssitev.point_handle(0), ssitev.point_handle(1),
ss.point_handle(0), ss.point_handle(1), true);
} else {
sv1.set_segment(sitev.point(0), sitev.point(1),
sitev.point(2), sitev.point(3),
t.point(0), t.point(1));
ssv1.set_segment(ssitev.supporting_segment_handle(),
ssitev.crossing_segment_handle(0),
ss.supporting_segment_handle());
// ssv1.set_segment(ssitev.supporting_segment_handle(),
// ssitev.crossing_segment_handle(0),
// ss.supporting_segment_handle());
ssv1.set_segment(ssitev.point_handle(0), ssitev.point_handle(1),
ssitev.point_handle(2), ssitev.point_handle(3),
ss.point_handle(0), ss.point_handle(1));
}
v1->set_site( ssv1 );
@ -1087,15 +1094,20 @@ insert_intersecting_segment_with_tag(const Storage_site_2& ss,
if ( sitev.is_exact(1) ) {
sv2.set_segment(sitev.point(0), sitev.point(1),
t.point(0), t.point(1), false);
ssv2.set_segment(ssitev.supporting_segment_handle(),
ss.supporting_segment_handle(), false);
// ssv2.set_segment(ssitev.supporting_segment_handle(),
// ss.supporting_segment_handle(), false);
ssv2.set_segment(ssitev.point_handle(0), ssitev.point_handle(1),
ss.point_handle(0), ss.point_handle(1), false);
} else {
sv2.set_segment(sitev.point(0), sitev.point(1),
t.point(0), t.point(1),
sitev.point(4), sitev.point(5));
ssv2.set_segment(ssitev.supporting_segment_handle(),
ss.supporting_segment_handle(),
ssitev.crossing_segment_handle(1));
// ssv2.set_segment(ssitev.supporting_segment_handle(),
// ss.supporting_segment_handle(),
// ssitev.crossing_segment_handle(1));
ssv2.set_segment(ssitev.point_handle(0), ssitev.point_handle(1),
ss.point_handle(0), ss.point_handle(1),
ssitev.point_handle(4), ssitev.point_handle(5));
}
v2->set_site( ssv2 );
@ -1109,29 +1121,39 @@ insert_intersecting_segment_with_tag(const Storage_site_2& ss,
if ( t.is_exact(0) ) {
s3.set_segment(t.point(0), t.point(1),
sitev.point(0), sitev.point(1), true);
ss3.set_segment(ss.supporting_segment_handle(),
ssitev.supporting_segment_handle(), true);
// ss3.set_segment(ss.supporting_segment_handle(),
// ssitev.supporting_segment_handle(), true);
ss3.set_segment(ss.point_handle(0), ss.point_handle(1),
ssitev.point_handle(1), ssitev.point_handle(1), true);
} else {
s3.set_segment(t.point(0), t.point(1),
t.point(2), t.point(3),
sitev.point(0), sitev.point(1));
ss3.set_segment(ss.supporting_segment_handle(),
ss.crossing_segment_handle(0),
ssitev.supporting_segment_handle());
// ss3.set_segment(ss.supporting_segment_handle(),
// ss.crossing_segment_handle(0),
// ssitev.supporting_segment_handle());
ss3.set_segment(ss.point_handle(0), ss.point_handle(1),
ss.point_handle(2), ss.point_handle(3),
ssitev.point_handle(0), ssitev.point_handle(1));
}
if ( t.is_exact(1) ) {
s4.set_segment(t.point(0), t.point(1),
sitev.point(0), sitev.point(1), false);
ss4.set_segment(ss.supporting_segment_handle(),
ssitev.supporting_segment_handle(), false);
// ss4.set_segment(ss.supporting_segment_handle(),
// ssitev.supporting_segment_handle(), false);
ss4.set_segment(ss.point_handle(0), ss.point_handle(1),
ssitev.point_handle(0), ssitev.point_handle(1), false);
} else {
s4.set_segment(t.point(0), t.point(1),
sitev.point(0), sitev.point(1),
t.point(4), t.point(5));
ss4.set_segment(ss.supporting_segment_handle(),
ssitev.supporting_segment_handle(),
ss.crossing_segment_handle(1));
// ss4.set_segment(ss.supporting_segment_handle(),
// ssitev.supporting_segment_handle(),
// ss.crossing_segment_handle(1));
ss4.set_segment(ss.point_handle(0), ss.point_handle(1),
ssitev.point_handle(0), ssitev.point_handle(1),
ss.point_handle(4), ss.point_handle(5));
}
insert_segment2(s3, ss3, vsx, false);

View File

@ -910,11 +910,13 @@ protected:
Storage_site_2 create_storage_site(Vertex_handle v0,
Vertex_handle v1)
{
typedef typename Storage_site_2::Handle_pair Point_handle_pair;
// typedef typename Storage_site_2::Handle_pair Point_handle_pair;
Point_handle_pair ph_pair(v0->storage_site().point_handle(),
v1->storage_site().point_handle());
return Storage_site_2( ph_pair );
// Point_handle_pair ph_pair(v0->storage_site().point_handle(),
// v1->storage_site().point_handle());
// return Storage_site_2( ph_pair );
return Storage_site_2( v0->storage_site().point_handle(0),
v1->storage_site().point_handle(0) );
}
Vertex_handle insert_first(const Point_2& p);

View File

@ -62,19 +62,6 @@ public:
// the compiler complains that it cannot find this constructor;
// solution: make the insert_intersecting_segment a template
// method...
template<class A1, class A2>
Segment_Voronoi_diagram_simple_site_2(const A1&, const A2&) {
// THIS_CONSTRUCTOR_SHOULD_HAVE_NEVER_BEEN_CALLED;
CGAL_assertion( false );
}
template<class A1, class A2, class A3>
Segment_Voronoi_diagram_simple_site_2(const A1&, const A2&,
const A3&) {
// THIS_CONSTRUCTOR_SHOULD_HAVE_NEVER_BEEN_CALLED;
CGAL_assertion( false );
}
template<class A1, class A2, class A3, class A4>
Segment_Voronoi_diagram_simple_site_2(const A1&, const A2&,
const A3&, const A4&) {
@ -99,8 +86,9 @@ public:
}
Segment_Voronoi_diagram_simple_site_2(const Object &o) {
if ( assign(p_, o) ) {
initialize_site(p_);
Point_2 p;
if ( assign(p, o) ) {
initialize_site(p);
return;
}
@ -121,43 +109,43 @@ public:
const Point_2& point() const {
CGAL_precondition ( is_point() );
return p_;
return p_[0];
}
const Point_2& point(unsigned int i) const {
CGAL_precondition ( i < 2 );
if ( i == 0 ) { return p_; }
else { CGAL_precondition( is_segment() ); return p2_; }
if ( i == 0 ) { return p_[0]; }
else { CGAL_precondition( is_segment() ); return p_[1]; }
}
Segment_2 segment() const {
CGAL_precondition ( is_segment() );
return Segment_2( p_, p2_ );
return Segment_2( p_[0], p_[1] );
}
Point_2 source() const {
CGAL_precondition ( is_segment() );
return p_;
return p_[0];
}
Point_2 target() const {
CGAL_precondition ( is_segment() );
return p2_;
return p_[1];
}
Self source_site() const {
CGAL_precondition( is_segment() );
return Self(p_);
return Self(p_[0]);
}
Self target_site() const {
CGAL_precondition( is_segment() );
return Self(p2_);
return Self(p_[1]);
}
Self opposite_site() const {
CGAL_precondition( is_segment() );
return Self( segment().opposite() );
return Self(p_[1],p_[0]);
}
Self supporting_site() const {
@ -166,11 +154,13 @@ public:
}
Self supporting_site(unsigned int i) const {
CGAL_assertion( false );
CGAL_precondition( is_point() && i < 2 );
return Self(p_, p_);
return Self(p_[0], p_[0]);
}
Self crossing_site(unsigned int i) const {
CGAL_assertion( false );
CGAL_precondition( is_segment() && i < 2 );
return *this;
}
@ -181,13 +171,15 @@ public:
}
Segment_2 supporting_segment(unsigned int i) const {
CGAL_assertion( false );
CGAL_precondition( is_point() && i < 2 );
return Segment_2(p_, p_);
return Segment_2(p_[0], p_[0]);
}
Segment_2 crossing_segment(unsigned int i) const {
CGAL_assertion( false );
CGAL_precondition( is_segment() && i < 2 );
return Segment_2(p_, p2_);
return Segment_2(p_[0], p_[1]);
}
void set_point(const Point_2& p) {
@ -221,27 +213,23 @@ public:
CGAL_assertion(false);
}
std::ostream& write(std::ostream& os)
{
return os << (*this);
}
protected:
void initialize_site(const Point_2& p)
{
type_ = 1;
p_ = p;
p_[0] = p;
}
void initialize_site(const Point_2& p1, const Point_2& p2)
{
type_ = 2;
p_ = p1;
p2_ = p2;
p_[0] = p1;
p_[1] = p2;
}
protected:
Point_2 p_, p2_;
Point_2 p_[2];
char type_;
};

View File

@ -32,47 +32,55 @@ CGAL_BEGIN_NAMESPACE
intersection of two non-parallel segments (if defined)
*/
template <class R_, class H_>
template <class Gt, class H>
class Segment_Voronoi_diagram_simple_storage_site_2
{
public:
typedef R_ R;
typedef R Rep;
typedef H_ Handle;
// typedef typename R::Point_2 Point_2;
// typedef typename R::Segment_2 Segment_2;
typedef typename R::Site_2 Site_2;
typedef Gt Geom_traits;
typedef H Point_handle;
typedef typename Geom_traits::Site_2 Site_2;
typedef std::pair<Handle,Handle> Handle_pair;
protected:
typedef typename R::FT FT;
typedef typename R::RT RT;
typedef Segment_Voronoi_diagram_simple_storage_site_2<Rep,Handle> Self;
typedef Point_handle Handle;
typedef
Segment_Voronoi_diagram_simple_storage_site_2<Geom_traits,Handle>
Self;
public:
Segment_Voronoi_diagram_simple_storage_site_2() : type_(0) {}
// constructs point site using input point
Segment_Voronoi_diagram_simple_storage_site_2(const Handle &h) {
initialize_site(h);
Segment_Voronoi_diagram_simple_storage_site_2(const Handle& hp) {
initialize_site(hp);
}
// constructs segment site using input segment
Segment_Voronoi_diagram_simple_storage_site_2(const Handle_pair &hp) {
initialize_site(hp);
Segment_Voronoi_diagram_simple_storage_site_2(const Handle& hp1,
const Handle& hp2) {
initialize_site(hp1, hp2);
}
// the compiler complains that it cannot find this constructor;
// solution: make the insert_intersecting_segment a template
// method...
template<class A1, class A2>
Segment_Voronoi_diagram_simple_storage_site_2(const A1&, const A2&) {
template<class A1, class A2, class A3, class A4>
Segment_Voronoi_diagram_simple_storage_site_2(const A1&, const A2&,
const A3&, const A4&) {
CGAL_assertion( false );
}
template<class A1, class A2, class A3>
template<class A1, class A2, class A3, class A4, class A5>
Segment_Voronoi_diagram_simple_storage_site_2(const A1&, const A2&,
const A3&) {
const A3&, const A4&,
const A5&) {
CGAL_assertion( false );
}
template<class A1, class A2, class A3, class A4, class A5, class A6>
Segment_Voronoi_diagram_simple_storage_site_2(const A1&, const A2&,
const A3&, const A4&,
const A5&, const A6&) {
CGAL_assertion( false );
}
@ -87,25 +95,26 @@ public:
// ACCESS METHODS
//---------------
Handle point_handle() const { return h_[0]; }
Handle_pair segment_handle() const {
return Handle_pair(h_[0], h_[1]);
const Handle& point_handle(unsigned int i) const {
CGAL_precondition( i < 6 );
return h_[i];
}
Handle_pair supporting_segment_handle() const {
Self supporting_segment_site() const {
CGAL_precondition( is_segment() );
return Handle_pair(h_[0], h_[1]);
return Self(h_[0], h_[1]);
}
Handle_pair supporting_segment_handle(unsigned int i) const {
Self supporting_segment_site(unsigned int i) const {
CGAL_precondition( false );
CGAL_precondition( is_point() && i < 2 );
return Handle_pair(h_[0], h_[0]);
return Self(h_[0], h_[0]);
}
Handle_pair crossing_segment_handle(unsigned int i) const {
Self crossing_segment_handle(unsigned int i) const {
CGAL_precondition( false );
CGAL_precondition( is_segment() && i < 2 );
return Handle_pair(h_[0], h_[1]);
return Self(h_[0], h_[1]);
}
Site_2 site() const {
@ -119,43 +128,48 @@ public:
public:
// SET METHODS
//------------
void set_point(const Handle& h) {
initialize_site(h);
void set_point(const Handle& hp) {
initialize_site(hp);
}
void set_segment(const Handle_pair& hp) {
initialize_site(hp);
void set_segment(const Handle& hp1, const Handle& hp2) {
initialize_site(hp1, hp2);
}
// the compiler complains that it cannot find this constructor;
// solution: make the insert_intersecting_segment a template
// method...
template<class A1, class A2>
void set_point(const A1&, const A2&)
{
template<class A1, class A2, class A3, class A4>
void set_point(const A1&, const A2&, const A3&, const A4&) {
CGAL_assertion(false);
}
template<class A1, class A2, class A3>
void set_segment(const A1&, const A2&, const A3&)
{
template<class A1, class A2, class A3, class A4, class A5>
void set_segment(const A1&, const A2&, const A3&, const A4&,
const A5&) {
CGAL_assertion(false);
}
template<class A1, class A2, class A3, class A4, class A5, class A6>
void set_segment(const A1&, const A2&, const A3&, const A4&,
const A5&, const A6&) {
CGAL_assertion(false);
}
protected:
// INITIALIZATION
//---------------
void initialize_site(const Handle& h)
void initialize_site(const Handle& hp)
{
type_ = 1;
h_[0] = h;
h_[0] = hp;
}
void initialize_site(const Handle_pair& hp)
void initialize_site(const Handle& hp1, const Handle& hp2)
{
type_ = 2;
h_[0] = hp.first;
h_[1] = hp.second;
h_[0] = hp1;
h_[1] = hp2;
}
protected:

View File

@ -31,42 +31,36 @@ CGAL_BEGIN_NAMESPACE
intersection of two non-parallel segments (if defined)
*/
template <class R_>
template <class Gt>
class Segment_Voronoi_diagram_site_2
{
public:
typedef R_ R;
typedef R Rep;
typedef typename R::Point_2 Point_2;
typedef typename R::Segment_2 Segment_2;
typedef Gt Geom_traits;
typedef typename Geom_traits::Point_2 Point_2;
typedef typename Geom_traits::Segment_2 Segment_2;
protected:
typedef typename R::FT FT;
typedef typename R::RT RT;
typedef Segment_Voronoi_diagram_site_2<Rep> Self;
typedef typename Geom_traits::FT FT;
typedef typename Geom_traits::RT RT;
typedef Segment_Voronoi_diagram_site_2<Geom_traits> Self;
public:
Segment_Voronoi_diagram_site_2() : type_(0) {}
// constructs point site using input point
Segment_Voronoi_diagram_site_2(const Point_2& p) {
changed_ = false;
initialize_site(p);
}
// constructs segment site using the segment (p1,p2)
Segment_Voronoi_diagram_site_2(const Point_2& p1, const Point_2& p2)
{
changed_ = false;
Segment_Voronoi_diagram_site_2(const Point_2& p1, const Point_2& p2) {
initialize_site(p1, p2);
}
// constructs point site using the point of intersection of the
// segments (p1,p2) and (q1,q2)
Segment_Voronoi_diagram_site_2(const Point_2& p1, const Point_2& p2,
const Point_2& q1, const Point_2& q2)
{
changed_ = false;
const Point_2& q1, const Point_2& q2) {
initialize_site(p1, p2, q1, q2);
}
@ -75,9 +69,7 @@ public:
// the segment (p1,p2) is a segment that supports the actual segment
Segment_Voronoi_diagram_site_2(const Point_2& p1, const Point_2& p2,
const Point_2& q1, const Point_2& q2,
const Point_2& r1, const Point_2& r2)
{
changed_ = false;
const Point_2& r1, const Point_2& r2) {
initialize_site(p1, p2, q1, q2, r1, r2);
}
@ -86,22 +78,19 @@ public:
// intersection of (p1,p2) with (q1,q2) as the other endpoint
Segment_Voronoi_diagram_site_2(const Point_2& p1, const Point_2& p2,
const Point_2& q1, const Point_2& q2,
bool is_first_exact)
{
changed_ = false;
bool is_first_exact) {
initialize_site(p1, p2, q1, q2, is_first_exact);
}
Segment_Voronoi_diagram_site_2(const Object &o) {
if ( assign(p_, o) ) {
changed_ = false;
initialize_site(p_);
Point_2 p;
if ( assign(p, o) ) {
initialize_site(p);
return;
}
Segment_2 s;
if ( assign(s, o) ) {
changed_ = false;
initialize_site(s.source(), s.target());
return;
}
@ -122,26 +111,26 @@ public:
const Point_2& point(unsigned int i) const
{
CGAL_precondition( i < 6 );
if ( i == 0 ) { return p_; }
if ( i == 0 ) { return p_[0]; }
else if ( i == 1 ) {
CGAL_precondition( is_segment() || !is_exact() );
return p2_;
return p_[1];
} else if ( i == 2 ) {
CGAL_precondition( (is_point() && !is_exact()) ||
(is_segment() && !is_exact(0)) );
return q1_;
return p_[2];
} else if ( i == 3 ) {
CGAL_precondition( (is_point() && !is_exact()) ||
(is_segment() && !is_exact(0)) );
return q2_;
return p_[3];
} else if ( i == 4 ) {
CGAL_precondition( (is_point() && !is_exact()) ||
(is_segment() && !is_exact(1)) );
return q3_;
return p_[4];
} else { // i == 5
CGAL_precondition( (is_point() && !is_exact()) ||
(is_segment() && !is_exact(1)) );
return q4_;
return p_[5];
}
}
@ -149,9 +138,9 @@ public:
Point_2 point() const {
CGAL_precondition ( is_point() );
if ( !is_exact() ) {
return compute_intersection_point(q1_, q2_, q3_, q4_);
return compute_intersection_point(p_[2], p_[3], p_[4], p_[5]);
} else {
return p_;
return p_[0];
}
}
@ -172,86 +161,79 @@ public:
Self supporting_site() const {
CGAL_precondition( is_segment() );
return Self(p_, p2_);
return Self(p_[0], p_[1]);
}
Self supporting_site(unsigned int i) const {
CGAL_precondition( is_point() && i < 2);
CGAL_precondition( !is_exact() );
if ( i == 0 ) { return Self(q1_, q2_); }
return Self(q3_, q4_);
if ( i == 0 ) { return Self(p_[2], p_[3]); }
return Self(p_[4], p_[5]);
}
Self crossing_site(unsigned int i) const {
CGAL_precondition( is_segment() && !is_exact() );
CGAL_precondition( i < 2 && !is_exact(i) );
if ( i == 0 ) {
return Self(q1_, q2_);
return Self(p_[2], p_[3]);
} else {
return Self(q3_, q4_);
return Self(p_[4], p_[5]);
}
}
Self source_site() const {
CGAL_precondition( is_segment() );
if ( is_exact() || is_exact(0) ) {
return Self(p_);
return Self(p_[0]);
} else {
return Self(p_, p2_, q1_, q2_);
return Self(p_[0], p_[1], p_[2], p_[3]);
}
}
Self target_site() const {
CGAL_precondition( is_segment() );
if ( is_exact() || is_exact(1) ) {
return Self(p2_);
return Self(p_[1]);
} else {
return Self(p_, p2_, q3_, q4_);
return Self(p_[0], p_[1], p_[4], p_[5]);
}
}
Self opposite_site() const {
CGAL_precondition( is_segment() );
if ( is_exact() ) {
return Self(p2_, p_);
return Self(p_[1], p_[0]);
// return segment().opposite() );
}
Segment_2 supp = supporting_segment().opposite();
// Segment_2 supp = supporting_segment().opposite();
CGAL_assertion( !is_exact(0) || !is_exact(1) );
if ( is_exact(0) && !is_exact(1) ) {
// return Self(supp, crossing_segment(1), false);
return Self(p2_, p_, q3_, q4_, false);
return Self(p_[1], p_[0], p_[4], p_[5], false);
} else if ( !is_exact(0) && is_exact(1) ) {
// return Self(supp, crossing_segment(0), true);
return Self(p2_, p_, q1_, q2_, true);
return Self(p_[1], p_[0], p_[2], p_[3], true);
} else {
// return Self(supp, crossing_segment(1), crossing_segment(0));
return Self(p2_, p_, q3_, q4_, q1_, q2_);
return Self(p_[1], p_[0], p_[4], p_[5], p_[2], p_[3]);
}
}
#if 1
Segment_2 supporting_segment() const {
CGAL_precondition( is_segment() );
#if 0
if ( is_exact() ) {
return segment();
} else {
return Segment_2(p_, p2_);
}
#else
return Segment_2(p_, p2_);
#endif
return Segment_2(p_[0], p_[1]);
}
Segment_2 supporting_segment(unsigned int i) const {
CGAL_precondition( is_point() && !is_exact() && i < 2 );
if ( i == 0 ) {
return Segment_2(q1_, q2_);
return Segment_2(p_[2], p_[3]);
} else {
return Segment_2(q3_, q4_);
return Segment_2(p_[4], p_[5]);
}
}
@ -259,59 +241,50 @@ public:
CGAL_precondition( is_segment() && !is_exact() );
CGAL_precondition( i < 2 && !is_exact(i) );
if ( i == 0 ) {
return Segment_2(q1_, q2_);
return Segment_2(p_[2], p_[3]);
} else {
return Segment_2(q3_, q4_);
return Segment_2(p_[4], p_[5]);
}
}
#endif
void set_point(const Point_2& p) {
changed_ = true;
initialize_site(p);
}
void set_segment(const Point_2& p1, const Point_2& p2) {
changed_ = true;
initialize_site(p1, p2);
}
void set_point(const Point_2& p1, const Point_2& p2,
const Point_2& q1, const Point_2& q2) {
changed_ = true;
initialize_site(p1, p2, q1, q2);
}
void set_segment(const Point_2& p1, const Point_2& p2,
const Point_2& q1, const Point_2& q2,
const Point_2& r1, const Point_2& r2) {
changed_ = true;
initialize_site(p1, p2, q1, q2, r1, r2);
}
void set_segment(const Point_2& p1, const Point_2& p2,
const Point_2& q1, const Point_2& q2,
bool is_first_exact) {
changed_ = true;
initialize_site(p1, p2, q1, q2, is_first_exact);
}
std::ostream& write(std::ostream& os)
{
return os << (*this);
}
protected:
void initialize_site(const Point_2& p)
{
type_ = 1;
p_ = p;
p_[0] = p;
}
void initialize_site(const Point_2& p1, const Point_2& p2)
{
type_ = 2;
p_ = p1;
p2_ = p2;
p_[0] = p1;
p_[1] = p2;
}
void initialize_site(const Point_2& p1, const Point_2& p2,
const Point_2& q1, const Point_2& q2)
@ -320,10 +293,10 @@ protected:
// that the computation of the intersection point is always
// done in the same manner (?)
type_ = 5;
q1_ = p1;
q2_ = p2;
q3_ = q1;
q4_ = q2;
p_[2] = p1;
p_[3] = p2;
p_[4] = q1;
p_[5] = q2;
}
@ -332,12 +305,12 @@ protected:
const Point_2& r1, const Point_2& r2)
{
type_ = 14;
p_ = p1;
p2_ = p2;
q1_ = q1;
q2_ = q2;
q3_ = r1;
q4_ = r2;
p_[0] = p1;
p_[1] = p2;
p_[2] = q1;
p_[3] = q2;
p_[4] = r1;
p_[5] = r2;
}
void initialize_site(const Point_2& p1, const Point_2& p2,
@ -345,77 +318,35 @@ protected:
bool is_first_exact)
{
type_ = (is_first_exact ? 10 : 6);
p_ = p1;
p2_ = p2;
p_[0] = p1;
p_[1] = p2;
if ( is_first_exact ) {
q3_ = q1;
q4_ = q2;
p_[4] = q1;
p_[5] = q2;
} else {
q1_ = q1;
q2_ = q2;
p_[2] = q1;
p_[3] = q2;
}
}
Point_2 compute_source() const {
CGAL_precondition( is_segment() );
if ( is_exact() || is_exact(0) ) {
return p_;
return p_[0];
} else {
return compute_intersection_point(p_, p2_, q1_, q2_);
return compute_intersection_point(p_[0], p_[1], p_[2], p_[3]);
}
}
Point_2 compute_target() const {
CGAL_precondition( is_segment() );
if ( is_exact() || is_exact(1) ) {
return p2_;
return p_[1];
} else {
return compute_intersection_point(p_, p2_, q3_, q4_);
return compute_intersection_point(p_[0], p_[1], p_[4], p_[5]);
}
}
// computes the point of intersection of the segments (p1,p2) and
// (q1,q2) and also caches the result
const Point_2& compute_intersection_point1() const
{
static const Point_2 px;
static int i = 0;
if ( i == 0 || changed_ ) {
px = compute_intersection_point(p1,p2,q1,q2);
i = 1;
}
return px;
}
// computes the point of intersection of the segments (p1,p2) and
// (q3,q4) and also caches the result
const Point_2& compute_intersection_point2() const
{
static const Point_2 px;
static int i = 0;
if ( i == 0 || changed_ ) {
px = compute_intersection_point(p1,p2,q3,q4);
i = 1;
}
return px;
}
// computes the point of intersection of the segments (q1,q2) and
// (q3,q4) and also caches the result
const Point_2& compute_intersection_point3() const
{
static const Point_2 px;
static int i = 0;
if ( i == 0 || changed_ ) {
px = compute_intersection_point(q1,q2,q3,q4);
i = 1;
}
return px;
}
// computes the point of intersection of the segments p1p2 and p3p4
static Point_2
compute_intersection_point(const Point_2& p1, const Point_2& p2,
@ -435,11 +366,8 @@ protected:
}
protected:
Point_2 p_;
Point_2 p2_;
Point_2 q1_, q2_, q3_, q4_;
Point_2 p_[6];
char type_;
bool changed_;
};
//-------------------------------------------------------------------------

View File

@ -32,57 +32,64 @@ CGAL_BEGIN_NAMESPACE
intersection of two non-parallel segments (if defined)
*/
template <class R_, class H_>
template <class Gt, class H>
class Segment_Voronoi_diagram_storage_site_2
{
public:
typedef R_ R;
typedef R Rep;
typedef H_ Handle;
// typedef typename R::Point_2 Point_2;
// typedef typename R::Segment_2 Segment_2;
typedef typename R::Site_2 Site_2;
typedef Gt Geom_traits;
typedef H Point_handle;
typedef typename Geom_traits::Site_2 Site_2;
typedef std::pair<Handle,Handle> Handle_pair;
protected:
typedef typename R::FT FT;
typedef typename R::RT RT;
typedef Segment_Voronoi_diagram_storage_site_2<Rep,Handle> Self;
typedef Point_handle Handle;
typedef
Segment_Voronoi_diagram_storage_site_2<Geom_traits,Handle> Self;
public:
Segment_Voronoi_diagram_storage_site_2() : type_(0) {}
// constructs point site using input point
Segment_Voronoi_diagram_storage_site_2(const Handle &h) {
initialize_site(h);
}
// constructs segment site using input segment
Segment_Voronoi_diagram_storage_site_2(const Handle_pair &hp) {
Segment_Voronoi_diagram_storage_site_2(const Handle& hp) {
initialize_site(hp);
}
// constructs point site using point of intersection
Segment_Voronoi_diagram_storage_site_2(const Handle_pair& hp1,
const Handle_pair& hp2) {
// constructs segment site corresponding to the segment (*hp1,*hp2)
Segment_Voronoi_diagram_storage_site_2(const Handle& hp1,
const Handle& hp2) {
initialize_site(hp1, hp2);
}
// constructs segment site using points of intersection of support
// with s1 and support with s2 as endpoints
Segment_Voronoi_diagram_storage_site_2(const Handle_pair& hsupport,
const Handle_pair& hp1,
const Handle_pair& hp2) {
initialize_site(hsupport, hp1, hp2);
// constructs point site using the point of intersection of the
// segments (*hp1,*hp2) and (*hq1,*hq2)
Segment_Voronoi_diagram_storage_site_2(const Handle& hp1,
const Handle& hp2,
const Handle& hq1,
const Handle& hq2) {
initialize_site(hp1, hp2, hq1, hq2);
}
// constructs segment site whose endpoints are the points of
// intersection of the pairs of segments (*hp1,*hp2), (*hq1,*hq2)
// and (*hp1,*hp2), (*hr1,*hr2)
Segment_Voronoi_diagram_storage_site_2(const Handle& hp1,
const Handle& hp2,
const Handle& hq1,
const Handle& hq2,
const Handle& hr1,
const Handle& hr2) {
initialize_site(hp1, hp2, hq1, hq2, hr1, hr2);
}
// constructs segment site using either the source or the target of
// support (that depends on the boolean is_first_exact) and the
// intersection of support with s as the other endpoint
Segment_Voronoi_diagram_storage_site_2(const Handle_pair& hsupport,
const Handle_pair& hp,
// (*hp1,*hp2) (that depends on the boolean is_first_exact) and the
// intersection of (*hp1,*hp2) with (*hq1,*hq2) as the other endpoint
Segment_Voronoi_diagram_storage_site_2(const Handle& hp1,
const Handle& hp2,
const Handle& hq1,
const Handle& hq2,
bool is_first_exact) {
initialize_site(hsupport, hp, is_first_exact);
initialize_site(hp1, hp2, hq1, hq2, is_first_exact);
}
public:
@ -100,33 +107,32 @@ public:
// ACCESS METHODS
//---------------
Handle point_handle() const { return h_[0]; }
Handle_pair segment_handle() const {
return Handle_pair(h_[0], h_[1]);
const Handle& point_handle(unsigned int i) const {
CGAL_precondition( i < 6 );
return h_[i];
}
Handle_pair supporting_segment_handle() const {
Self supporting_segment_site() const {
CGAL_precondition( is_segment() );
return Handle_pair(h_[0], h_[1]);
return Self(h_[0], h_[1]);
}
Handle_pair supporting_segment_handle(unsigned int i) const {
Self supporting_segment_site(unsigned int i) const {
CGAL_precondition( is_point() && !is_exact() && i < 2 );
if ( i == 0 ) {
return Handle_pair(h_[2], h_[3]);
return Self(h_[2], h_[3]);
} else {
return Handle_pair(h_[4], h_[5]);
return Self(h_[4], h_[5]);
}
}
Handle_pair crossing_segment_handle(unsigned int i) const {
Self crossing_segment_site(unsigned int i) const {
CGAL_precondition( is_segment() && !is_exact() );
CGAL_precondition( i < 2 && !is_exact(i) );
if ( i == 0 ) {
return Handle_pair(h_[2], h_[3]);
return Self(h_[2], h_[3]);
} else {
return Handle_pair(h_[4], h_[5]);
return Self(h_[4], h_[5]);
}
}
@ -153,85 +159,86 @@ public:
public:
// SET METHODS
//------------
void set_point(const Handle& h) {
initialize_site(h);
}
void set_segment(const Handle_pair& hp) {
void set_point(const Handle& hp) {
initialize_site(hp);
}
void set_point(const Handle_pair& hp1, const Handle_pair& hp2) {
void set_segment(const Handle& hp1, const Handle& hp2) {
initialize_site(hp1, hp2);
}
void set_segment(const Handle_pair& hsupport,
const Handle_pair& hp1,
const Handle_pair& hp2) {
initialize_site(hsupport, hp1, hp2);
void set_point(const Handle& hp1, const Handle& hp2,
const Handle& hq1, const Handle& hq2) {
initialize_site(hp1, hp2, hq1, hq2);
}
void set_segment(const Handle_pair& hsupport,
const Handle_pair& hp,
void set_segment(const Handle& hp1, const Handle& hp2,
const Handle& hq1, const Handle& hq2,
const Handle& hr1, const Handle& hr2) {
initialize_site(hp1, hp2, hq1, hq2, hr1, hr2);
}
void set_segment(const Handle& hp1, const Handle& hp2,
const Handle& hq1, const Handle& hq2,
bool is_first_exact) {
initialize_site(hsupport, hp, is_first_exact);
initialize_site(hp1, hp2, hq1, hq2, is_first_exact);
}
protected:
// INITIALIZATION
//---------------
void initialize_site(const Handle& h)
void initialize_site(const Handle& hp)
{
type_ = 1;
h_[0] = h;
h_[0] = hp;
}
void initialize_site(const Handle_pair& hp)
void initialize_site(const Handle& hp1, const Handle& hp2)
{
type_ = 2;
h_[0] = hp.first;
h_[1] = hp.second;
h_[0] = hp1;
h_[1] = hp2;
}
void initialize_site(const Handle_pair& hp1,
const Handle_pair& hp2)
void initialize_site(const Handle& hp1, const Handle& hp2,
const Handle& hq1, const Handle& hq2)
{
// MK: Sort the segments s1 and s2 in lexicographical order so
// that the computation of the intersection point is always
// done in the same manner (?)
type_ = 5;
h_[2] = hp1.first;
h_[3] = hp1.second;
h_[4] = hp2.first;
h_[5] = hp2.second;
h_[2] = hp1;
h_[3] = hp2;
h_[4] = hq1;
h_[5] = hq2;
}
void initialize_site(const Handle_pair& hsupport,
const Handle_pair& hp1,
const Handle_pair& hp2)
void initialize_site(const Handle& hp1, const Handle& hp2,
const Handle& hq1, const Handle& hq2,
const Handle& hr1, const Handle& hr2)
{
type_ = 14;
h_[0] = hsupport.first;
h_[1] = hsupport.second;
h_[2] = hp1.first;
h_[3] = hp1.second;
h_[4] = hp2.first;
h_[5] = hp2.second;
h_[0] = hp1;
h_[1] = hp2;
h_[2] = hq1;
h_[3] = hq2;
h_[4] = hr1;
h_[5] = hr2;
}
void initialize_site(const Handle_pair& hsupport,
const Handle_pair& hp,
void initialize_site(const Handle& hp1, const Handle& hp2,
const Handle& hq1, const Handle& hq2,
bool is_first_exact)
{
type_ = (is_first_exact ? 10 : 6);
h_[0] = hsupport.first;
h_[1] = hsupport.second;
h_[0] = hp1;
h_[1] = hp2;
if ( is_first_exact ) {
h_[4] = hp.first;
h_[5] = hp.second;
h_[4] = hq1;
h_[5] = hq2;
} else {
h_[2] = hp.first;
h_[3] = hp.second;
h_[2] = hq1;
h_[3] = hq2;
}
}