- Merge H2 and H3 into Homogeneous_kernel.

This commit is contained in:
Sylvain Pion
2006-03-06 23:51:27 +00:00
parent bcf05d4b2d
commit 0ec1b0efcc
41 changed files with 480 additions and 478 deletions
@@ -0,0 +1,60 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_HOMOGENEOUS_H
#define CGAL_HOMOGENEOUS_H
#include <CGAL/Homogeneous/Homogeneous_base.h>
#include <CGAL/Handle_for.h>
#include <CGAL/Kernel/Type_equality_wrapper.h>
#include <CGAL/Quotient.h>
CGAL_BEGIN_NAMESPACE
template < typename RT_, typename FT_, typename Kernel >
struct Homogeneous_base_ref_count
: public Homogeneous_base<RT_, FT_, Kernel >
{
typedef RT_ RT;
typedef FT_ FT;
// The mecanism that allows to specify reference-counting or not.
template < typename T >
struct Handle { typedef Handle_for<T> type; };
template < typename Kernel2 >
struct Base {
typedef Homogeneous_base_ref_count<RT_,FT_,Kernel2> Type;
};
};
template < typename RT_, typename FT_ = Quotient<RT_> >
struct Homogeneous
: public Type_equality_wrapper<
Homogeneous_base_ref_count<RT_, FT_, Homogeneous<RT_, FT_> >,
Homogeneous<RT_, FT_> >
{};
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,894 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_AFF_TRANSFORMATIONH3_H
#define CGAL_AFF_TRANSFORMATIONH3_H
#include <CGAL/Handle_for_virtual.h>
#include <CGAL/determinant.h>
CGAL_BEGIN_NAMESPACE
// forward declaration
template < class R >
class Aff_transformationH3;
template < class R >
class Aff_transformation_repH3;
template < class R >
std::ostream &
operator<< ( std::ostream & out,
const Aff_transformationH3<R>& t);
template < class R >
Aff_transformationH3<R>
_general_transformation_composition (
Aff_transformation_repH3<R> l,
Aff_transformation_repH3<R> r);
template <class R_ >
class Aff_transformation_rep_baseH3 : public Ref_counted_virtual
// abstract base class of aff transformation representations
{
public:
typedef R_ R;
typedef typename R::FT FT;
typedef typename R::RT RT;
typedef typename R::Point_3 Point_3;
typedef typename R::Vector_3 Vector_3;
typedef typename R::Direction_3 Direction_3;
typedef typename R::Plane_3 Plane_3;
typedef typename R::Aff_transformation_3 Aff_transformation_3;
virtual ~Aff_transformation_rep_baseH3(){}
virtual Point_3
transform(const Point_3&) const = 0;
virtual Vector_3
transform(const Vector_3&) const = 0;
virtual Direction_3
transform(const Direction_3&) const = 0;
virtual Plane_3
transform(const Plane_3&) const = 0;
virtual Aff_transformation_3
inverse() const = 0;
virtual Aff_transformation_3
transpose() const = 0;
virtual Aff_transformation_repH3<R>
general_form() const = 0;
virtual bool
is_even() const = 0;
virtual RT
homogeneous(int i, int j) const = 0;
virtual FT
cartesian(int i, int j) const = 0;
};
template < class R_ >
class Aff_transformation_repH3 : public Aff_transformation_rep_baseH3<R_>
{
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Plane_3 Plane_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
public:
typedef R_ R;
Aff_transformation_repH3() {}
Aff_transformation_repH3(
const RT& m00, const RT& m01, const RT& m02, const RT& m03,
const RT& m10, const RT& m11, const RT& m12, const RT& m13,
const RT& m20, const RT& m21, const RT& m22, const RT& m23,
const RT& m33);
virtual ~Aff_transformation_repH3() {}
virtual Point_3
transform(const Point_3& p) const;
virtual Vector_3
transform(const Vector_3& v) const;
virtual Direction_3
transform(const Direction_3& dir) const;
virtual Plane_3
transform(const Plane_3& pl) const;
virtual Aff_transformation_3
inverse() const;
virtual Aff_transformation_repH3<R>
general_form() const;
virtual Aff_transformation_3
transpose() const;
virtual bool
is_even() const;
virtual RT
homogeneous(int i, int j) const ;
virtual FT
cartesian(int i, int j) const ;
friend class Aff_transformationH3<R>;
friend
Aff_transformationH3<R>
_general_transformation_composition <> (
Aff_transformation_repH3<R> l,
Aff_transformation_repH3<R> r);
friend
std::ostream &
operator<< <> (std::ostream & out, const Aff_transformationH3<R>& t);
private:
RT t00, t01, t02, t03;
RT t10, t11, t12, t13;
RT t20, t21, t22, t23;
RT t33;
};
template < class R_ >
class Identity_repH3 : public Aff_transformation_rep_baseH3<R_>
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Plane_3 Plane_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
public:
typedef R_ R;
Identity_repH3()
{}
virtual ~Identity_repH3()
{}
virtual Point_3
transform(const Point_3& p) const
{ return p; }
virtual Vector_3
transform(const Vector_3& v) const
{ return v; }
virtual Direction_3
transform(const Direction_3& dir) const
{ return dir; }
virtual Plane_3
transform(const Plane_3& pl) const
{ return pl; }
virtual Aff_transformation_3
inverse() const
{ return Aff_transformation_3( IDENTITY); }
virtual Aff_transformation_repH3<R>
general_form() const;
virtual Aff_transformation_3
transpose() const
{ return Aff_transformation_3( IDENTITY); }
virtual bool
is_even() const
{ return true; }
virtual RT
homogeneous(int i, int j) const
{ return (i==j) ? RT(1) : RT(0); }
virtual FT
cartesian(int i, int j) const
{ return (i==j) ? FT(1) : FT(0); }
};
template < class R_ >
class Translation_repH3 : public Aff_transformation_rep_baseH3<R_>
{
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Plane_3 Plane_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
public:
typedef R_ R;
Translation_repH3( const Vector_3& v);
virtual ~Translation_repH3() {}
virtual Point_3
transform(const Point_3& p) const;
virtual Vector_3
transform(const Vector_3& v) const;
virtual Direction_3
transform(const Direction_3& dir) const;
virtual Plane_3
transform(const Plane_3& pl) const;
virtual Aff_transformation_3
inverse() const;
virtual Aff_transformation_repH3<R>
general_form() const;
virtual Aff_transformation_3
transpose() const;
virtual bool
is_even() const;
virtual RT
homogeneous(int i, int j) const ;
virtual FT
cartesian(int i, int j) const ;
friend class Aff_transformationH3<R>;
private:
Vector_3 tv;
};
template < class R_ >
class Aff_transformationH3
: public Handle_for_virtual< Aff_transformation_rep_baseH3<R_> >
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Plane_3 Plane_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
public:
typedef R_ R;
Aff_transformationH3();
// Identity
Aff_transformationH3(const Identity_transformation&);
// Translation
Aff_transformationH3(const Translation& , const Vector_3& v);
// Scaling
Aff_transformationH3(const Scaling&, const RT& num, const RT& den);
// General form
Aff_transformationH3(
const RT& m00, const RT& m01, const RT& m02, const RT& m03,
const RT& m10, const RT& m11, const RT& m12, const RT& m13,
const RT& m20, const RT& m21, const RT& m22, const RT& m23,
const RT& m33);
Aff_transformationH3(
const RT& m00, const RT& m01, const RT& m02,
const RT& m10, const RT& m11, const RT& m12,
const RT& m20, const RT& m21, const RT& m22,
const RT& m33);
Point_3
transform(const Point_3& p) const;
Vector_3
transform(const Vector_3& v) const;
Direction_3
transform(const Direction_3& d) const;
Plane_3
transform(const Plane_3& pl) const;
Aff_transformation_3
inverse() const;
Aff_transformationH3<R>
transpose() const;
bool
is_even() const;
bool
is_odd() const;
FT
cartesian(int i, int j) const
{ return this->Ptr()->cartesian(i,j); }
RT
homogeneous(int i, int j) const
{ return this->Ptr()->homogeneous(i,j); }
FT
m(int i, int j) const
{ return this->Ptr()->cartesian(i,j); }
RT
hm(int i, int j) const
{ return this->Ptr()->homogeneous(i,j); }
};
template < class R >
CGAL_KERNEL_INLINE
Aff_transformation_repH3<R>::Aff_transformation_repH3(
const RT& m00, const RT& m01, const RT& m02, const RT& m03,
const RT& m10, const RT& m11, const RT& m12, const RT& m13,
const RT& m20, const RT& m21, const RT& m22, const RT& m23,
const RT& m33)
: t00(m00), t01(m01), t02(m02), t03(m03),
t10(m10), t11(m11), t12(m12), t13(m13),
t20(m20), t21(m21), t22(m22), t23(m23),
t33(m33)
{}
template < class R >
CGAL_KERNEL_INLINE
typename Aff_transformation_repH3<R>::Point_3
Aff_transformation_repH3<R>::
transform(const typename Aff_transformation_repH3<R>::Point_3& p) const
{
return Point_3(t00 * p.hx() + t01 * p.hy() + t02 * p.hz() + t03 * p.hw(),
t10 * p.hx() + t11 * p.hy() + t12 * p.hz() + t13 * p.hw(),
t20 * p.hx() + t21 * p.hy() + t22 * p.hz() + t23 * p.hw(),
t33 * p.hw());
}
template < class R >
CGAL_KERNEL_INLINE
typename Aff_transformation_repH3<R>::Vector_3
Aff_transformation_repH3<R>::
transform(const typename Aff_transformation_repH3<R>::Vector_3& v) const
{
return Vector_3(t00 * v.hx() + t01 * v.hy() + t02 * v.hz(),
t10 * v.hx() + t11 * v.hy() + t12 * v.hz(),
t20 * v.hx() + t21 * v.hy() + t22 * v.hz(),
t33 * v.hw() );
}
template < class R >
CGAL_KERNEL_INLINE
typename Aff_transformation_repH3<R>::Direction_3
Aff_transformation_repH3<R>::
transform(const typename Aff_transformation_repH3<R>::Direction_3& d) const
{
if (t33 > RT(0))
return Direction_3(t00 * d.hx() + t01 * d.hy() + t02 * d.hz(),
t10 * d.hx() + t11 * d.hy() + t12 * d.hz(),
t20 * d.hx() + t21 * d.hy() + t22 * d.hz());
else
return - Direction_3(t00 * d.hx() + t01 * d.hy() + t02 * d.hz(),
t10 * d.hx() + t11 * d.hy() + t12 * d.hz(),
t20 * d.hx() + t21 * d.hy() + t22 * d.hz());
}
template < class R >
CGAL_KERNEL_INLINE
typename Aff_transformation_repH3<R>::Plane_3
Aff_transformation_repH3<R>::
transform(const typename Aff_transformation_repH3<R>::Plane_3& pl) const
{
if ( is_even() )
{
return Plane_3(
transform(pl.point() ),
transpose().inverse().transform(pl.orthogonal_direction() ));
}
else
{
return Plane_3(
transform(pl.point() ),
-(transpose().inverse().transform(pl.orthogonal_direction() )));
}
}
template < class R >
CGAL_KERNEL_INLINE
typename Aff_transformation_repH3<R>::Aff_transformation_3
Aff_transformation_repH3<R>::inverse() const
{
typedef typename R::RT RT;
const RT RT0(0);
return Aff_transformation_3(
det3x3_by_formula( t11, t12, t13,
t21, t22, t23, // i 00
RT0, RT0, t33 ),
- det3x3_by_formula( t01, t02, t03,
t21, t22, t23, // i 01
RT0, RT0, t33 ),
det3x3_by_formula( t01, t02, t03,
t11, t12, t13, // i 02
RT0, RT0, t33 ),
- det3x3_by_formula( t01, t02, t03,
t11, t12, t13, // i 03
t21, t22, t23 ),
- det3x3_by_formula( t10, t12, t13,
t20, t22, t23, // i 10
RT0, RT0, t33 ),
det3x3_by_formula( t00, t02, t03,
t20, t22, t23, // i 11
RT0, RT0, t33 ),
- det3x3_by_formula( t00, t02, t03,
t10, t12, t13, // i 12
RT0, RT0, t33 ),
det3x3_by_formula( t00, t02, t03,
t10, t12, t13, // i 13
t20, t22, t23 ),
det3x3_by_formula( t10, t11, t13,
t20, t21, t23, // i 20
RT0, RT0, t33 ),
- det3x3_by_formula( t00, t01, t03,
t20, t21, t23, // i 21
RT0, RT0, t33 ),
det3x3_by_formula( t00, t01, t03,
t10, t11, t13, // i 22
RT0, RT0, t33 ),
- det3x3_by_formula( t00, t01, t03,
t10, t11, t13, // i 23
t20, t21, t23 ),
det3x3_by_formula( t00, t01, t02,
t10, t11, t12, // i 33
t20, t21, t22 )
) ;
}
template < class R >
inline
Aff_transformation_repH3<R>
Aff_transformation_repH3<R>::general_form() const
{ return *this; }
template < class R >
CGAL_KERNEL_INLINE
typename Aff_transformation_repH3<R>::Aff_transformation_3
Aff_transformation_repH3<R>::transpose() const
{
typedef typename R::RT RT;
const RT RT0(0);
return Aff_transformation_3( t00, t10, t20, RT0,
t01, t11, t21, RT0,
t02, t12, t22, RT0,
t33);
}
template < class R >
CGAL_KERNEL_INLINE
bool
Aff_transformation_repH3<R>::is_even() const
{
return (CGAL_NTS sign<RT>( t33 *
det3x3_by_formula(t00, t01, t02,
t10, t11, t12,
t20, t21, t22 ) ) == POSITIVE );
}
template < class R >
CGAL_KERNEL_LARGE_INLINE
typename Aff_transformation_repH3<R>::RT
Aff_transformation_repH3<R>::
homogeneous(int i, int j) const
{
typedef typename R::RT RT;
CGAL_kernel_precondition( (i >= 0) && (i <= 3) && (j >= 0) && (j <= 3) );
const RT RT0(0);
switch (i)
{
case 0: switch (j)
{
case 0: return t00;
case 1: return t01;
case 2: return t02;
case 3: return t03;
}
case 1: switch (j)
{
case 0: return t10;
case 1: return t11;
case 2: return t12;
case 3: return t13;
}
case 2: switch (j)
{
case 0: return t20;
case 1: return t21;
case 2: return t22;
case 3: return t23;
}
case 3: switch (j)
{
case 0: return RT0;
case 1: return RT0;
case 2: return RT0;
case 3: return t33;
}
}
return RT0;
}
template < class R >
inline
typename Aff_transformation_repH3<R>::FT
Aff_transformation_repH3<R>::
cartesian(int i, int j) const
{
typedef typename R::FT FT;
return FT(homogeneous(i,j)) / FT(t33);
}
template <class R>
Aff_transformation_repH3<R>
Identity_repH3<R>::general_form() const
{
typedef typename R::RT RT;
const RT RT0(0);
const RT RT1(1);
return Aff_transformation_repH3<R>(RT1, RT0, RT0, RT0,
RT0, RT1, RT0, RT0,
RT0, RT0, RT1, RT0,
RT1 );
}
template < class R >
inline
Translation_repH3<R>::
Translation_repH3( const typename Translation_repH3<R>::Vector_3& v)
: tv(v)
{}
template < class R >
CGAL_KERNEL_INLINE
typename Translation_repH3<R>::Point_3
Translation_repH3<R>::
transform(const typename Translation_repH3<R>::Point_3& p) const
{
return Point_3( tv.hw() * p.hx() + tv.hx() * p.hw(),
tv.hw() * p.hy() + tv.hy() * p.hw(),
tv.hw() * p.hz() + tv.hz() * p.hw(),
tv.hw() * p.hw() );
}
template < class R >
inline
typename Translation_repH3<R>::Vector_3
Translation_repH3<R>::
transform(const typename Translation_repH3<R>::Vector_3& v) const
{ return v; }
template < class R >
inline
typename Translation_repH3<R>::Direction_3
Translation_repH3<R>::
transform(const typename Translation_repH3<R>::Direction_3& dir) const
{ return dir; }
template < class R >
inline
typename Translation_repH3<R>::Plane_3
Translation_repH3<R>::
transform(const typename Translation_repH3<R>::Plane_3& pl) const
{
return Plane_3( transform( pl.point() ), pl.orthogonal_vector() );
}
template < class R >
inline
typename Translation_repH3<R>::Aff_transformation_3
Translation_repH3<R>::inverse() const
{ return Aff_transformation_3(TRANSLATION, - tv ); }
template < class R >
CGAL_KERNEL_INLINE
Aff_transformation_repH3<R>
Translation_repH3<R>::general_form() const
{
const RT RT0(0);
return Aff_transformation_repH3<R>(tv.hw(), RT0, RT0, tv.hx(),
RT0, tv.hw(), RT0, tv.hy(),
RT0, RT0, tv.hw(), tv.hz(),
tv.hw() );
}
template < class R >
CGAL_KERNEL_INLINE
typename Translation_repH3<R>::Aff_transformation_3
Translation_repH3<R>::transpose() const
{
typedef typename R::RT RT;
const RT RT0(0);
const RT RT1(1);
return Aff_transformation_3( RT1, RT0, RT0, RT0,
RT0, RT1, RT0, RT0,
RT0, RT0, RT1, RT0,
RT1 );
}
template < class R >
inline
bool
Translation_repH3<R>::is_even() const
{ return true; }
template < class R >
CGAL_KERNEL_LARGE_INLINE
typename Translation_repH3<R>::RT
Translation_repH3<R>::homogeneous(int i, int j) const
{
CGAL_kernel_precondition( (i >= 0) && (i <= 3) && (j >= 0) && (j <= 3) );
const RT RT0(0);
switch (i)
{
case 0: switch (j)
{
case 0: return tv.hw();
case 1: return RT0;
case 2: return RT0;
case 3: return tv.hx();
}
case 1: switch (j)
{
case 0: return RT0;
case 1: return tv.hw();
case 2: return RT0;
case 3: return tv.hy();
}
case 2: switch (j)
{
case 0: return RT0;
case 1: return RT0;
case 2: return tv.hw();
case 3: return tv.hz();
}
case 3: switch (j)
{
case 0: return RT0;
case 1: return RT0;
case 2: return RT0;
case 3: return tv.hw();
}
}
return RT0;
}
template < class R >
inline
typename Translation_repH3<R>::FT
Translation_repH3<R>::
cartesian(int i, int j) const
{
return FT(homogeneous(i,j)) / FT(tv.hw());
}
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>
_general_transformation_composition(
Aff_transformation_repH3<R> l,
Aff_transformation_repH3<R> r )
{
return Aff_transformationH3<R>(
l.t00*r.t00 + l.t01*r.t10 + l.t02*r.t20,
l.t00*r.t01 + l.t01*r.t11 + l.t02*r.t21,
l.t00*r.t02 + l.t01*r.t12 + l.t02*r.t22,
l.t00*r.t03 + l.t01*r.t13 + l.t02*r.t23 + l.t03*r.t33,
l.t10*r.t00 + l.t11*r.t10 + l.t12*r.t20,
l.t10*r.t01 + l.t11*r.t11 + l.t12*r.t21,
l.t10*r.t02 + l.t11*r.t12 + l.t12*r.t22,
l.t10*r.t03 + l.t11*r.t13 + l.t12*r.t23 + l.t13*r.t33,
l.t20*r.t00 + l.t21*r.t10 + l.t22*r.t20,
l.t20*r.t01 + l.t21*r.t11 + l.t22*r.t21,
l.t20*r.t02 + l.t21*r.t12 + l.t22*r.t22,
l.t20*r.t03 + l.t21*r.t13 + l.t22*r.t23 + l.t23*r.t33,
l.t33*r.t33 );
}
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>::Aff_transformationH3()
{ initialize_with(Aff_transformation_repH3<R>()); }
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>::
Aff_transformationH3(const Identity_transformation&)
{ initialize_with(Identity_repH3<R>()); }
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>::
Aff_transformationH3(const Translation&,
const typename Aff_transformationH3<R>::Vector_3& v)
{ initialize_with(Translation_repH3<R>( v )); }
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>::
Aff_transformationH3(const Scaling&, const RT& num, const RT& den)
{
const RT RT0(0);
initialize_with(Aff_transformation_repH3<R>(num, RT0, RT0, RT0,
RT0, num, RT0, RT0,
RT0, RT0, num, RT0,
den ));
}
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>::
Aff_transformationH3(
const RT& m00, const RT& m01, const RT& m02, const RT& m03,
const RT& m10, const RT& m11, const RT& m12, const RT& m13,
const RT& m20, const RT& m21, const RT& m22, const RT& m23,
const RT& m33)
{
initialize_with(Aff_transformation_repH3<R>(m00, m01, m02, m03,
m10, m11, m12, m13,
m20, m21, m22, m23,
m33 ));
}
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>::
Aff_transformationH3(
const RT& m00, const RT& m01, const RT& m02,
const RT& m10, const RT& m11, const RT& m12,
const RT& m20, const RT& m21, const RT& m22,
const RT& m33)
{
const RT RT0 = RT(0);
initialize_with(Aff_transformation_repH3<R>(m00, m01, m02, RT0,
m10, m11, m12, RT0,
m20, m21, m22, RT0,
m33 ));
}
template < class R >
inline
typename Aff_transformationH3<R>::Point_3
Aff_transformationH3<R>::
transform(const typename Aff_transformationH3<R>::Point_3& p) const
{ return this->Ptr()->transform(p); }
template < class R >
inline
typename Aff_transformationH3<R>::Vector_3
Aff_transformationH3<R>::
transform(const typename Aff_transformationH3<R>::Vector_3& v) const
{ return this->Ptr()->transform(v); }
template < class R >
inline
typename Aff_transformationH3<R>::Direction_3
Aff_transformationH3<R>::
transform(const typename Aff_transformationH3<R>::Direction_3& d) const
{ return this->Ptr()->transform(d); }
template < class R >
inline
typename Aff_transformationH3<R>::Plane_3
Aff_transformationH3<R>::
transform(const typename Aff_transformationH3<R>::Plane_3& pl) const
{ return this->Ptr()->transform(pl); }
template < class R >
inline
typename Aff_transformationH3<R>::Aff_transformation_3
Aff_transformationH3<R>::inverse() const
{ return this->Ptr()->inverse(); }
template < class R >
inline
Aff_transformationH3<R>
Aff_transformationH3<R>::transpose() const
{ return this->Ptr()->transpose(); }
template < class R >
inline
bool
Aff_transformationH3<R>::is_even() const
{ return this->Ptr()->is_even(); }
template < class R >
inline
bool
Aff_transformationH3<R>::is_odd() const
{ return ( ! (this->Ptr()->is_even() )); }
template < class R >
CGAL_KERNEL_INLINE
Aff_transformationH3<R>
operator*(const Aff_transformationH3<R>& left_argument,
const Aff_transformationH3<R>& right_argument )
{
return _general_transformation_composition(
left_argument.Ptr() ->general_form(),
right_argument.Ptr()->general_form() );
}
template < class R >
std::ostream &
operator<< ( std::ostream & out,
const Aff_transformationH3<R>& t)
{
typename R::RT RT0(0);
Aff_transformation_repH3<R> r = t.Ptr()->general_form();
return out
<< "| "<< r.t00 <<' '<< r.t01 <<' '<< r.t02 <<' '<< r.t03 << " |\n"
<< "| "<< r.t10 <<' '<< r.t11 <<' '<< r.t12 <<' '<< r.t13 << " |\n"
<< "| "<< r.t20 <<' '<< r.t21 <<' '<< r.t22 <<' '<< r.t23 << " |\n"
<< "| "<< RT0 <<' '<< RT0 <<' '<< RT0 <<' '<< r.t33 << " |\n";
}
CGAL_END_NAMESPACE
#endif // CGAL_AFF_TRANSFORMATIONH3_H
@@ -0,0 +1,364 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Sven Schoenherr
// Stefan Schirra
#ifndef CGAL_CIRCLEH2_H
#define CGAL_CIRCLEH2_H
#include <CGAL/utility.h>
#include <CGAL/Interval_arithmetic.h>
CGAL_BEGIN_NAMESPACE
template <class R_>
class CircleH2
{
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Aff_transformation_2 Aff_transformation_2;
typedef Triple<Point_2, FT, Orientation> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
CircleH2() {}
CircleH2(const Point_2& p, const Point_2& q, const Point_2& r)
{
Orientation o = CGAL::orientation( p, q, r);
CGAL_kernel_precondition( o != COLLINEAR);
Point_2 cp = circumcenter( p, q, r);
FT sq_r = squared_distance( p, cp);
base = Rep(cp, sq_r, o);
}
CircleH2(const Point_2& p, const Point_2& q, const Orientation& o)
{
CGAL_kernel_precondition( o != COLLINEAR);
if ( p != q)
{
Point_2 cp = midpoint( p, q);
FT sq_r = squared_distance( cp, p);
base = Rep(cp, sq_r, o);
}
else
base = Rep(p, FT( 0), o);
}
CircleH2(const Point_2& cp, const FT& squared_radius,
const Orientation& o)
{
CGAL_precondition( ( ! CGAL_NTS is_negative( squared_radius)) &&
( o != COLLINEAR ) );
base = Rep(cp, squared_radius, o);
}
Bbox_2
bbox() const;
CircleH2<R>
orthogonal_transform(const Aff_transformation_2&) const;
const Point_2 &
center() const;
Orientation
orientation() const;
const FT &
squared_radius() const;
CircleH2<R>
opposite() const;
Oriented_side
oriented_side(const Point_2& ) const;
Bounded_side
bounded_side(const Point_2& ) const;
bool operator==( const CircleH2<R>& ) const;
bool operator!=( const CircleH2<R>& ) const;
bool has_on_positive_side(const Point_2& ) const;
bool has_on_negative_side(const Point_2& ) const;
bool has_on_boundary( const Point_2& ) const;
bool has_on_bounded_side( const Point_2& ) const;
bool has_on_unbounded_side(const Point_2&) const;
bool is_degenerate() const;
// bool oriented_equal( const CircleH2<R>& ) const;
// bool unoriented_equal( const CircleH2<R>& ) const;
};
template <class R>
inline
const typename CircleH2<R>::Point_2 &
CircleH2<R>::center() const
{ return get(base).first; }
template <class R>
inline
const typename CircleH2<R>::FT &
CircleH2<R>::squared_radius() const
{ return get(base).second; }
template <class R>
CGAL_KERNEL_INLINE
CircleH2<R>
CircleH2<R>::opposite() const
{
return CircleH2<R>( center(),
squared_radius(),
CGAL::opposite( orientation() ) );
}
template <class R>
inline
Orientation
CircleH2<R>::orientation() const
{ return get(base).third; }
template <class R>
CGAL_KERNEL_INLINE
Oriented_side
CircleH2<R>::oriented_side( const typename CircleH2<R>::Point_2& p) const
{
FT sq_dist = squared_distance( p, center() );
FT sq_rad = squared_radius();
Comparison_result vgl = CGAL_NTS compare( sq_dist, sq_rad );
Oriented_side rel_pos = (vgl == LARGER ) ?
ON_NEGATIVE_SIDE :
( (vgl == SMALLER ) ?
ON_POSITIVE_SIDE :
ON_ORIENTED_BOUNDARY);
if (orientation() == POSITIVE)
{ return rel_pos; }
else // NEGATIVE
{ return CGAL::opposite( rel_pos ); }
}
template <class R>
CGAL_KERNEL_INLINE
bool
CircleH2<R>::has_on_positive_side(const typename CircleH2<R>::Point_2& p) const
{
if ( orientation() == POSITIVE )
{ return (has_on_bounded_side(p) ); }
else
{ return (has_on_unbounded_side(p) ); }
}
template <class R>
CGAL_KERNEL_INLINE
bool
CircleH2<R>::has_on_boundary(const typename CircleH2<R>::Point_2& p) const
{
FT sq_dist = squared_distance( p, center() );
FT sq_rad = squared_radius();
return ( sq_dist == sq_rad );
}
template <class R>
CGAL_KERNEL_INLINE
bool
CircleH2<R>::has_on_negative_side( const typename CircleH2<R>::Point_2&p) const
{
if ( orientation() == NEGATIVE )
{
return (has_on_bounded_side(p) );
}
else
{
return (has_on_unbounded_side(p) );
}
}
template <class R>
CGAL_KERNEL_INLINE
Bounded_side
CircleH2<R>::bounded_side(const typename CircleH2<R>::Point_2& p) const
{
FT sq_dist = squared_distance( p, center() );
FT sq_rad = squared_radius();
Comparison_result vgl = CGAL_NTS compare( sq_dist, sq_rad );
return (vgl == LARGER ) ? ON_UNBOUNDED_SIDE :
( (vgl == SMALLER ) ?
ON_BOUNDED_SIDE :
ON_BOUNDARY);
}
template <class R>
CGAL_KERNEL_INLINE
bool
CircleH2<R>::has_on_bounded_side(const typename CircleH2<R>::Point_2& p) const
{
FT sq_dist = squared_distance( p, center() );
FT sq_rad = squared_radius();
return ( sq_dist < sq_rad );
}
template <class R>
CGAL_KERNEL_INLINE
bool
CircleH2<R>::has_on_unbounded_side(const typename CircleH2<R>::Point_2&p) const
{
FT sq_dist = squared_distance( p, center() );
FT sq_rad = squared_radius();
return ( sq_rad < sq_dist );
}
template <class R>
inline
bool
CircleH2<R>::is_degenerate() const
{ return ( squared_radius() == FT(0) ); }
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
Bbox_2
CircleH2<R>::bbox() const
{
Bbox_2 b = center().bbox();
Interval_nt<> x (b.xmin(), b.xmax());
Interval_nt<> y (b.ymin(), b.ymax());
Interval_nt<> sqr = CGAL_NTS to_interval(squared_radius());
Interval_nt<> r = CGAL::sqrt(sqr);
Interval_nt<> minx = x-r;
Interval_nt<> maxx = x+r;
Interval_nt<> miny = y-r;
Interval_nt<> maxy = y+r;
return Bbox_2(minx.inf(), miny.inf(), maxx.sup(), maxy.sup());
}
template <class R>
CGAL_KERNEL_INLINE
CircleH2<R>
CircleH2<R>::
orthogonal_transform(const typename CircleH2<R>::Aff_transformation_2& t) const
{
typename R::Vector_2 vec( RT(1), RT(0) ); // unit vector
vec = vec.transform(t); // transformed
FT sq_scale = FT( vec*vec ); // squared scaling factor
if ( t.is_even() )
{
return CircleH2<R>(t.transform(center() ),
sq_scale * squared_radius(),
orientation() );
}
else
{
return CircleH2<R>(t.transform(center() ),
sq_scale * squared_radius(),
CGAL::opposite( orientation()) );
}
}
template <class R>
CGAL_KERNEL_INLINE
bool
CircleH2<R>::operator==(const CircleH2<R>& c) const
{
return ( center() == c.center() )
&&( squared_radius() == c.squared_radius() )
&&( orientation() == c.orientation() );
}
template <class R>
inline
bool
CircleH2<R>::operator!=(const CircleH2<R>& c) const
{ return !(*this == c); }
#ifndef CGAL_NO_OSTREAM_INSERT_CIRCLEH2
template < class R >
std::ostream &operator<<(std::ostream &os, const CircleH2<R> &c)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
os << c.center() << ' ' << c.squared_radius() << ' '
<< static_cast<int>(c.orientation());
break;
case IO::BINARY :
os << c.center();
write(os, c.squared_radius());
write(os, static_cast<int>(c.orientation()));
break;
default:
os << "CircleH2(" << c.center() << ", " << c.squared_radius() ;
if (c.orientation() == CLOCKWISE) {
os << ", clockwise)";
} else if (c.orientation() == COUNTERCLOCKWISE) {
os << ", counterclockwise)";
} else {
os << ", collinear)";
}
break;
}
return os;
}
#endif // CGAL_NO_OSTREAM_INSERT_CIRCLEH2
#ifndef CGAL_NO_ISTREAM_EXTRACT_CIRCLEH2
template < class R >
std::istream& operator>>(std::istream &is, CircleH2<R> &c)
{
typename R::Point_2 center;
typename R::FT squared_radius;
int o;
switch(is.iword(IO::mode))
{
case IO::ASCII :
is >> center >> squared_radius >> o;
break;
case IO::BINARY :
is >> center;
read(is, squared_radius);
is >> o;
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
c = CircleH2<R>(center, squared_radius, static_cast<Orientation>(o));
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_CIRCLEH2
CGAL_END_NAMESPACE
#endif // CGAL_CIRCLEH2_H
@@ -0,0 +1,59 @@
// Copyright (c) 1999,2001 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_DATA_ACCESSORH2_H
#define CGAL_DATA_ACCESSORH2_H
CGAL_BEGIN_NAMESPACE
template < class R >
class Data_accessorH2
{
public:
typedef typename R::FT FT;
typedef typename R::RT RT;
typedef typename R::Point_2 Point_2;
RT get_hx( const Point_2 & p) const { return( p.hx()); }
RT get_hy( const Point_2 & p) const { return( p.hy()); }
RT get_hw( const Point_2 & p) const { return( p.hw()); }
void
get( const Point_2 & p, RT& hx, RT& hy, RT& hw) const
{
hx = get_hx( p);
hy = get_hy( p);
hw = get_hw( p);
}
void
set( Point_2& p, const RT & hx, const RT & hy, const RT & hw) const
{
p = Point_2( hx, hy, hw);
}
};
CGAL_END_NAMESPACE
#endif // CGAL_DATA_ACCESSORH2_H
@@ -0,0 +1,174 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_HOMOGENEOUS_DIRECTION_2_H
#define CGAL_HOMOGENEOUS_DIRECTION_2_H
#include <CGAL/Threetuple.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class DirectionH2
{
typedef DirectionH2<R_> Self;
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Vector_2 Vector_2;
typedef typename R_::Line_2 Line_2;
typedef typename R_::Ray_2 Ray_2;
typedef typename R_::Segment_2 Segment_2;
typedef typename R_::Aff_transformation_2 Aff_transformation_2;
typedef Threetuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
typedef const RT& Homogeneous_coordinate_type;
const Self&
rep() const
{
return static_cast<const Self& >(*this);
}
DirectionH2() {}
DirectionH2(const RT& x, const RT& y)
: base (x, y, RT(1)) {}
// TODO Not documented : should not exist , not used.
// we should also change Threetuple<RT> -> Twotuple<RT>
DirectionH2(const RT& x, const RT& y, const RT& w )
{
if (w > RT(0) )
base = Rep(x, y, w);
else
base = Rep(-x, -y, -w);
}
bool operator==( const DirectionH2<R>& d) const;
bool operator!=( const DirectionH2<R>& d) const;
Vector_2 to_vector() const;
const RT & x() const { return get(base).e0; };
const RT & y() const { return get(base).e1; };
const RT & delta(int i) const;
const RT & dx() const { return get(base).e0; };
const RT & dy() const { return get(base).e1; };
DirectionH2<R> transform(const Aff_transformation_2 &) const;
};
template <class R >
CGAL_KERNEL_INLINE
bool
DirectionH2<R>::operator==( const DirectionH2<R>& d) const
{
return ( ( x() * d.y() == y() * d.x() )
&&( CGAL_NTS sign( x() ) == CGAL_NTS sign( d.x() ) )
&&( CGAL_NTS sign( y() ) == CGAL_NTS sign( d.y() ) ) );
}
template <class R >
inline
bool
DirectionH2<R>::operator!=( const DirectionH2<R>& d) const
{ return !(*this == d); }
CGAL_END_NAMESPACE
#include <CGAL/Homogeneous/predicates_on_directionsH2.h>
CGAL_BEGIN_NAMESPACE
template <class R >
inline
DirectionH2<R>
DirectionH2<R>::
transform(const typename DirectionH2<R>::Aff_transformation_2& t) const
{ return t.transform(*this); }
template <class R >
CGAL_KERNEL_INLINE
typename DirectionH2<R>::Vector_2
DirectionH2<R>::to_vector() const
{ return Vector_2(dx(), dy()); }
#ifndef CGAL_NO_OSTREAM_INSERT_DIRECTIONH2
template < class R >
std::ostream &
operator<<(std::ostream &os, const DirectionH2<R> &p)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << p.dx() << ' ' << p.dy();
case IO::BINARY :
write(os, p.dx());
write(os, p.dy());
return os;
default:
return os << "DirectionH2(" << p.dx() << ", "
<< p.dy() << ')';
}
}
#endif // CGAL_NO_OSTREAM_INSERT_DIRECTIONH2
#ifndef CGAL_NO_ISTREAM_EXTRACT_DIRECTIONH2
template < class R >
std::istream &
operator>>(std::istream &is, DirectionH2<R> &p)
{
typename R::RT x, y;
switch(is.iword(IO::mode))
{
case IO::ASCII :
is >> x >> y;
break;
case IO::BINARY :
read(is, x);
read(is, y);
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
p = DirectionH2<R>(x, y);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_DIRECTIONH2
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_DIRECTION_2_H
@@ -0,0 +1,217 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_HOMOGENEOUS_DIRECTION_3_H
#define CGAL_HOMOGENEOUS_DIRECTION_3_H
#include <CGAL/Fourtuple.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class DirectionH3
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Segment_3 Segment_3;
typedef typename R_::Line_3 Line_3;
typedef typename R_::Ray_3 Ray_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
typedef Fourtuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
DirectionH3() {}
//DirectionH3(const Point_3 & p )
//: base(p) {}
DirectionH3(const Vector_3 & v )
{ *this = v.direction(); }
DirectionH3(const Line_3 & l )
{ *this = l.direction(); }
DirectionH3(const Ray_3 & r )
{ *this = r.direction(); }
DirectionH3(const Segment_3 & s )
{ *this = s.direction(); }
// the fourth argument is not documented. Should go away ?
DirectionH3(const RT& x, const RT& y,
const RT& z, const RT& w = RT(1) )
{
if ( w >= RT(0) )
base = Rep(x,y,z,w);
else
base = Rep(-x,-y,-z,-w);
}
DirectionH3<R>
transform(const Aff_transformation_3 &) const ;
DirectionH3<R>
operator-() const;
bool is_degenerate() const;
bool operator==( const DirectionH3<R>& d) const;
bool operator!=( const DirectionH3<R>& d) const;
Vector_3 to_vector() const;
Vector_3 vector() const { return to_vector(); }
const RT & dx() const { return get(base).e0; }
const RT & dy() const { return get(base).e1; }
const RT & dz() const { return get(base).e2; }
const RT & x() const { return get(base).e0; }
const RT & y() const { return get(base).e1; }
const RT & z() const { return get(base).e2; }
const RT & hx() const { return get(base).e0; }
const RT & hy() const { return get(base).e1; }
const RT & hz() const { return get(base).e2; }
const RT & delta(int i) const;
};
template <class R >
CGAL_KERNEL_INLINE
const typename DirectionH3<R>::RT &
DirectionH3<R>::delta(int i) const
{
switch (i)
{
case 0: return x();
case 1: return y();
case 2: return z();
default: return delta( i%3 );
}
}
template <class R >
CGAL_KERNEL_INLINE
bool
DirectionH3<R>::operator==( const DirectionH3<R>& d) const
{
return ( ( hx()*d.hy() == hy()*d.hx() )
&&( hx()*d.hz() == hz()*d.hx() )
&&( hy()*d.hz() == hz()*d.hy() )
&&( CGAL_NTS sign( hx() ) == CGAL_NTS sign( d.hx() ) )
&&( CGAL_NTS sign( hy() ) == CGAL_NTS sign( d.hy() ) )
&&( CGAL_NTS sign( hz() ) == CGAL_NTS sign( d.hz() ) ) );
}
template <class R >
inline
bool
DirectionH3<R>::operator!=( const DirectionH3<R>& d) const
{ return !operator==(d); }
template <class R >
CGAL_KERNEL_INLINE
bool
DirectionH3<R>::is_degenerate() const
{ return ((hx() == RT(0)) && (hy() == RT(0)) && (hz() == RT(0))); }
template <class R >
inline
DirectionH3<R>
DirectionH3<R>::operator-() const
{ return DirectionH3<R>(- hx(),- hy(),- hz() ); }
template <class R >
inline
typename DirectionH3<R>::Vector_3
DirectionH3<R>::to_vector() const
{ return Vector_3(dx(), dy(), dz(), RT(1)); }
template <class R>
CGAL_KERNEL_INLINE
DirectionH3<R>
cross_product( const DirectionH3<R>& d1,
const DirectionH3<R>& d2)
{ return cross_product(d1.to_vector(),d2.to_vector()).direction(); }
template <class R >
inline
DirectionH3<R>
DirectionH3<R>::
transform(const typename DirectionH3<R>::Aff_transformation_3& t) const
{ return t.transform(*this); }
#ifndef CGAL_NO_OSTREAM_INSERT_DIRECTIONH3
template < class R >
std::ostream &operator<<(std::ostream &os, const DirectionH3<R> &p)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << p.dx() << ' ' << p.dy() << ' ' << p.dz();
case IO::BINARY :
write(os, p.dx());
write(os, p.dy());
write(os, p.dz());
return os;
default:
return os << "DirectionH3(" << p.dx() << ", "
<< p.dy() << ", "
<< p.dz() << ')';
}
}
#endif // CGAL_NO_OSTREAM_INSERT_DIRECTIONH3
#ifndef CGAL_NO_ISTREAM_EXTRACT_DIRECTIONH3
template < class R >
std::istream &operator>>(std::istream &is, DirectionH3<R> &p)
{
typename R::RT x, y, z;
switch(is.iword(IO::mode))
{
case IO::ASCII :
is >> x >> y >> z;
break;
case IO::BINARY :
read(is, x);
read(is, y);
read(is, z);
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
p = DirectionH3<R>(x, y, z);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_DIRECTIONH3
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_DIRECTION_3_H
@@ -0,0 +1,152 @@
// 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra, Sylvain Pion
#ifndef CGAL_HOMOGENEOUS_BASE_H
#define CGAL_HOMOGENEOUS_BASE_H
#define CGAL_REP_CLASS_DEFINED
#include <CGAL/basic.h>
#include <CGAL/basic_classes.h>
#include <CGAL/Kernel/global_functions.h>
#include <CGAL/Homogeneous/Aff_transformationH2.h>
#include <CGAL/Cartesian/Circle_2.h>
//#include <CGAL/Cartesian/Direction_2.h>
#include <CGAL/Homogeneous/DirectionH2.h>
#include <CGAL/Homogeneous/Iso_rectangleH2.h>
#include <CGAL/Homogeneous/LineH2.h>
#include <CGAL/Homogeneous/PointH2.h>
#include <CGAL/Cartesian/Ray_2.h>
#include <CGAL/Cartesian/Segment_2.h>
#include <CGAL/Cartesian/Triangle_2.h>
#include <CGAL/Homogeneous/VectorH2.h>
#include <CGAL/Homogeneous/Data_accessorH2.h>
#include <CGAL/ConicHPA2.h>
#include <CGAL/Homogeneous/Aff_transformationH3.h>
#include <CGAL/Homogeneous/DirectionH3.h>
#include <CGAL/Homogeneous/Iso_cuboidH3.h>
#include <CGAL/Cartesian/Line_3.h>
#include <CGAL/Homogeneous/PlaneH3.h>
#include <CGAL/Homogeneous/PointH3.h>
#include <CGAL/Homogeneous/RayH3.h>
#include <CGAL/Cartesian/Segment_3.h>
#include <CGAL/Homogeneous/SphereH3.h>
#include <CGAL/Cartesian/Tetrahedron_3.h>
#include <CGAL/Cartesian/Triangle_3.h>
#include <CGAL/Homogeneous/VectorH3.h>
#include <CGAL/Homogeneous/basic_constructionsH2.h>
#include <CGAL/Homogeneous/distance_predicatesH2.h>
#include <CGAL/Homogeneous/predicates_on_directionsH2.h>
#include <CGAL/Homogeneous/predicates_on_pointsH2.h>
#include <CGAL/Homogeneous/predicates_on_rtH2.h>
#include <CGAL/Homogeneous/basic_constructionsH3.h>
#include <CGAL/Homogeneous/distance_predicatesH3.h>
#include <CGAL/Homogeneous/predicates_on_pointsH3.h>
#include <CGAL/Homogeneous/predicates_on_pointsH2.h>
#include <CGAL/representation_tags.h>
#include <CGAL/Homogeneous/function_objects.h>
CGAL_BEGIN_NAMESPACE
template <typename RT_, typename FT_, typename K_ >
struct Homogeneous_base
{
typedef K_ Kernel;
typedef FT_ FT;
typedef Homogeneous_tag Rep_tag;
typedef Homogeneous_tag Kernel_tag;
typedef CGAL::Object Object_2;
typedef CGAL::Object Object_3;
// These are currently undocumented.
// Should they be part of the Kernel interface ?
typedef typename Same_uncertainty_nt<bool, FT>::type
Bool;
typedef typename Same_uncertainty_nt<CGAL::Sign, FT>::type
Sign;
typedef typename Same_uncertainty_nt<CGAL::Comparison_result, FT>::type
Comparison_result;
typedef typename Same_uncertainty_nt<CGAL::Orientation, FT>::type
Orientation;
typedef typename Same_uncertainty_nt<CGAL::Oriented_side, FT>::type
Oriented_side;
typedef typename Same_uncertainty_nt<CGAL::Bounded_side, FT>::type
Bounded_side;
typedef typename Same_uncertainty_nt<CGAL::Angle, FT>::type
Angle;
typedef PointH2<Kernel> Point_2;
typedef VectorH2<Kernel> Vector_2;
typedef DirectionH2<Kernel> Direction_2;
typedef SegmentC2<Kernel> Segment_2;
typedef LineH2<Kernel> Line_2;
typedef RayC2<Kernel> Ray_2;
typedef CircleC2<Kernel> Circle_2;
typedef TriangleC2<Kernel> Triangle_2;
typedef Iso_rectangleH2<Kernel> Iso_rectangle_2;
typedef Aff_transformationH2<Kernel> Aff_transformation_2;
typedef PointH3<Kernel> Point_3;
typedef VectorH3<Kernel> Vector_3;
typedef DirectionH3<Kernel> Direction_3;
typedef SegmentC3<Kernel> Segment_3;
typedef PlaneH3<Kernel> Plane_3;
typedef LineC3<Kernel> Line_3;
typedef RayH3<Kernel> Ray_3;
typedef TriangleC3<Kernel> Triangle_3;
typedef TetrahedronC3<Kernel> Tetrahedron_3;
typedef Iso_cuboidH3<Kernel> Iso_cuboid_3;
typedef SphereH3<Kernel> Sphere_3;
typedef Aff_transformationH3<Kernel> Aff_transformation_3;
typedef Cartesian_coordinate_iterator_2<Kernel>
Cartesian_const_iterator_2;
typedef Cartesian_coordinate_iterator_3<Kernel>
Cartesian_const_iterator_3;
typedef FT_ Cartesian_coordinate_type;
typedef const RT_& Homogeneous_coordinate_type;
// Undocumented stuff.
typedef Data_accessorH2<Kernel> Data_accessor_2;
typedef ConicHPA2<Point_2, Data_accessor_2> Conic_2;
// Functors types and access functions.
#define CGAL_Kernel_pred(Y,Z) typedef HomogeneousKernelFunctors::Y<Kernel> Y; \
Y Z() const { return Y(); }
#define CGAL_Kernel_cons(Y,Z) CGAL_Kernel_pred(Y,Z)
#include <CGAL/Kernel/interface_macros.h>
};
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_BASE_H
@@ -0,0 +1,420 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_ISO_CUBOIDH3_H
#define CGAL_ISO_CUBOIDH3_H
#include <CGAL/Twotuple.h>
CGAL_BEGIN_NAMESPACE
template <class R_>
class Iso_cuboidH3
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
typedef Twotuple<Point_3> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
Iso_cuboidH3() {}
Iso_cuboidH3(const Point_3& p, const Point_3& q);
Iso_cuboidH3(const Point_3& left, const Point_3& right,
const Point_3& bottom, const Point_3& top,
const Point_3& far_, const Point_3& close);
Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz,
const RT& max_hx, const RT& max_hy, const RT& max_hz,
const RT& hw);
Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz,
const RT& max_hx, const RT& max_hy, const RT& max_hz);
bool operator==(const Iso_cuboidH3<R>& s) const;
bool operator!=(const Iso_cuboidH3<R>& s) const;
const Point_3 & min() const;
const Point_3 & max() const;
Point_3 vertex(int i) const;
Point_3 operator[](int i) const;
Iso_cuboidH3<R>
transform(const Aff_transformation_3& t) const;
Bounded_side
bounded_side(const Point_3& p) const;
bool has_on(const Point_3& p) const;
bool has_on_boundary(const Point_3& p) const;
bool has_on_bounded_side(const Point_3& p) const;
bool has_on_unbounded_side(const Point_3& p) const;
bool is_degenerate() const;
Bbox_3 bbox() const;
FT xmin() const;
FT ymin() const;
FT zmin() const;
FT xmax() const;
FT ymax() const;
FT zmax() const;
FT min_coord(int i) const;
FT max_coord(int i) const;
FT volume() const;
};
template < class R >
CGAL_KERNEL_LARGE_INLINE
Iso_cuboidH3<R>::
Iso_cuboidH3(const typename Iso_cuboidH3<R>::Point_3& p,
const typename Iso_cuboidH3<R>::Point_3& q)
{
bool px_k_qx = ( p.hx()*q.hw() < q.hx()*p.hw() );
bool py_k_qy = ( p.hy()*q.hw() < q.hy()*p.hw() );
bool pz_k_qz = ( p.hz()*q.hw() < q.hz()*p.hw() );
RT minx;
RT miny;
RT minz;
RT maxx;
RT maxy;
RT maxz;
RT minw = p.hw()*q.hw();
RT maxw = p.hw()*q.hw();
if ( px_k_qx )
{
minx = p.hx()*q.hw();
maxx = q.hx()*p.hw();
}
else
{
minx = q.hx()*p.hw();
maxx = p.hx()*q.hw();
}
if ( py_k_qy )
{
miny = p.hy()*q.hw();
maxy = q.hy()*p.hw();
}
else
{
miny = q.hy()*p.hw();
maxy = p.hy()*q.hw();
}
if ( pz_k_qz )
{
minz = p.hz()*q.hw();
maxz = q.hz()*p.hw();
}
else
{
minz = q.hz()*p.hw();
maxz = p.hz()*q.hw();
}
base = Rep(Point_3(minx, miny, minz, minw),
Point_3(maxx, maxy, maxz, maxw));
}
template < class R >
CGAL_KERNEL_LARGE_INLINE
Iso_cuboidH3<R>::
Iso_cuboidH3(const typename Iso_cuboidH3<R>::Point_3& left,
const typename Iso_cuboidH3<R>::Point_3& right,
const typename Iso_cuboidH3<R>::Point_3& bottom,
const typename Iso_cuboidH3<R>::Point_3& top,
const typename Iso_cuboidH3<R>::Point_3& far_,
const typename Iso_cuboidH3<R>::Point_3& close)
: base(Point_3(left.hx() * bottom.hw() * far_.hw(),
bottom.hy() * left.hw() * far_.hw(),
far_.hz() * left.hw() * bottom.hw(),
left.hw() * bottom.hw() * far_.hw()),
Point_3(right.hx() * top.hw() * close.hw(),
top.hy() * right.hw() * close.hw(),
close.hz() * right.hw() * top.hw(),
right.hw() * top.hw() * close.hw()))
{
CGAL_kernel_precondition(!less_x(right, left));
CGAL_kernel_precondition(!less_y(top, bottom));
CGAL_kernel_precondition(!less_z(close, far_));
}
template < class R >
CGAL_KERNEL_LARGE_INLINE
Iso_cuboidH3<R>::
Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz,
const RT& max_hx, const RT& max_hy, const RT& max_hz)
: base(Point_3(min_hx, min_hy, min_hz, RT(1)),
Point_3(max_hx, max_hy, max_hz, RT(1)))
{}
template < class R >
CGAL_KERNEL_LARGE_INLINE
Iso_cuboidH3<R>::
Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz,
const RT& max_hx, const RT& max_hy, const RT& max_hz,
const RT& hw)
: base(Point_3(min_hx, min_hy, min_hz, hw),
Point_3(max_hx, max_hy, max_hz, hw))
{}
template < class R >
CGAL_KERNEL_INLINE
bool
Iso_cuboidH3<R>::
operator==(const Iso_cuboidH3<R>& r) const
{ return (min() == r.min()) && (max() == r.max()); }
template < class R >
inline
bool
Iso_cuboidH3<R>::
operator!=(const Iso_cuboidH3<R>& r) const
{ return !(*this == r); }
template < class R >
inline
const typename Iso_cuboidH3<R>::Point_3 &
Iso_cuboidH3<R>::min() const
{ return get(base).e0; }
template < class R >
inline
const typename Iso_cuboidH3<R>::Point_3 &
Iso_cuboidH3<R>::max() const
{ return get(base).e1; }
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::xmin() const
{ return FT( min().hx() ) / FT( min().hw() ); }
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::ymin() const
{ return FT( min().hy() ) / FT( min().hw() ); }
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::zmin() const
{ return FT( min().hz() ) / FT( min().hw() ); }
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::xmax() const
{ return FT( max().hx() ) / FT( max().hw() ); }
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::ymax() const
{ return FT( max().hy() ) / FT( max().hw() ); }
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::zmax() const
{ return FT( max().hz() ) / FT( max().hw() ); }
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::min_coord(int i) const
{
CGAL_kernel_precondition(i == 0 || i == 1 || i == 2);
if ( i == 0 )
return xmin();
else if (i == 1)
return ymin();
return zmin();
}
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::max_coord(int i) const
{
CGAL_kernel_precondition(i == 0 || i == 1 || i == 2);
if ( i == 0 )
return xmax();
else if ( i == 1 )
return ymax();
return zmax();
}
template < class R >
inline
typename Iso_cuboidH3<R>::FT
Iso_cuboidH3<R>::volume() const
{ return (xmax() - xmin()) * (ymax() - ymin()) * (zmax() - zmin()); }
template < class R >
CGAL_KERNEL_LARGE_INLINE
typename Iso_cuboidH3<R>::Point_3
Iso_cuboidH3<R>::vertex(int i) const
{
switch (i%8)
{
case 0: return min();
case 1: return Point_3( max().hx(), min().hy(),
min().hz(), min().hw() );
case 2: return Point_3( max().hx(), max().hy(),
min().hz(), min().hw() );
case 3: return Point_3( min().hx(), max().hy(),
min().hz(), min().hw() );
case 4: return Point_3( min().hx(), max().hy(),
max().hz(), min().hw() );
case 5: return Point_3( min().hx(), min().hy(),
max().hz(), min().hw() );
case 6: return Point_3( max().hx(), min().hy(),
max().hz(), min().hw() );
default: /*case 7:*/ return max();
}
}
template < class R >
inline
typename Iso_cuboidH3<R>::Point_3
Iso_cuboidH3<R>::operator[](int i) const
{ return vertex(i); }
template < class R >
CGAL_KERNEL_MEDIUM_INLINE
Bounded_side
Iso_cuboidH3<R>::
bounded_side(const typename Iso_cuboidH3<R>::Point_3& p) const
{
if ( (p.hx()*min().hw() < min().hx()*p.hw() )
||(p.hy()*min().hw() < min().hy()*p.hw() )
||(p.hz()*min().hw() < min().hz()*p.hw() )
||(p.hx()*max().hw() > max().hx()*p.hw() )
||(p.hy()*max().hw() > max().hy()*p.hw() )
||(p.hz()*max().hw() > max().hz()*p.hw() ) )
{ return ON_UNBOUNDED_SIDE; }
if ( (p.hx()*min().hw() == min().hx()*p.hw() )
||(p.hy()*min().hw() == min().hy()*p.hw() )
||(p.hz()*min().hw() == min().hz()*p.hw() )
||(p.hx()*max().hw() == max().hx()*p.hw() )
||(p.hy()*max().hw() == max().hy()*p.hw() )
||(p.hz()*max().hw() == max().hz()*p.hw() ) )
{ return ON_BOUNDARY; }
else
{ return ON_BOUNDED_SIDE; }
}
template < class R >
inline
bool
Iso_cuboidH3<R>::
has_on_boundary(const typename Iso_cuboidH3<R>::Point_3& p) const
{ return ( bounded_side(p) == ON_BOUNDARY ); }
template < class R >
inline
bool
Iso_cuboidH3<R>::has_on(const typename Iso_cuboidH3<R>::Point_3& p) const
{ return ( bounded_side(p) == ON_BOUNDARY ); }
template < class R >
inline
bool
Iso_cuboidH3<R>::
has_on_bounded_side(const typename Iso_cuboidH3<R>::Point_3& p) const
{ return ( bounded_side(p) == ON_BOUNDED_SIDE ); }
template < class R >
CGAL_KERNEL_INLINE
bool
Iso_cuboidH3<R>::
has_on_unbounded_side(const typename Iso_cuboidH3<R>::Point_3& p) const
{
return ( ( lexicographically_xyz_smaller(p,min() ))
||( lexicographically_xyz_smaller(max(),p )) );
}
template < class R >
CGAL_KERNEL_INLINE
bool
Iso_cuboidH3<R>::is_degenerate() const
{
return ( ( min().hx() == max().hx() )
|| ( min().hy() == max().hy() )
|| ( min().hz() == max().hz() ) );
}
template < class R >
inline
Bbox_3
Iso_cuboidH3<R>::bbox() const
{ return min().bbox() + max().bbox(); }
template < class R >
CGAL_KERNEL_INLINE
Iso_cuboidH3<R>
Iso_cuboidH3<R>::
transform(const typename Iso_cuboidH3<R>::Aff_transformation_3&t) const
{
return Iso_cuboidH3<R>(t.transform(min() ),
t.transform(max() ) );
}
#ifndef CGAL_NO_OSTREAM_INSERT_ISO_CUBOIDH3
template < class R >
std::ostream& operator<<(std::ostream& os, const Iso_cuboidH3<R>& r)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << r.min() << ' ' << r.max();
case IO::BINARY :
return os << r.min() << r.max();
default:
return os << "Iso_cuboidH3(" << r.min() << ", " << r.max() << ")";
}
}
#endif // CGAL_NO_OSTREAM_INSERT_ISO_CUBOIDH3
#ifndef CGAL_NO_ISTREAM_EXTRACT_ISO_CUBOIDH3
template < class R >
std::istream& operator>>(std::istream& is, Iso_cuboidH3<R>& r)
{
typename R::Point_3 p, q;
is >> p >> q;
r = Iso_cuboidH3<R>(p, q);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_ISO_CUBOIDH3
CGAL_END_NAMESPACE
#endif // CGAL_ISO_CUBOIDH3_H
@@ -0,0 +1,133 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_ISO_RECTANGLEH2_H
#define CGAL_ISO_RECTANGLEH2_H
#include <CGAL/Twotuple.h>
CGAL_BEGIN_NAMESPACE
template <class R_>
class Iso_rectangleH2
{
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Aff_transformation_2 Aff_transformation_2;
typedef typename R_::Iso_rectangle_2 Iso_rectangle_2;
typedef Twotuple<Point_2> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
typedef typename Point_2::Rep::Cartesian_coordinate_type Cartesian_coordinate_type;
typedef typename Point_2::Rep::Homogeneous_coordinate_type Homogeneous_coordinate_type;
Iso_rectangleH2() {}
Iso_rectangleH2(const Point_2& p, const Point_2& q)
: base(p,q)
{}
const Point_2 & min() const;
const Point_2 & max() const;
Iso_rectangle_2
transform(const Aff_transformation_2& t) const
{
// FIXME : We need a precondition like this!!!
// CGAL_kernel_precondition(t.is_axis_preserving());
return Iso_rectangle_2(t.transform(min()), t.transform(max()));
}
Bounded_side bounded_side(const Point_2& p) const;
};
template < class R >
inline
const typename Iso_rectangleH2<R>::Point_2 &
Iso_rectangleH2<R>::min() const
{ return get(base).e0; }
template < class R >
inline
const typename Iso_rectangleH2<R>::Point_2 &
Iso_rectangleH2<R>::max() const
{ return get(base).e1; }
template < class R >
CGAL_KERNEL_INLINE
Bounded_side
Iso_rectangleH2<R>::
bounded_side(const typename Iso_rectangleH2<R>::Point_2& p) const
{
Oriented_side wrt_min = _where_wrt_L_wedge(min(),p);
Oriented_side wrt_max = _where_wrt_L_wedge(p,max());
if (( wrt_min == ON_NEGATIVE_SIDE )||( wrt_max == ON_NEGATIVE_SIDE))
{
return ON_UNBOUNDED_SIDE;
}
if ( ( wrt_min == ON_ORIENTED_BOUNDARY )
||( wrt_max == ON_ORIENTED_BOUNDARY ) )
{
return ON_BOUNDARY;
}
return ON_BOUNDED_SIDE;
}
#ifndef CGAL_NO_OSTREAM_INSERT_ISO_RECTANGLEH2
template < class R >
std::ostream& operator<<(std::ostream& os, const Iso_rectangleH2<R>& r)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << r.min() << ' ' << r.max();
case IO::BINARY :
return os << r.min() << r.max();
default:
return os << "Iso_rectangleH2(" << r.min() << ", " << r.max() << ")";
}
}
#endif // CGAL_NO_OSTREAM_INSERT_ISO_RECTANGLEH2
#ifndef CGAL_NO_ISTREAM_EXTRACT_ISO_RECTANGLEH2
template < class R >
std::istream& operator>>(std::istream& is, Iso_rectangleH2<R>& r)
{
typename R::Point_2 p, q;
is >> p >> q;
r = Iso_rectangleH2<R>(p, q);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_ISO_RECTANGLEH2
CGAL_END_NAMESPACE
#endif // CGAL_ISO_RECTANGLEH2_H
@@ -0,0 +1,104 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_LINEH2_H
#define CGAL_LINEH2_H
#include <CGAL/Threetuple.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class LineH2
{
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Vector_2 Vector_2;
typedef typename R_::Direction_2 Direction_2;
typedef typename R_::Segment_2 Segment_2;
typedef typename R_::Ray_2 Ray_2;
typedef typename R_::Line_2 Line_2;
typedef Threetuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
LineH2() {}
LineH2(const RT& a, const RT& b, const RT& c)
: base(a,b,c)
{}
bool operator==(const LineH2<R>& l) const ;
bool operator!=(const LineH2<R>& l) const ;
const RT & a() const { return get(base).e0; }
const RT & b() const { return get(base).e1; }
const RT & c() const { return get(base).e2; }
};
template < class R >
CGAL_KERNEL_MEDIUM_INLINE
bool
LineH2<R>::operator==(const LineH2<R>& l) const
{
if ( (a() * l.c() != l.a() * c() )
||(b() * l.c() != l.b() * c() ) )
{
return false;
}
int sc = static_cast<int>(CGAL_NTS sign(c()));
int slc = static_cast<int>(CGAL_NTS sign(l.c()));
if ( sc == slc )
{
if (sc == 0)
return ( (a()*l.b() == b()*l.a() )
&&(CGAL_NTS sign(a() )== CGAL_NTS sign( l.a() ))
&&(CGAL_NTS sign(b() )== CGAL_NTS sign( l.b() )) );
else
return true;
}
else
return false;
}
template < class R >
inline
bool
LineH2<R>::operator!=(const LineH2<R>& l) const
{ return !(*this == l); }
CGAL_END_NAMESPACE
#endif // CGAL_LINEH2_H
@@ -0,0 +1,610 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_PLANEH3_H
#define CGAL_PLANEH3_H
#include <CGAL/Fourtuple.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class PlaneH3
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Line_3 Line_3;
typedef typename R_::Segment_3 Segment_3;
typedef typename R_::Ray_3 Ray_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Plane_3 Plane_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
typedef Fourtuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
PlaneH3() {}
PlaneH3(const Point_3&, const Point_3&, const Point_3& );
PlaneH3(const RT& a, const RT& b,
const RT& c, const RT& d );
PlaneH3(const Point_3&, const Ray_3& );
PlaneH3(const Point_3&, const Line_3& );
PlaneH3(const Point_3&, const Segment_3& );
PlaneH3(const Line_3&, const Point_3& );
PlaneH3(const Segment_3&, const Point_3& );
PlaneH3(const Ray_3&, const Point_3& );
PlaneH3(const Point_3&, const Direction_3& );
PlaneH3(const Point_3&, const Vector_3& );
PlaneH3(const Point_3&, const Direction_3&, const Direction_3& );
const RT & a() const;
const RT & b() const;
const RT & c() const;
const RT & d() const;
bool operator==( const PlaneH3<R>& ) const;
bool operator!=( const PlaneH3<R>& ) const;
Line_3 perpendicular_line(const Point_3& ) const;
Plane_3 opposite() const; // plane with opposite orientation
Point_3 projection(const Point_3& ) const;
Point_3 point() const; // same point on the plane
Direction_3
orthogonal_direction() const;
Vector_3
orthogonal_vector() const;
Oriented_side oriented_side(const Point_3 &p) const;
bool has_on(const Point_3 &p) const;
bool has_on(const Line_3 &p) const;
bool has_on_positive_side(const Point_3&l) const;
bool has_on_negative_side(const Point_3&l) const;
bool is_degenerate() const;
Plane_3 transform(const Aff_transformation_3& ) const;
Aff_transformation_3 transform_to_2d() const;
Point_2 to_2d(const Point_3& ) const;
Point_3 to_3d(const Point_2& ) const;
Vector_3 base1() const;
Vector_3 base2() const;
protected:
Point_3 point1() const; // same point different from point()
Point_3 point2() const; // same point different from point()
// and point1()
void new_rep(const Point_3 &p,
const Point_3 &q,
const Point_3 &r);
void new_rep(const RT &a, const RT &b,
const RT &c, const RT &d);
};
//
// a() * X + b() * Y + c() * Z() + d() * W() == 0
//
// | X Y Z W |
// | p.hx() p.hy() p.hz() p.hw() |
// | q.hx() q.hy() q.hz() q.hw() |
// | r.hx() r.hy() r.hz() r.hw() |
//
// Fourtuple<RT> ( a(), b(), c(), d() )
template < class R >
inline
void
PlaneH3<R>::new_rep(const typename PlaneH3<R>::Point_3 &p,
const typename PlaneH3<R>::Point_3 &q,
const typename PlaneH3<R>::Point_3 &r)
{
RT phx = p.hx();
RT phy = p.hy();
RT phz = p.hz();
RT phw = p.hw();
RT qhx = q.hx();
RT qhy = q.hy();
RT qhz = q.hz();
RT qhw = q.hw();
RT rhx = r.hx();
RT rhy = r.hy();
RT rhz = r.hz();
RT rhw = r.hw();
base = Rep (
phy*( qhz*rhw - qhw*rhz )
- qhy*( phz*rhw - phw*rhz ) // * X
+ rhy*( phz*qhw - phw*qhz ),
- phx*( qhz*rhw - qhw*rhz )
+ qhx*( phz*rhw - phw*rhz ) // * Y
- rhx*( phz*qhw - phw*qhz ),
phx*( qhy*rhw - qhw*rhy )
- qhx*( phy*rhw - phw*rhy ) // * Z
+ rhx*( phy*qhw - phw*qhy ),
- phx*( qhy*rhz - qhz*rhy )
+ qhx*( phy*rhz - phz*rhy ) // * W
- rhx*( phy*qhz - phz*qhy ) );
}
template < class R >
inline
void
PlaneH3<R>::new_rep(const RT &a, const RT &b, const RT &c, const RT &d)
{ base = Rep(a, b, c, d); }
template < class R >
inline
bool
PlaneH3<R>::operator!=(const PlaneH3<R>& l) const
{
return !(*this == l);
}
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Point_3& p,
const typename PlaneH3<R>::Point_3& q,
const typename PlaneH3<R>::Point_3& r)
{ new_rep(p,q,r); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const RT& a, const RT& b,
const RT& c, const RT& d)
{ new_rep(a,b,c,d); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Point_3& p ,
const typename PlaneH3<R>::Line_3& l)
{ new_rep(p, l.point(0), l.point(1) ); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Point_3& p,
const typename PlaneH3<R>::Segment_3& s)
{ new_rep(p, s.source(), s.target() ); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Point_3& p ,
const typename PlaneH3<R>::Ray_3& r)
{ new_rep(p, r.start(), r.start() + r.direction().to_vector() ); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Line_3& l ,
const typename PlaneH3<R>::Point_3& p)
{ new_rep(l.point(0), p, l.point(1) ); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Segment_3& s,
const typename PlaneH3<R>::Point_3& p)
{ new_rep(s.source(), p, s.target() ); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Ray_3& r,
const typename PlaneH3<R>::Point_3& p)
{ new_rep(r.start(), p, r.start() + r.direction().to_vector() ); }
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Point_3& p,
const typename PlaneH3<R>::Direction_3& d)
{
Vector_3 ov = d.to_vector();
new_rep( ov.hx()*p.hw(),
ov.hy()*p.hw(),
ov.hz()*p.hw(),
-(ov.hx()*p.hx() + ov.hy()*p.hy() + ov.hz()*p.hz() ) );
}
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Point_3& p,
const typename PlaneH3<R>::Vector_3& ov)
{
new_rep( ov.hx()*p.hw(),
ov.hy()*p.hw(),
ov.hz()*p.hw(),
-(ov.hx()*p.hx() + ov.hy()*p.hy() + ov.hz()*p.hz() ) );
}
template < class R >
CGAL_KERNEL_INLINE
PlaneH3<R>::PlaneH3(const typename PlaneH3<R>::Point_3& p,
const typename PlaneH3<R>::Direction_3& d1,
const typename PlaneH3<R>::Direction_3& d2)
{ new_rep( p, p + d1.to_vector(), p + d2.to_vector() ); }
template < class R >
inline
const typename PlaneH3<R>::RT &
PlaneH3<R>::a() const
{ return get(base).e0; }
template < class R >
inline
const typename PlaneH3<R>::RT &
PlaneH3<R>::b() const
{ return get(base).e1; }
template < class R >
inline
const typename PlaneH3<R>::RT &
PlaneH3<R>::c() const
{ return get(base).e2; }
template < class R >
inline
const typename PlaneH3<R>::RT &
PlaneH3<R>::d() const
{ return get(base).e3; }
template < class R >
CGAL_KERNEL_INLINE
typename PlaneH3<R>::Line_3
PlaneH3<R>::perpendicular_line(const typename PlaneH3<R>::Point_3& p) const
{ return Line_3( p, orthogonal_direction() ); }
template < class R >
CGAL_KERNEL_INLINE
typename PlaneH3<R>::Plane_3
PlaneH3<R>::opposite() const
{ return PlaneH3<R>(-a(), -b(), -c(), -d() ); }
template < class R >
CGAL_KERNEL_INLINE
typename PlaneH3<R>::Point_3
PlaneH3<R>::projection(const typename PlaneH3<R>::Point_3& p) const
{ return _projection( p, *this ); }
template < class R >
CGAL_KERNEL_INLINE
typename PlaneH3<R>::Point_3
PlaneH3<R>::point() const
{
const RT RT0(0);
if ( a() != RT0 )
{
return Point_3( -d(), RT0, RT0, a() );
}
if ( b() != RT0 )
{
return Point_3( RT0, -d(), RT0, b() );
}
CGAL_kernel_assertion ( c() != RT0);
return Point_3( RT0, RT0, -d(), c() );
}
template < class R >
CGAL_KERNEL_INLINE
typename PlaneH3<R>::Vector_3
PlaneH3<R>::base1() const
{
// point():
// a() != RT0 : Point_3( -d(), RT0, RT0, a() );
// b() != RT0 : Point_3( RT0, -d(), RT0, b() );
// : Point_3( RT0, RT0, -d(), c() );
// point1():
// a() != RT0 : Point_3( -b()-d(), a(), RT0, a() );
// b() != RT0 : Point_3( RT0, -c()-d(), b(), b() );
// : Point_3( c(), RT0, -a()-d(), c() );
const RT RT0(0);
if ( a() != RT0 )
{
return Vector_3( -b(), a(), RT0, a() );
}
if ( b() != RT0 )
{
return Vector_3( RT0, -c(), b(), b() );
}
CGAL_kernel_assertion ( c() != RT(0) );
return Vector_3( c(), RT0, -a(), c() );
}
template < class R >
inline
typename PlaneH3<R>::Vector_3
PlaneH3<R>::base2() const
{
Vector_3 a = orthogonal_vector();
Vector_3 b = base1();
return Vector_3(a.hy()*b.hz() - a.hz()*b.hy(),
a.hz()*b.hx() - a.hx()*b.hz(),
a.hx()*b.hy() - a.hy()*b.hx(),
a.hw()*b.hw() );
}
// Actually, the following should work, but bcc doesn't like it:
// { return cross_product( orthogonal_vector(), base1() ); }
template < class R >
inline
typename PlaneH3<R>::Point_3
PlaneH3<R>::point1() const
{ return point() + base1(); }
template < class R >
inline
typename PlaneH3<R>::Point_3
PlaneH3<R>::point2() const
{ return point() + base2(); }
template < class R >
inline
typename PlaneH3<R>::Direction_3
PlaneH3<R>::orthogonal_direction() const
{ return Direction_3(a(), b(), c() ); }
template < class R >
inline
typename PlaneH3<R>::Vector_3
PlaneH3<R>::orthogonal_vector() const
{ return Vector_3(a(), b(), c() ); }
template < class R >
typename PlaneH3<R>::Plane_3
PlaneH3<R>::transform(const typename PlaneH3<R>::Aff_transformation_3& t) const
{
return t.transform(*this);
}
#ifndef CGAL_NO_OSTREAM_INSERT_PLANE3
template < class R >
std::ostream &operator<<(std::ostream &os, const PlaneH3<R> &p)
{
switch(os.iword(IO::mode)) {
case IO::ASCII :
return os << p.a() << ' ' << p.b() << ' ' << p.c() << ' ' << p.d();
case IO::BINARY :
write(os, p.a());
write(os, p.b());
write(os, p.c());
write(os, p.d());
return os;
default:
os << "PlaneC3(" << p.a() << ", " << p.b() << ", ";
os << p.c() << ", " << p.d() <<")";
return os;
}
}
#endif // CGAL_NO_OSTREAM_INSERT_PLANE3
#ifndef CGAL_NO_ISTREAM_EXTRACT_PLANE3
template < class R >
std::istream &operator>>(std::istream &is, PlaneH3<R> &p)
{
typename R::RT a, b, c, d;
switch(is.iword(IO::mode)) {
case IO::ASCII :
is >> a >> b >> c >> d;
break;
case IO::BINARY :
read(is, a);
read(is, b);
read(is, c);
read(is, d);
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
p = PlaneH3<R>(a, b, c, d);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_PLANE3
template < class R >
bool
PlaneH3<R>::is_degenerate() const
{
const RT RT0(0);
return ( (a() == RT0 ) && (b() == RT0 ) && (c() == RT0 ) );
}
template < class R >
bool
PlaneH3<R>::has_on_positive_side( const typename PlaneH3<R>::Point_3& p) const
{
return (a()*p.hx() + b()*p.hy() + c()*p.hz() + d()*p.hw() > RT(0) );
}
template < class R >
bool
PlaneH3<R>::has_on_negative_side( const typename PlaneH3<R>::Point_3& p) const
{
return (a()*p.hx() + b()*p.hy() + c()*p.hz() + d()*p.hw() < RT(0) );
}
template < class R >
bool
PlaneH3<R>::has_on( const typename PlaneH3<R>::Point_3& p) const
{
return (a()*p.hx() + b()*p.hy() + c()*p.hz() + d()*p.hw() == RT(0) );
}
template < class R >
bool
PlaneH3<R>::has_on( const typename PlaneH3<R>::Line_3& l) const
{
Point_3 p = l.point();
Vector_3 ld = l.direction().to_vector();
Vector_3 ov = orthogonal_vector();
return ( ( a()*p.hx() + b()*p.hy() + c()*p.hz() + d()*p.hw() == RT(0) )
&&( ld.hx()*ov.hx() + ld.hy()*ov.hy() + ld.hz()*ov.hz() == RT(0) ) );
}
template < class R >
Oriented_side
PlaneH3<R>::oriented_side( const typename PlaneH3<R>::Point_3& p) const
{
RT value = a()*p.hx() + b()*p.hy() + c()*p.hz() + d()*p.hw() ;
if (value > RT(0) )
{
return ON_POSITIVE_SIDE;
}
else
{
return
(value < RT(0) ) ? ON_NEGATIVE_SIDE : ON_ORIENTED_BOUNDARY;
}
}
template < class R >
bool
PlaneH3<R>::operator==(const PlaneH3<R>& l) const
{
if ( (a() * l.d() != l.a() * d() )
||(b() * l.d() != l.b() * d() )
||(c() * l.d() != l.c() * d() ) )
{
return false;
}
int sd = static_cast<int>(CGAL_NTS sign(d()));
int sld = static_cast<int>(CGAL_NTS sign(l.d()));
if ( sd == sld )
{
if (sd == 0)
{
return ( (a()*l.b() == b()*l.a() )
&&(a()*l.c() == c()*l.a() )
&&(b()*l.c() == c()*l.b() )
&&(CGAL_NTS sign(a() )== CGAL_NTS sign( l.a() ))
&&(CGAL_NTS sign(b() )== CGAL_NTS sign( l.b() ))
&&(CGAL_NTS sign(c() )== CGAL_NTS sign( l.c() )) );
}
else
{
return true;
}
}
else
{
return false;
}
}
template < class R >
typename PlaneH3<R>::Aff_transformation_3
PlaneH3<R>::transform_to_2d() const
{
const RT RT0(0);
const RT RT1(1);
Vector_3 nov = orthogonal_vector();
Vector_3 e1v = point1()-point() ;
Vector_3 e2v = point2()-point() ;
RT orthohx = nov.hx();
RT orthohy = nov.hy();
RT orthohz = nov.hz();
RT e1phx = e1v.hx();
RT e1phy = e1v.hy();
RT e1phz = e1v.hz();
RT e2phx = e2v.hx();
RT e2phy = e2v.hy();
RT e2phz = e2v.hz();
RT t11 = -( orthohy*e2phz - orthohz*e2phy );
RT t12 = ( orthohx*e2phz - orthohz*e2phx );
RT t13 = -( orthohx*e2phy - orthohy*e2phx );
RT t21 = ( orthohy*e1phz - orthohz*e1phy );
RT t22 = -( orthohx*e1phz - orthohz*e1phx );
RT t23 = ( orthohx*e1phy - orthohy*e1phx );
RT t31 = ( e1phy*e2phz - e1phz*e2phy );
RT t32 = -( e1phx*e2phz - e1phz*e2phx );
RT t33 = ( e1phx*e2phy - e1phy*e2phx );
RT scale = det3x3_by_formula( orthohx, orthohy, orthohz,
e1phx, e1phy, e1phz,
e2phx, e2phy, e2phz );
Aff_transformation_3
point_to_origin(TRANSLATION, - ( point() - ORIGIN ) );
Aff_transformation_3
rotate_and_more( t11, t12, t13, RT0,
t21, t22, t23, RT0,
t31, t32, t33, RT0,
scale);
Point_3 ortho( orthohx, orthohy, orthohz );
Point_3 e1p( e1phx, e1phy, e1phz );
Point_3 e2p( e2phx, e2phy, e2phz );
CGAL_kernel_assertion(( ortho.transform(rotate_and_more)
== Point_3( RT(0), RT(0), RT(1)) ));
CGAL_kernel_assertion(( e1p.transform(rotate_and_more)
== Point_3( RT(1), RT(0), RT(0)) ));
CGAL_kernel_assertion(( e2p.transform(rotate_and_more)
== Point_3( RT(0), RT(1), RT(0)) ));
return rotate_and_more * point_to_origin;
}
template < class R >
CGAL_KERNEL_INLINE
typename PlaneH3<R>::Point_2
PlaneH3<R>::to_2d(const typename PlaneH3<R>::Point_3& p) const
{
Point_3 tp = p.transform( transform_to_2d() );
return Point_2( tp.hx(), tp.hy(), tp.hw());
}
template < class R >
CGAL_KERNEL_INLINE
typename PlaneH3<R>::Point_3
PlaneH3<R>::to_3d(const typename PlaneH3<R>::Point_2& p) const
{
Point_3 hp( p.hx(), p.hy(), RT(0.0), p.hw());
return hp.transform( transform_to_2d().inverse() );
}
CGAL_END_NAMESPACE
#endif // CGAL_PLANEH3_H
@@ -0,0 +1,171 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_HOMOGENEOUS_POINT_2_H
#define CGAL_HOMOGENEOUS_POINT_2_H
#include <CGAL/Origin.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Threetuple.h>
#include <CGAL/Kernel/Cartesian_coordinate_iterator_2.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class PointH2
{
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Vector_2 Vector_2;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Direction_2 Direction_2;
typedef typename R_::Aff_transformation_2 Aff_transformation_2;
typedef Threetuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef FT Cartesian_coordinate_type;
typedef const RT& Homogeneous_coordinate_type;
typedef Cartesian_coordinate_iterator_2<R_> Cartesian_const_iterator;
typedef R_ R;
PointH2() {}
PointH2(const Origin &)
: base (RT(0), RT(0), RT(1)) {}
PointH2(const RT& hx, const RT& hy )
: base (hx, hy, RT(1)) {}
PointH2(const RT& hx, const RT& hy, const RT& hw)
{
if ( hw >= RT(0) )
base = Rep( hx, hy, hw);
else
base = Rep(-hx,-hy,-hw);
}
bool operator==( const PointH2<R>& p) const;
bool operator!=( const PointH2<R>& p) const;
const RT & hx() const { return get(base).e0; };
const RT & hy() const { return get(base).e1; };
const RT & hw() const { return get(base).e2; };
FT x() const { return FT(hx()) / FT(hw()); };
FT y() const { return FT(hy()) / FT(hw()); };
FT cartesian(int i) const;
FT operator[](int i) const;
const RT & homogeneous(int i) const;
Cartesian_const_iterator cartesian_begin() const
{
return Cartesian_const_iterator(static_cast<const Point_2*>(this), 0);
}
Cartesian_const_iterator cartesian_end() const
{
return Cartesian_const_iterator(static_cast<const Point_2*>(this), 2);
}
int dimension() const;
Point_2 transform( const Aff_transformation_2 & t) const;
Direction_2 direction() const;
};
template < class R >
CGAL_KERNEL_INLINE
bool
PointH2<R>::operator==( const PointH2<R>& p) const
{ // FIXME : Predicate
return ( (hx() * p.hw() == p.hx() * hw() )
&&(hy() * p.hw() == p.hy() * hw() ) );
}
template < class R >
inline
bool
PointH2<R>::operator!=( const PointH2<R>& p) const
{ return !(*this == p); }
template < class R >
CGAL_KERNEL_INLINE
typename PointH2<R>::FT
PointH2<R>::cartesian(int i) const
{
CGAL_kernel_precondition( (i==0 || i==1) );
if (i==0)
return x();
return y();
}
template < class R >
CGAL_KERNEL_INLINE
const typename PointH2<R>::RT &
PointH2<R>::homogeneous(int i) const
{
CGAL_kernel_precondition( (i>=0) && (i<=2) );
if (i==0)
return hx();
if (i==1)
return hy();
return hw();
}
template < class R >
inline
typename PointH2<R>::FT
PointH2<R>::operator[](int i) const
{ return cartesian(i); }
template < class R >
inline
int
PointH2<R>::dimension() const
{ return 2; }
template < class R >
CGAL_KERNEL_INLINE
typename PointH2<R>::Direction_2
PointH2<R>::direction() const
{ return typename PointH2<R>::Direction_2(*this); }
template < class R >
inline
typename R::Point_2
PointH2<R>::transform(const typename PointH2<R>::Aff_transformation_2& t) const
{ return t.transform(static_cast<const typename R::Point_2 &>(*this)); }
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_POINT_2_H
@@ -0,0 +1,280 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_HOMOGENEOUS_POINT_3_H
#define CGAL_HOMOGENEOUS_POINT_3_H
#include <CGAL/Origin.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/Fourtuple.h>
#include <CGAL/Kernel/Cartesian_coordinate_iterator_3.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class PointH3
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
typedef Fourtuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef Cartesian_coordinate_iterator_3<R_> Cartesian_const_iterator;
typedef R_ R;
PointH3() {}
PointH3(const Origin &)
: base (RT(0), RT(0), RT(0), RT(1)) { }
PointH3(const RT& x, const RT& y, const RT& z)
: base(x, y, z, RT(1)) {}
PointH3(const RT& x, const RT& y, const RT& z, const RT& w)
{
if ( w < RT(0) )
base = Rep(-x,-y,-z,-w);
else
base = Rep(x,y,z,w);
}
FT x() const;
FT y() const;
FT z() const;
const RT & hx() const;
const RT & hy() const;
const RT & hz() const;
const RT & hw() const;
const RT & homogeneous(int i) const;
FT cartesian(int i) const;
FT operator[](int i) const;
Cartesian_const_iterator cartesian_begin() const
{
return Cartesian_const_iterator(static_cast<const Point_3*>(this), 0);
}
Cartesian_const_iterator cartesian_end() const
{
return Cartesian_const_iterator(static_cast<const Point_3*>(this), 3);
}
int dimension() const;
Direction_3 direction() const;
Point_3 transform( const Aff_transformation_3 & t) const;
Bbox_3 bbox() const;
bool operator==( const PointH3<R>& p) const;
bool operator!=( const PointH3<R>& p) const;
};
template < class R >
inline
const typename PointH3<R>::RT &
PointH3<R>::hx() const
{ return get(base).e0 ; }
template < class R >
inline
const typename PointH3<R>::RT &
PointH3<R>::hy() const
{ return get(base).e1 ; }
template < class R >
inline
const typename PointH3<R>::RT &
PointH3<R>::hz() const
{ return get(base).e2 ; }
template < class R >
inline
const typename PointH3<R>::RT &
PointH3<R>::hw() const
{ return get(base).e3 ; }
template < class R >
CGAL_KERNEL_INLINE
typename PointH3<R>::FT
PointH3<R>::x() const
{ return ( FT(hx()) / FT(hw())); }
template < class R >
CGAL_KERNEL_INLINE
typename PointH3<R>::FT
PointH3<R>::y() const
{ return ( FT(hy()) / FT(hw())); }
template < class R >
CGAL_KERNEL_INLINE
typename PointH3<R>::FT
PointH3<R>::z() const
{ return ( FT(hz()) / FT(hw())); }
template < class R >
inline
int
PointH3<R>::dimension() const
{ return 3; }
template < class R >
CGAL_KERNEL_INLINE
typename PointH3<R>::FT
PointH3<R>::cartesian(int i) const
{
CGAL_kernel_precondition(i == 0 || i == 1 || i == 2);
switch (i)
{
case 0: return x();
case 1: return y();
}
return z();
}
template < class R >
CGAL_KERNEL_INLINE
const typename PointH3<R>::RT &
PointH3<R>::homogeneous(int i) const
{
CGAL_kernel_precondition(i == 0 || i == 1 || i == 2 || i == 3);
switch (i)
{
case 0: return hx();
case 1: return hy();
case 2: return hz();
}
return hw();
}
template < class R >
inline
typename PointH3<R>::FT
PointH3<R>::operator[](int i) const
{ return cartesian(i); }
template < class R >
inline
typename PointH3<R>::Direction_3
PointH3<R>::direction() const
{ return Direction_3(*this); }
template < class R >
CGAL_KERNEL_INLINE
bool
PointH3<R>::operator==( const PointH3<R> & p) const
{
return ( (hx() * p.hw() == p.hx() * hw() )
&&(hy() * p.hw() == p.hy() * hw() )
&&(hz() * p.hw() == p.hz() * hw() ) );
}
template < class R >
inline
bool
PointH3<R>::operator!=( const PointH3<R> & p) const
{ return !(*this == p); }
#ifndef CGAL_NO_OSTREAM_INSERT_POINTH3
template < class R >
std::ostream &operator<<(std::ostream &os, const PointH3<R> &p)
{
switch(os.iword(IO::mode)) {
case IO::ASCII :
return os << p.hx() << ' ' << p.hy() << ' ' << p.hz() << ' ' << p.hw();
case IO::BINARY :
write(os, p.hx());
write(os, p.hy());
write(os, p.hz());
write(os, p.hw());
return os;
default:
return os << "PointH3(" << p.hx() << ", "
<< p.hy() << ", "
<< p.hz() << ", "
<< p.hw() << ')';
}
}
#endif // CGAL_NO_OSTREAM_INSERT_POINTH3
#ifndef CGAL_NO_ISTREAM_EXTRACT_POINTH3
template < class R >
std::istream &operator>>(std::istream &is, PointH3<R> &p)
{
typename R::RT hx, hy, hz, hw;
switch(is.iword(IO::mode)) {
case IO::ASCII :
is >> hx >> hy >> hz >> hw;
break;
case IO::BINARY :
read(is, hx);
read(is, hy);
read(is, hz);
read(is, hw);
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
p = PointH3<R>(hx, hy, hz, hw);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_POINTH3
template < class R >
inline
typename R::Point_3
PointH3<R>::transform(const typename PointH3<R>::Aff_transformation_3& t) const
{ return t.transform(static_cast<const Point_3&>(*this)); }
template < class R >
CGAL_KERNEL_LARGE_INLINE
Bbox_3
PointH3<R>::bbox() const
{
Interval_nt<> ihx = CGAL_NTS to_interval(hx());
Interval_nt<> ihy = CGAL_NTS to_interval(hy());
Interval_nt<> ihz = CGAL_NTS to_interval(hz());
Interval_nt<> ihw = CGAL_NTS to_interval(hw());
Interval_nt<> ix = ihx/ihw;
Interval_nt<> iy = ihy/ihw;
Interval_nt<> iz = ihz/ihw;
return Bbox_3(ix.inf(), iy.inf(), iz.inf(), ix.sup(), iy.sup(), iz.sup());
}
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_POINT_3_H
@@ -0,0 +1,240 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_RAYH2_H
#define CGAL_RAYH2_H
#include <CGAL/Twotuple.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class RayH2
{
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Direction_2 Direction_2;
typedef typename R_::Line_2 Line_2;
typedef typename R_::Vector_2 Vector_2;
typedef typename R_::Aff_transformation_2 Aff_transformation_2;
typedef Twotuple<Point_2> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
RayH2() {}
RayH2( const Point_2& sp, const Point_2& secondp)
: base(sp, secondp) {}
RayH2( const Point_2& sp, const Direction_2& d)
: base(sp, sp + d.to_vector()) {}
RayH2( const Point_2& sp, const Vector_2& v)
: base(sp, sp + v) {}
RayH2( const Point_2& sp, const Line_2& l)
: base(sp, sp + l.to_vector()) {}
bool operator==(const RayH2<R>& r) const;
bool operator!=(const RayH2<R>& r) const;
const Point_2 & start() const;
const Point_2 & source() const;
const Point_2 & second_point() const;
Point_2 point(int i) const;
Direction_2 direction() const;
Vector_2 to_vector() const;
Line_2 supporting_line() const;
RayH2<R> opposite() const;
bool is_horizontal() const;
bool is_vertical() const;
bool has_on(const Point_2& p) const;
bool collinear_has_on(const Point_2& p) const;
bool is_degenerate() const;
RayH2<R> transform( const Aff_transformation_2 & t) const;
};
template < class R >
inline
const typename RayH2<R>::Point_2 &
RayH2<R>::source() const
{ return get(base).e0; }
template < class R >
inline
const typename RayH2<R>::Point_2 &
RayH2<R>::start() const
{ return source(); }
template < class R >
CGAL_KERNEL_INLINE
typename RayH2<R>::Vector_2
RayH2<R>::to_vector() const
{
CGAL_kernel_precondition( !is_degenerate() );
return second_point() - start();
}
template < class R >
CGAL_KERNEL_INLINE
typename RayH2<R>::Direction_2
RayH2<R>::direction() const
{
CGAL_kernel_precondition( !is_degenerate() );
return Direction_2( second_point() - start() );
}
template < class R >
inline
const typename RayH2<R>::Point_2 &
RayH2<R>::second_point() const
{
CGAL_kernel_precondition( !is_degenerate() );
return get(base).e1;
}
template < class R >
CGAL_KERNEL_INLINE
typename RayH2<R>::Point_2
RayH2<R>::point(int i) const
{
CGAL_kernel_precondition( !is_degenerate() );
CGAL_kernel_precondition( i>= 0 );
Vector_2 v = direction().to_vector();
return start() + RT(i) * v;
}
template < class R >
inline
typename RayH2<R>::Line_2
RayH2<R>::supporting_line() const
{
CGAL_kernel_precondition( !is_degenerate() );
return Line_2(*this);
}
template < class R >
inline
RayH2<R>
RayH2<R>::opposite() const
{ return RayH2<R>( start(), - direction() ); }
template < class R >
CGAL_KERNEL_INLINE
RayH2<R>
RayH2<R>::
transform(const typename RayH2<R>::Aff_transformation_2 & t) const
{
return RayH2<R>(t.transform(start()), t.transform(second_point()) );
}
#ifndef CGAL_NO_OSTREAM_INSERT_RAYH2
template < class R >
std::ostream &
operator<<(std::ostream &os, const RayH2<R> &r)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << r.source() << ' ' << r.second_point();
case IO::BINARY :
return os << r.source() << r.second_point();
default:
return os << "RayC2(" << r.source() << ", " << r.second_point() << ")";
}
}
#endif // CGAL_NO_OSTREAM_INSERT_RAYH2
#ifndef CGAL_NO_ISTREAM_EXTRACT_RAYH2
template < class R >
std::istream &
operator>>(std::istream &is, RayH2<R> &r)
{
typename R::Point_2 p, q;
is >> p >> q;
r = RayH2<R>(p, q);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_RAYH2
template < class R >
CGAL_KERNEL_INLINE
bool
RayH2<R>::is_horizontal() const
{
return start().hy()*second_point().hw() == second_point().hy()*start().hw();
}
template < class R >
CGAL_KERNEL_INLINE
bool
RayH2<R>::is_vertical() const
{
return start().hx()*second_point().hw() == second_point().hx()*start().hw();
}
template < class R >
CGAL_KERNEL_INLINE
bool
RayH2<R>::has_on(const typename RayH2<R>::Point_2& p) const
{
return p == start() || Direction_2(p - start()) == direction();
}
template < class R >
CGAL_KERNEL_INLINE
bool
RayH2<R>::is_degenerate() const
{ return start() == get(base).e1; }
template < class R >
inline
bool
RayH2<R>::collinear_has_on(const typename RayH2<R>::Point_2& p) const
{ return has_on(p); }
template < class R >
CGAL_KERNEL_INLINE
bool
RayH2<R>::operator==(const RayH2<R>& r) const
{ return ( (start() == r.start() )&&( direction() == r.direction() ) ); }
template < class R >
inline
bool
RayH2<R>::operator!=( const RayH2<R>& r) const
{ return !(*this == r); }
CGAL_END_NAMESPACE
#endif // CGAL_RAYH2_H
@@ -0,0 +1,209 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_RAYH3_H
#define CGAL_RAYH3_H
#include <utility>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class RayH3
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Line_3 Line_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
typedef std::pair<Point_3, Vector_3> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
RayH3() {}
RayH3( const Point_3& sp, const Point_3& secondp)
: base(sp, secondp-sp) {}
RayH3( const Point_3& sp, const Vector_3& v)
: base(sp, v) {}
RayH3( const Point_3& sp, const Direction_3& d)
: base(sp, d.to_vector()) {}
RayH3( const Point_3& sp, const Line_3& l)
: base(sp, l.to_vector()) {}
const Point_3 & start() const;
const Point_3 & source() const;
Point_3 second_point() const;
Point_3 point(int i) const;
Direction_3 direction() const;
const Vector_3 & to_vector() const;
Line_3 supporting_line() const;
RayH3<R> opposite() const;
RayH3<R> transform( const Aff_transformation_3 & t) const;
bool has_on(const Point_3& p) const;
bool collinear_has_on(const Point_3 &p) const;
bool is_degenerate() const;
bool operator==(const RayH3<R>& r) const;
bool operator!=(const RayH3<R>& r) const;
};
template < class R >
inline
const typename RayH3<R>::Point_3 &
RayH3<R>::source() const
{ return get(base).first; }
template < class R >
inline
const typename RayH3<R>::Point_3 &
RayH3<R>::start() const
{ return get(base).first; }
template < class R >
inline
const typename RayH3<R>::Vector_3 &
RayH3<R>::to_vector() const
{
return get(base).second;
}
template < class R >
inline
typename RayH3<R>::Direction_3
RayH3<R>::direction() const
{
return to_vector().direction();
}
template < class R >
CGAL_KERNEL_INLINE
typename RayH3<R>::Point_3
RayH3<R>::second_point() const
{ return start() + to_vector(); }
template < class R >
CGAL_KERNEL_INLINE
typename RayH3<R>::Point_3
RayH3<R>::point(int i) const
{
CGAL_kernel_precondition( i >= 0 );
return start() + RT(i)*to_vector();
}
template < class R >
CGAL_KERNEL_INLINE
typename RayH3<R>::Line_3
RayH3<R>::supporting_line() const
{
CGAL_kernel_precondition( !is_degenerate() );
return Line_3(start(), second_point() );
}
template < class R >
CGAL_KERNEL_INLINE
RayH3<R>
RayH3<R>::opposite() const
{ return RayH3<R>( start(), - direction() ); }
template < class R >
CGAL_KERNEL_INLINE
RayH3<R>
RayH3<R>::transform( const Aff_transformation_3 & t) const
{ return RayH3<R>(t.transform(start()), t.transform(direction()) ); }
#ifndef CGAL_NO_OSTREAM_INSERT_RAYH3
template < class R >
std::ostream &operator<<(std::ostream &os, const RayH3<R> &r)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << r.start() << ' ' << r.direction();
case IO::BINARY :
return os<< r.start() << r.direction();
default:
return os << "RayH3(" << r.start() << ", " << r.direction() << ")";
}
}
#endif // CGAL_NO_OSTREAM_INSERT_RAYH3
#ifndef CGAL_NO_ISTREAM_EXTRACT_RAYH3
template < class R >
std::istream &operator>>(std::istream &is, RayH3<R> &r)
{
typename R::Point_3 p;
typename R::Direction_3 d;
is >> p >> d;
r = RayH3<R>(p, d);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_RAYH3
template < class R >
CGAL_KERNEL_INLINE
bool
RayH3<R>::has_on(const typename RayH3<R>::Point_3 &p) const
{
return ( ( p == start() )
||( Direction_3(p - start()) == direction() ) );
}
template < class R >
inline /* XXX */
bool
RayH3<R>::collinear_has_on(const typename RayH3<R>::Point_3 &p) const
{ return has_on(p); }
template < class R >
inline
bool
RayH3<R>::is_degenerate() const
{ return to_vector() == NULL_VECTOR; }
template < class R >
CGAL_KERNEL_INLINE
bool
RayH3<R>::operator==(const RayH3<R>& r) const
{ return ( (start() == r.start() )&&( direction() == r.direction() ) ); }
template < class R >
CGAL_KERNEL_INLINE
bool
RayH3<R>::operator!=( const RayH3<R>& r) const
{ return !operator==(r); }
CGAL_END_NAMESPACE
#endif // CGAL_RAYH3_H
@@ -0,0 +1,324 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_SPHEREH3_H
#define CGAL_SPHEREH3_H
#include <CGAL/utility.h>
#include <CGAL/Interval_arithmetic.h>
#include <CGAL/Homogeneous/predicates_on_pointsH3.h>
CGAL_BEGIN_NAMESPACE
template <class R_>
class SphereH3
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
typedef Triple<Point_3, FT, Orientation> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
SphereH3() {}
SphereH3(const Point_3& p, const FT& sq_rad,
const Orientation& o = COUNTERCLOCKWISE);
SphereH3(const Point_3& p, const Point_3& q,
const Point_3& r, const Point_3& u);
SphereH3(const Point_3& p, const Point_3& q,
const Point_3& r,
const Orientation& o = COUNTERCLOCKWISE);
SphereH3(const Point_3& p, const Point_3& q,
const Orientation& o = COUNTERCLOCKWISE);
SphereH3(const Point_3& p,
const Orientation& o = COUNTERCLOCKWISE);
bool
operator==(const SphereH3<R>&) const;
bool
operator!=(const SphereH3<R>& s) const
{ return !(*this == s); }
const Point_3 & center() const;
const FT & squared_radius() const;
Orientation orientation() const;
SphereH3<R> orthogonal_transform(const Aff_transformation_3& t) const;
bool is_degenerate() const;
SphereH3<R> opposite() const;
Bbox_3 bbox() const;
Oriented_side oriented_side(const Point_3& p) const;
bool
has_on_boundary(const Point_3& p) const
{ return oriented_side(p)==ON_ORIENTED_BOUNDARY; }
bool
has_on_positive_side(const Point_3& p) const
{ return oriented_side(p)==ON_POSITIVE_SIDE; }
bool
has_on_negative_side(const Point_3& p) const
{ return oriented_side(p)==ON_NEGATIVE_SIDE; }
Bounded_side
bounded_side(const Point_3& p) const;
bool
has_on_bounded_side(const Point_3& p) const
{ return bounded_side(p)==ON_BOUNDED_SIDE; }
bool
has_on_unbounded_side(const Point_3& p) const
{ return bounded_side(p)==ON_UNBOUNDED_SIDE; }
};
template < class R >
CGAL_KERNEL_INLINE
SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& center,
const FT& squared_radius,
const Orientation& o)
{
CGAL_kernel_precondition( !( squared_radius < FT(0))
&&( o != COLLINEAR) );
base = Rep(center, squared_radius, o);
}
template <class R>
CGAL_KERNEL_INLINE
SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& center,
const Orientation& o)
{
CGAL_kernel_precondition( ( o != COLLINEAR) );
base = Rep(center, FT(0), o);
}
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& p,
const typename SphereH3<R>::Point_3& q,
const Orientation& o)
{
CGAL_kernel_precondition( o != COLLINEAR);
Point_3 center = midpoint(p,q);
FT squared_radius = squared_distance(p,center);
base = Rep(center, squared_radius, o);
}
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& p,
const typename SphereH3<R>::Point_3& q,
const typename SphereH3<R>::Point_3& r,
const Orientation& o)
{
CGAL_kernel_precondition( o != COLLINEAR);
Point_3 center = circumcenter(p,q,r);
FT squared_radius = squared_distance(p,center);
base = Rep(center, squared_radius, o);
}
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
SphereH3<R>::SphereH3(const typename SphereH3<R>::Point_3& p,
const typename SphereH3<R>::Point_3& q,
const typename SphereH3<R>::Point_3& r,
const typename SphereH3<R>::Point_3& s)
{
Orientation o = CGAL::orientation(p,q,r,s);
CGAL_kernel_precondition( o != COLLINEAR);
Point_3 center = circumcenter(p,q,r,s);
FT squared_radius = squared_distance(p,center);
base = Rep(center, squared_radius, o);
}
template <class R>
CGAL_KERNEL_INLINE
bool
SphereH3<R>::operator==(const SphereH3<R>& s) const
{
return ( orientation() == s.orientation())
&& ( center() == s.center())
&& ( squared_radius() == s.squared_radius());
}
template <class R>
inline
const typename SphereH3<R>::Point_3 &
SphereH3<R>::center() const
{ return get(base).first; }
template <class R>
inline
const typename SphereH3<R>::FT &
SphereH3<R>::squared_radius() const
{ return get(base).second; }
template <class R>
inline
Orientation
SphereH3<R>::orientation() const
{ return get(base).third; }
template <class R>
inline
bool
SphereH3<R>::is_degenerate() const
{ return squared_radius() <= FT(0) ; }
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
Oriented_side
SphereH3<R>::oriented_side(const typename SphereH3<R>::Point_3& p) const
{ return Oriented_side(bounded_side(p) * orientation()); }
template <class R>
CGAL_KERNEL_INLINE
Bounded_side
SphereH3<R>::bounded_side(const typename SphereH3<R>::Point_3& p) const
{
return Bounded_side(CGAL_NTS compare(squared_radius(),
squared_distance(center(),p)));
}
template <class R>
inline
SphereH3<R>
SphereH3<R>::opposite() const
{
return SphereH3<R>(center(), squared_radius(),
CGAL::opposite(orientation()) );
}
template <class R>
CGAL_KERNEL_INLINE
Bbox_3
SphereH3<R>::bbox() const
{
Bbox_3 b = center().bbox();
Interval_nt<> x (b.xmin(), b.xmax());
Interval_nt<> y (b.ymin(), b.ymax());
Interval_nt<> z (b.zmin(), b.zmax());
Interval_nt<> sqr = CGAL_NTS to_interval(squared_radius());
Interval_nt<> r = CGAL::sqrt(sqr);
Interval_nt<> minx = x-r;
Interval_nt<> maxx = x+r;
Interval_nt<> miny = y-r;
Interval_nt<> maxy = y+r;
Interval_nt<> minz = z-r;
Interval_nt<> maxz = z+r;
return Bbox_3(minx.inf(), miny.inf(), minz.inf(),
maxx.sup(), maxy.sup(), maxz.sup());
}
#ifndef CGAL_NO_OSTREAM_INSERT_SPHEREH3
template < class R >
CGAL_KERNEL_INLINE
std::ostream &
operator<<(std::ostream &os, const SphereH3<R> &c)
{
switch(os.iword(IO::mode)) {
case IO::ASCII :
os << c.center() << ' ' << c.squared_radius() << ' '
<< static_cast<int>(c.orientation());
break;
case IO::BINARY :
os << c.center();
write(os, c.squared_radius());
write(os, static_cast<int>(c.orientation()));
break;
default:
os << "SphereH3(" << c.center() << ", " << c.squared_radius();
switch (c.orientation()) {
case CLOCKWISE:
os << ", clockwise)";
break;
case COUNTERCLOCKWISE:
os << ", counterclockwise)";
break;
default:
os << ", collinear)";
break;
}
break;
}
return os;
}
#endif // CGAL_NO_OSTREAM_INSERT_SPHEREH3
#ifndef CGAL_NO_ISTREAM_EXTRACT_SPHEREH3
template < class R >
CGAL_KERNEL_INLINE
std::istream &
operator>>(std::istream &is, SphereH3<R> &c)
{
typename R::Point_3 center;
typename R::FT squared_radius;
int o;
switch(is.iword(IO::mode)) {
case IO::ASCII :
is >> center >> squared_radius >> o;
break;
case IO::BINARY :
is >> center;
read(is, squared_radius);
is >> o;
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
if (is)
c = SphereH3<R>(center, squared_radius,
static_cast<Orientation>(o));
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_SPHEREH3
CGAL_END_NAMESPACE
#endif // CGAL_SPHEREH3_H
@@ -0,0 +1,287 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_HOMOGENEOUS_VECTOR_2_h
#define CGAL_HOMOGENEOUS_VECTOR_2_h
#include <CGAL/Origin.h>
#include <CGAL/Threetuple.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class VectorH2
{
typedef VectorH2<R_> Self;
typedef typename R_::FT FT;
typedef typename R_::RT RT;
typedef typename R_::Point_2 Point_2;
typedef typename R_::Segment_2 Segment_2;
typedef typename R_::Ray_2 Ray_2;
typedef typename R_::Line_2 Line_2;
typedef typename R_::Direction_2 Direction_2;
typedef typename R_::Vector_2 Vector_2;
typedef typename R_::Aff_transformation_2 Aff_transformation_2;
typedef Threetuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef const FT Cartesian_coordinate_type;
typedef const RT& Homogeneous_coordinate_type;
typedef R_ R;
VectorH2() {}
VectorH2(const RT& x, const RT& y)
: base (x, y, RT(1)) {}
VectorH2(const RT& x, const RT& y, const RT& w )
{
if ( w >= RT(0) )
base = Rep( x, y, w);
else
base = Rep(-x, -y, -w);
}
const Self&
rep() const
{
return static_cast<const Self& >(*this);
}
bool operator==( const VectorH2<R>& v) const;
bool operator!=( const VectorH2<R>& v) const;
bool operator==( const Null_vector&) const;
bool operator!=( const Null_vector& v) const;
const RT & hx() const { return get(base).e0; };
const RT & hy() const { return get(base).e1; };
const RT & hw() const { return get(base).e2; };
FT x() const { return FT(hx()) / FT(hw()); };
FT y() const { return FT(hy()) / FT(hw()); };
FT cartesian(int i) const;
const RT & homogeneous(int i) const;
FT operator[](int i) const;
int dimension() const;
Direction_2 direction() const;
Vector_2 transform(const Aff_transformation_2& t ) const;
Vector_2 perpendicular(const Orientation& o ) const;
// Vector_2 operator+(const VectorH2 &v) const;
Vector_2 operator-(const VectorH2 &v) const;
Vector_2 operator-() const;
Vector_2 opposite() const;
FT squared_length() const;
// Vector_2 operator/(const RT &f) const;
//Vector_2 operator/(const FT &f) const;
// undocumented:
VectorH2(const Direction_2 & dir)
: base ( dir) {}
VectorH2(const Point_2 & p)
: base ( p) {}
};
template < class R >
inline
bool
VectorH2<R>::operator==( const Null_vector&) const
{ return (hx() == RT(0)) && (hy() == RT(0)); }
template < class R >
inline
bool
VectorH2<R>::operator!=( const Null_vector& v) const
{ return !(*this == v); }
template < class R >
CGAL_KERNEL_INLINE
bool
VectorH2<R>::operator==( const VectorH2<R>& v) const
{
return ( (hx() * v.hw() == v.hx() * hw() )
&&(hy() * v.hw() == v.hy() * hw() ) );
}
template < class R >
inline
bool
VectorH2<R>::operator!=( const VectorH2<R>& v) const
{ return !(*this == v); } /* XXX */
template < class R >
CGAL_KERNEL_INLINE
typename VectorH2<R>::FT
VectorH2<R>::cartesian(int i) const
{
CGAL_kernel_precondition( (i==0 || i==1) );
if (i==0)
return x();
return y();
}
template < class R >
CGAL_KERNEL_INLINE
const typename VectorH2<R>::RT &
VectorH2<R>::homogeneous(int i) const
{
CGAL_kernel_precondition( (i>=0) && (i<=2) );
if (i==0)
return hx();
if (i==1)
return hy();
return hw();
}
template < class R >
inline
typename VectorH2<R>::FT
VectorH2<R>::operator[](int i) const
{ return cartesian(i); }
template < class R >
inline
int
VectorH2<R>::dimension() const
{ return 2; }
template < class R >
CGAL_KERNEL_INLINE
typename VectorH2<R>::Direction_2
VectorH2<R>::direction() const
{ return Direction_2(hx(), hy()); }
template < class R >
inline
typename VectorH2<R>::Vector_2
VectorH2<R>::operator-() const
{ return VectorH2<R>(- hx(), - hy(), hw() ); }
template < class R >
inline
typename VectorH2<R>::Vector_2
VectorH2<R>::opposite() const
{ return VectorH2<R>(- hx(), - hy(), hw() ); }
template <class R>
CGAL_KERNEL_INLINE
typename VectorH2<R>::Vector_2
VectorH2<R>::operator-(const VectorH2<R>& v) const
{
return VectorH2<R>( hx()*v.hw() - v.hx()*hw(),
hy()*v.hw() - v.hy()*hw(),
hw()*v.hw() );
}
template <class R>
CGAL_KERNEL_INLINE
typename VectorH2<R>::FT
VectorH2<R>::squared_length() const
{
typedef typename R::FT FT;
return
FT( CGAL_NTS square(hx()) + CGAL_NTS square(hy()) ) /
FT( CGAL_NTS square(hw()) );
}
template < class R >
CGAL_KERNEL_INLINE
typename R::Vector_2
VectorH2<R>::perpendicular(const Orientation& o) const
{
CGAL_kernel_precondition(o != COLLINEAR);
if (o == COUNTERCLOCKWISE)
return typename R::Vector_2(-hy(), hx(), hw());
else
return typename R::Vector_2(hy(), -hx(), hw());
}
template < class R >
inline
typename R::Vector_2
VectorH2<R>::
transform(const typename VectorH2<R>::Aff_transformation_2& t) const
{ return t.transform(*this); }
#ifndef CGAL_NO_OSTREAM_INSERT_VECTORH2
template < class R >
std::ostream &
operator<<(std::ostream &os, const VectorH2<R> &p)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << p.hx() << ' ' << p.hy() << ' ' << p.hw();
case IO::BINARY :
write(os, p.hx());
write(os, p.hy());
write(os, p.hw());
return os;
default:
return os << "VectorH2(" << p.hx() << ", "
<< p.hy() << ", "
<< p.hw() << ')';
}
}
#endif // CGAL_NO_OSTREAM_INSERT_VECTORH2
#ifndef CGAL_NO_ISTREAM_EXTRACT_VECTORH2
template < class R >
std::istream &
operator>>(std::istream &is, VectorH2<R> &p)
{
typename R::RT hx, hy, hw;
switch(is.iword(IO::mode))
{
case IO::ASCII :
is >> hx >> hy >> hw;
break;
case IO::BINARY :
read(is, hx);
read(is, hy);
read(is, hw);
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
p = VectorH2<R>(hx, hy, hw);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_VECTORH2
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_VECTOR_2_h
@@ -0,0 +1,284 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_HOMOGENEOUS_VECTOR_3_H
#define CGAL_HOMOGENEOUS_VECTOR_3_H
#include <CGAL/Origin.h>
#include <CGAL/Fourtuple.h>
CGAL_BEGIN_NAMESPACE
template < class R_ >
class VectorH3
{
typedef typename R_::RT RT;
typedef typename R_::FT FT;
typedef typename R_::Point_3 Point_3;
typedef typename R_::Vector_3 Vector_3;
typedef typename R_::Segment_3 Segment_3;
typedef typename R_::Ray_3 Ray_3;
typedef typename R_::Line_3 Line_3;
typedef typename R_::Direction_3 Direction_3;
typedef typename R_::Aff_transformation_3 Aff_transformation_3;
typedef Fourtuple<RT> Rep;
typedef typename R_::template Handle<Rep>::type Base;
Base base;
public:
typedef R_ R;
VectorH3() {}
VectorH3(const Point_3& a, const Point_3& b)
{ *this = R().construct_vector_3_object()(a, b); }
VectorH3(const Segment_3& s)
{ *this = R().construct_vector_3_object()(s); }
VectorH3(const Ray_3& r)
{ *this = R().construct_vector_3_object()(r); }
VectorH3(const Line_3& l)
{ *this = R().construct_vector_3_object()(l); }
VectorH3(const Null_vector&)
: base(RT(0), RT(0), RT(0), RT(1)) {}
VectorH3(const RT& x, const RT& y, const RT& z)
: base(x, y, z, RT(1)) {}
VectorH3(const RT& w, const RT& x, const RT& y, const RT& z);
const RT & hx() const { return get(base).e0 ; }
const RT & hy() const { return get(base).e1 ; }
const RT & hz() const { return get(base).e2 ; }
const RT & hw() const { return get(base).e3 ; }
FT x() const { return FT(hx())/FT(hw()) ; }
FT y() const { return FT(hy())/FT(hw()) ; }
FT z() const { return FT(hz())/FT(hw()) ; }
const RT & homogeneous(int i) const;
FT cartesian(int i) const;
FT operator[](int i) const;
int dimension() const { return 3; };
Direction_3 direction() const;
Vector_3 transform(const Aff_transformation_3& t ) const;
Vector_3 operator-() const;
bool operator==( const VectorH3<R>& v) const;
bool operator!=( const VectorH3<R>& v) const;
Vector_3 operator+( const VectorH3 &v) const;
Vector_3 operator-( const VectorH3 &v) const;
FT squared_length() const;
Vector_3 operator/( const RT &f) const;
Vector_3 operator/( const FT &f) const;
};
template < class R >
CGAL_KERNEL_INLINE
VectorH3<R>::VectorH3(const RT& x, const RT& y, const RT& z, const RT& w)
{
if ( w >= RT(0) )
base = Rep(x, y, z, w);
else
base = Rep(-x,-y,-z,-w);
}
template < class R >
CGAL_KERNEL_INLINE
typename VectorH3<R>::FT
VectorH3<R>::cartesian(int i) const
{
CGAL_kernel_precondition(i == 0 || i == 1 || i == 2);
switch (i)
{
case 0: return x();
case 1: return y();
}
return z();
}
template < class R >
CGAL_KERNEL_INLINE
const typename VectorH3<R>::RT &
VectorH3<R>::homogeneous(int i) const
{
CGAL_kernel_precondition(i == 0 || i == 1 || i == 2 || i == 3);
switch (i)
{
case 0: return hx();
case 1: return hy();
case 2: return hz();
}
return hw() ;
}
template < class R >
inline
typename VectorH3<R>::Direction_3
VectorH3<R>::direction() const
{ return Direction_3(hx(), hy(), hz()); }
template < class R >
CGAL_KERNEL_INLINE
bool
VectorH3<R>::operator==( const VectorH3<R>& v) const
{
return ( (hx() * v.hw() == v.hx() * hw() )
&&(hy() * v.hw() == v.hy() * hw() )
&&(hz() * v.hw() == v.hz() * hw() ) );
}
template < class R >
inline
bool
VectorH3<R>::operator!=( const VectorH3<R>& v) const
{ return !(*this == v); }
template < class R >
inline
typename VectorH3<R>::FT
VectorH3<R>::operator[](int i) const
{ return cartesian(i); }
template < class R >
CGAL_KERNEL_INLINE
typename VectorH3<R>::Vector_3
VectorH3<R>::operator-() const
{ return Vector_3( - hx(), - hy(), -hz(), hw() ); }
template <class R>
CGAL_KERNEL_INLINE
typename R::Vector_3
VectorH3<R>::operator+(const VectorH3<R>& v) const
{
return typename R::Vector_3(hx()*v.hw() + v.hx()*hw(),
hy()*v.hw() + v.hy()*hw(),
hz()*v.hw() + v.hz()*hw(),
hw()*v.hw() );
}
template <class R>
CGAL_KERNEL_INLINE
typename R::Vector_3
VectorH3<R>::operator-(const VectorH3<R>& v) const
{
return typename R::Vector_3(hx()*v.hw() - v.hx()*hw(),
hy()*v.hw() - v.hy()*hw(),
hz()*v.hw() - v.hz()*hw(),
hw()*v.hw() );
}
template <class R>
CGAL_KERNEL_INLINE
typename VectorH3<R>::FT
VectorH3<R>::squared_length() const
{
typedef typename R::FT FT;
return
FT( CGAL_NTS square(hx()) +
CGAL_NTS square(hy()) +
CGAL_NTS square(hz()) ) /
FT( CGAL_NTS square(hw()) );
}
template <class R>
CGAL_KERNEL_INLINE
typename R::Vector_3
VectorH3<R>::operator/(const typename VectorH3<R>::RT& f) const
{ return typename R::Vector_3( hx(), hy(), hz(), hw()*f ); }
template <class R>
CGAL_KERNEL_INLINE
typename R::Vector_3
VectorH3<R>::operator/(const typename VectorH3<R>::FT& f) const
{ return typename R::Vector_3(hx()*f.denominator(), hy()*f.denominator(),
hz()*f.denominator(), hw()*f.numerator() ); }
template < class R >
inline
typename R::Vector_3
VectorH3<R>::
transform(const typename VectorH3<R>::Aff_transformation_3&t ) const
{ return t.transform(*this); }
#ifndef CGAL_NO_OSTREAM_INSERT_VECTORH3
template < class R >
std::ostream& operator<<(std::ostream& os, const VectorH3<R>& v)
{
switch(os.iword(IO::mode))
{
case IO::ASCII :
return os << v.hx() << ' ' << v.hy() << ' ' << v.hz() << ' ' << v.hw();
case IO::BINARY :
write(os, v.hx());
write(os, v.hy());
write(os, v.hz());
write(os, v.hw());
return os;
default:
return os << "VectorH3(" << v.hx() << ", "
<< v.hy() << ", "
<< v.hz() << ", "
<< v.hw() << ')';
}
}
#endif // CGAL_NO_OSTREAM_INSERT_VECTORH3
#ifndef CGAL_NO_ISTREAM_EXTRACT_VECTORH3
template < class R >
std::istream& operator>>(std::istream& is, VectorH3<R>& v)
{
typename R::RT hx, hy, hz, hw;
switch(is.iword(IO::mode))
{
case IO::ASCII :
is >> hx >> hy >> hz >> hw;
break;
case IO::BINARY :
read(is, hx);
read(is, hy);
read(is, hz);
read(is, hw);
break;
default:
std::cerr << "" << std::endl;
std::cerr << "Stream must be in ascii or binary mode" << std::endl;
break;
}
v = VectorH3<R>(hx, hy, hz, hw);
return is;
}
#endif // CGAL_NO_ISTREAM_EXTRACT_VECTORH3
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_VECTOR_3_H
@@ -0,0 +1,75 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Sven Schoenherr
// Stefan Schirra
#ifndef CGAL_BASIC_CONSTRUCTIONSH2_H
#define CGAL_BASIC_CONSTRUCTIONSH2_H
#include <CGAL/Homogeneous/PointH2.h>
#include <CGAL/Homogeneous/LineH2.h>
CGAL_BEGIN_NAMESPACE
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
typename R::Point_2
gp_linear_intersection(const LineH2<R>& l1, const LineH2<R>& l2)
{
return typename R::Point_2( l1.b()*l2.c() - l2.b()*l1.c(),
l2.a()*l1.c() - l1.a()*l2.c(),
l1.a()*l2.b() - l2.a()*l1.b() );
}
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
typename R::FT
squared_distance( const PointH2<R>& p, const PointH2<R>& q )
{
typedef typename R::RT RT;
typedef typename R::FT FT;
const RT & phx = p.hx();
const RT & phy = p.hy();
const RT & phw = p.hw();
const RT & qhx = q.hx();
const RT & qhy = q.hy();
const RT & qhw = q.hw();
RT sq_dist_numerator =
phx * phx * qhw * qhw
- RT(2) * phx * qhx * phw * qhw
+ qhx * qhx * phw * phw
+ phy * phy * qhw * qhw
- RT(2) * phy * qhy * phw * qhw
+ qhy * qhy * phw * phw ;
RT sq_dist_denominator = qhw * qhw * phw * phw ;
return FT( sq_dist_numerator ) / FT( sq_dist_denominator );
}
CGAL_END_NAMESPACE
#endif // CGAL_BASIC_CONSTRUCTIONSH2_H
@@ -0,0 +1,85 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_BASIC_CONSTRUCTIONSH3_H
#define CGAL_BASIC_CONSTRUCTIONSH3_H
CGAL_BEGIN_NAMESPACE
template <class R>
typename R::Point_3
_projection(const typename R::Point_3& p, const PlaneH3<R>& pl)
{
typedef typename R::RT RT;
if ( pl.has_on(p) ) return p;
RT A = pl.a();
RT B = pl.b();
RT C = pl.c();
RT D = pl.d();
RT phx = p.hx();
RT phy = p.hy();
RT phz = p.hz();
RT phw = p.hw();
RT num = A * phx + B * phy + C * phz + D * phw;
RT den = A * A + B * B + C * C;
return typename R::Point_3( num * A - den * phx,
num * B - den * phy,
num * C - den * phz,
-den );
}
template <class R>
typename R::Point_3
gp_linear_intersection(const PlaneH3<R> &f,
const PlaneH3<R> &g,
const PlaneH3<R> &h)
{
typedef typename R::RT RT;
return typename R::Point_3(
det3x3_by_formula<RT>(-f.d(), f.b(), f.c(),
-g.d(), g.b(), g.c(),
-h.d(), h.b(), h.c()),
det3x3_by_formula<RT>( f.a(),-f.d(), f.c(),
g.a(),-g.d(), g.c(),
h.a(),-h.d(), h.c()),
det3x3_by_formula<RT>( f.a(), f.b(),-f.d(),
g.a(), g.b(),-g.d(),
h.a(), h.b(),-h.d()),
det3x3_by_formula<RT>( f.a(), f.b(), f.c(),
g.a(), g.b(), g.c(),
h.a(), h.b(), h.c()));
}
template <class R>
CGAL_KERNEL_INLINE
typename R::FT
squared_distance( PointH3<R> const& p, PointH3<R> const& q)
{ return (p-q)*(p-q); }
CGAL_END_NAMESPACE
#endif // CGAL_BASIC_CONSTRUCTIONSH3_H
@@ -0,0 +1,283 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_DISTANCE_PREDICATESH2_H
#define CGAL_DISTANCE_PREDICATESH2_H
#include <CGAL/determinant.h>
CGAL_BEGIN_NAMESPACE
template < class R>
CGAL_KERNEL_MEDIUM_INLINE
bool
has_larger_distance_to_point(const PointH2<R>& p,
const PointH2<R>& q,
const PointH2<R>& r)
{
typedef typename R::RT RT;
const RT phx = p.hx();
const RT phy = p.hy();
const RT phw = p.hw();
const RT qhx = q.hx();
const RT qhy = q.hy();
const RT qhw = q.hw();
const RT rhx = r.hx();
const RT rhy = r.hy();
const RT rhw = r.hw();
const RT RT0 = RT(0);
const RT RT2 = RT(2);
RT dosd = // difference of squared distances
// phx * phx * qhw * qhw * rhw * rhw
// -RT(2) * phx * qhx * phw * qhw * rhw * rhw
// + qhx * qhx * phw * phw * rhw * rhw
//
// + phy * phy * qhw * qhw * rhw * rhw
// -RT(2) * phy * qhy * phw * qhw * rhw * rhw
// + qhy * qhy * phw * phw * rhw * rhw
//
// - ( phx * phx * qhw * qhw * rhw * rhw
// -RT(2) * phx * rhx * phw * qhw * qhw * rhw
// + rhx * rhx * phw * phw * qhw * qhw
//
// + phy * phy * qhw * qhw * rhw * rhw
// -RT(2) * phy * rhy * phw * qhw * qhw * rhw
// + rhy * rhy * phw * phw * qhw * qhw
rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy )
- RT2 * qhw * ( phx*qhx + phy*qhy )
)
- qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy )
- RT2 * rhw * ( phx*rhx + phy*rhy )
);
return ( dosd > RT0 );
}
template < class R>
CGAL_KERNEL_INLINE
Comparison_result
compare_signed_distance_to_line(const LineH2<R>& l,
const PointH2<R>& p,
const PointH2<R>& q)
{
typedef typename R::RT RT;
const RT la = l.a();
const RT lb = l.b();
const RT phx= p.hx();
const RT phy= p.hy();
const RT phw= p.hw();
const RT qhx= q.hx();
const RT qhy= q.hy();
const RT qhw= q.hw();
const RT RT0 = RT(0);
RT scaled_dist_p_minus_scaled_dist_q =
la*( phx*qhw - qhx*phw )
+ lb*( phy*qhw - qhy*phw );
if ( scaled_dist_p_minus_scaled_dist_q < RT0 )
{
return SMALLER;
}
else
{
return ( RT0 < scaled_dist_p_minus_scaled_dist_q ) ?
LARGER : EQUAL;
}
}
template < class R>
CGAL_KERNEL_INLINE
bool
has_larger_signed_distance_to_line(const LineH2<R>& l,
const PointH2<R>& p,
const PointH2<R>& q)
{
typedef typename R::RT RT;
const RT la = l.a();
const RT lb = l.b();
const RT phx= p.hx();
const RT phy= p.hy();
const RT phw= p.hw();
const RT qhx= q.hx();
const RT qhy= q.hy();
const RT qhw= q.hw();
const RT RT0 = RT(0);
RT scaled_dist_p_minus_scaled_dist_q =
la*( phx*qhw - qhx*phw )
+ lb*( phy*qhw - qhy*phw );
return ( scaled_dist_p_minus_scaled_dist_q > RT0 );
}
template < class R>
CGAL_KERNEL_INLINE
bool
has_smaller_signed_distance_to_line(const LineH2<R>& l,
const PointH2<R>& p,
const PointH2<R>& q)
{
typedef typename R::RT RT;
const RT la = l.a();
const RT lb = l.b();
const RT phx= p.hx();
const RT phy= p.hy();
const RT phw= p.hw();
const RT qhx= q.hx();
const RT qhy= q.hy();
const RT qhw= q.hw();
const RT RT0 = RT(0);
RT scaled_dist_p_minus_scaled_dist_q =
la*( phx*qhw - qhx*phw )
+ lb*( phy*qhw - qhy*phw );
return ( scaled_dist_p_minus_scaled_dist_q < RT0 );
}
template < class R>
CGAL_KERNEL_MEDIUM_INLINE
Comparison_result
compare_signed_distance_to_line(const PointH2<R>& p,
const PointH2<R>& q,
const PointH2<R>& r,
const PointH2<R>& s)
{
typedef typename R::RT RT;
const RT phx= p.hx();
const RT phy= p.hy();
const RT phw= p.hw();
const RT qhx= q.hx();
const RT qhy= q.hy();
const RT qhw= q.hw();
const RT rhx= r.hx();
const RT rhy= r.hy();
const RT rhw= r.hw();
const RT shx= s.hx();
const RT shy= s.hy();
const RT shw= s.hw();
const RT RT0 = RT(0);
RT scaled_dist_r_minus_scaled_dist_s =
( rhx*shw - shx*rhw ) * (phy*qhw - qhy*phw)
- ( rhy*shw - shy*rhw ) * (phx*qhw - qhx*phw);
if ( scaled_dist_r_minus_scaled_dist_s < RT0 )
{
return SMALLER;
}
else
{
return (scaled_dist_r_minus_scaled_dist_s > RT0 ) ?
LARGER : EQUAL;
}
}
template < class R>
CGAL_KERNEL_MEDIUM_INLINE
bool
has_smaller_signed_distance_to_line(const PointH2<R>& p,
const PointH2<R>& q,
const PointH2<R>& r,
const PointH2<R>& s)
{
typedef typename R::RT RT;
const RT phx= p.hx();
const RT phy= p.hy();
const RT phw= p.hw();
const RT qhx= q.hx();
const RT qhy= q.hy();
const RT qhw= q.hw();
const RT rhx= r.hx();
const RT rhy= r.hy();
const RT rhw= r.hw();
const RT shx= s.hx();
const RT shy= s.hy();
const RT shw= s.hw();
const RT RT0 = RT(0);
RT scaled_dist_r_minus_scaled_dist_s =
( rhx*shw - shx*rhw ) * (phy*qhw - qhy*phw)
- ( rhy*shw - shy*rhw ) * (phx*qhw - qhx*phw);
return ( scaled_dist_r_minus_scaled_dist_s < RT0 );
}
template < class R>
CGAL_KERNEL_MEDIUM_INLINE
bool
has_larger_signed_distance_to_line(const PointH2<R>& p,
const PointH2<R>& q,
const PointH2<R>& r,
const PointH2<R>& s)
{
typedef typename R::RT RT;
const RT phx= p.hx();
const RT phy= p.hy();
const RT phw= p.hw();
const RT qhx= q.hx();
const RT qhy= q.hy();
const RT qhw= q.hw();
const RT rhx= r.hx();
const RT rhy= r.hy();
const RT rhw= r.hw();
const RT shx= s.hx();
const RT shy= s.hy();
const RT shw= s.hw();
const RT RT0 = RT(0);
RT scaled_dist_r_minus_scaled_dist_s =
( rhx*shw - shx*rhw ) * (phy*qhw - qhy*phw)
- ( rhy*shw - shy*rhw ) * (phx*qhw - qhx*phw);
return ( scaled_dist_r_minus_scaled_dist_s > RT0 );
}
CGAL_END_NAMESPACE
#endif //CGAL_DISTANCE_PREDICATESH2_H
@@ -0,0 +1,333 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_DISTANCE_PREDICATESH3_H
#define CGAL_DISTANCE_PREDICATESH3_H
CGAL_BEGIN_NAMESPACE
template <class R>
Comparison_result
compare_distance_to_point(const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
bool
has_larger_distance_to_point(const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
bool
has_smaller_distance_to_point(const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
Comparison_result
compare_signed_distance_to_plane(const PlaneH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
bool
has_larger_signed_distance_to_plane(const PlaneH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
bool
has_smaller_signed_distance_to_plane(const PlaneH3<R>&,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
Comparison_result
compare_signed_distance_to_plane(const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
bool
has_larger_signed_distance_to_plane(const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
bool
has_smaller_signed_distance_to_plane(const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& ,
const PointH3<R>& );
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
Comparison_result
compare_distance_to_point(const PointH3<R>& p,
const PointH3<R>& q,
const PointH3<R>& r)
{
typedef typename R::RT RT;
const RT phx = p.hx();
const RT phy = p.hy();
const RT phz = p.hz();
const RT phw = p.hw();
const RT qhx = q.hx();
const RT qhy = q.hy();
const RT qhz = q.hz();
const RT qhw = q.hw();
const RT rhx = r.hx();
const RT rhy = r.hy();
const RT rhz = r.hz();
const RT rhw = r.hw();
const RT RT0 = RT(0);
const RT RT2 = RT(2);
RT dosd = // difference of squared distances
rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz )
- RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz )
)
- qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz )
- RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz )
);
if ( RT0 < dosd )
{ return LARGER; }
else
{ return (dosd < RT0) ? SMALLER : EQUAL; }
}
template < class R>
CGAL_KERNEL_MEDIUM_INLINE
bool
has_larger_distance_to_point(const PointH3<R>& p,
const PointH3<R>& q,
const PointH3<R>& r)
{
typedef typename R::RT RT;
const RT phx = p.hx();
const RT phy = p.hy();
const RT phz = p.hz();
const RT phw = p.hw();
const RT qhx = q.hx();
const RT qhy = q.hy();
const RT qhz = q.hz();
const RT qhw = q.hw();
const RT rhx = r.hx();
const RT rhy = r.hy();
const RT rhz = r.hz();
const RT rhw = r.hw();
const RT RT0 = RT(0);
const RT RT2 = RT(2);
RT dosd = // difference of squared distances
rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz )
- RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz )
)
- qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz )
- RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz )
);
return ( RT0 < dosd );
}
template < class R>
CGAL_KERNEL_MEDIUM_INLINE
bool
has_smaller_distance_to_point(const PointH3<R>& p,
const PointH3<R>& q,
const PointH3<R>& r)
{
typedef typename R::RT RT;
const RT phx = p.hx();
const RT phy = p.hy();
const RT phz = p.hz();
const RT phw = p.hw();
const RT qhx = q.hx();
const RT qhy = q.hy();
const RT qhz = q.hz();
const RT qhw = q.hw();
const RT rhx = r.hx();
const RT rhy = r.hy();
const RT rhz = r.hz();
const RT rhw = r.hw();
const RT RT0 = RT(0);
const RT RT2 = RT(2);
RT dosd = // difference of squared distances
rhw*rhw * ( phw * ( qhx*qhx + qhy*qhy + qhz*qhz )
- RT2 * qhw * ( phx*qhx + phy*qhy + phz*qhz )
)
- qhw*qhw * ( phw * ( rhx*rhx + rhy*rhy + rhz*rhz )
- RT2 * rhw * ( phx*rhx + phy*rhy + phz*rhz )
);
return ( dosd < RT0 );
}
template < class R>
CGAL_KERNEL_INLINE
Comparison_result
compare_signed_distance_to_plane(const PlaneH3<R>& pl,
const PointH3<R>& p,
const PointH3<R>& q)
{
typedef typename R::RT RT;
const RT pla = pl.a();
const RT plb = pl.b();
const RT plc = pl.c();
const RT phx = p.hx();
const RT phy = p.hy();
const RT phz = p.hz();
const RT phw = p.hw();
const RT qhx = q.hx();
const RT qhy = q.hy();
const RT qhz = q.hz();
const RT qhw = q.hw();
const RT RT0 = RT(0);
RT scaled_dist_p_minus_scaled_dist_q =
pla*( phx*qhw - qhx*phw )
+ plb*( phy*qhw - qhy*phw )
+ plc*( phz*qhw - qhz*phw );
if ( scaled_dist_p_minus_scaled_dist_q < RT0 )
{ return SMALLER; }
else
{ return (RT0 < scaled_dist_p_minus_scaled_dist_q ) ? LARGER : EQUAL;}
}
template <class R>
bool
has_larger_signed_distance_to_plane(const PlaneH3<R>& pl,
const PointH3<R>& p,
const PointH3<R>& q )
{
typedef typename R::RT RT;
const RT pla = pl.a();
const RT plb = pl.b();
const RT plc = pl.c();
const RT phx = p.hx();
const RT phy = p.hy();
const RT phz = p.hz();
const RT phw = p.hw();
const RT qhx = q.hx();
const RT qhy = q.hy();
const RT qhz = q.hz();
const RT qhw = q.hw();
const RT RT0 = RT(0);
RT scaled_dist_p_minus_scaled_dist_q =
pla*( phx*qhw - qhx*phw )
+ plb*( phy*qhw - qhy*phw )
+ plc*( phz*qhw - qhz*phw );
return ( RT0 < scaled_dist_p_minus_scaled_dist_q );
}
template <class R>
bool
has_smaller_signed_distance_to_plane(const PlaneH3<R>& pl,
const PointH3<R>& p,
const PointH3<R>& q )
{
typedef typename R::RT RT;
const RT pla = pl.a();
const RT plb = pl.b();
const RT plc = pl.c();
const RT phx = p.hx();
const RT phy = p.hy();
const RT phz = p.hz();
const RT phw = p.hw();
const RT qhx = q.hx();
const RT qhy = q.hy();
const RT qhz = q.hz();
const RT qhw = q.hw();
const RT RT0 = RT(0);
RT scaled_dist_p_minus_scaled_dist_q =
pla*( phx*qhw - qhx*phw )
+ plb*( phy*qhw - qhy*phw )
+ plc*( phz*qhw - qhz*phw );
return ( scaled_dist_p_minus_scaled_dist_q < RT0 );
}
template <class R>
inline
Comparison_result
compare_signed_distance_to_plane(const PointH3<R>& p,
const PointH3<R>& q,
const PointH3<R>& r,
const PointH3<R>& s,
const PointH3<R>& t)
{
CGAL_kernel_precondition( !collinear(p,q,r) );
PlaneH3<R> P(p,q,r);
return cmp_signed_dist_to_plane( P, s, t);
}
template <class R>
inline
bool
has_larger_signed_distance_to_plane(const PointH3<R>& p,
const PointH3<R>& q,
const PointH3<R>& r,
const PointH3<R>& s,
const PointH3<R>& t)
{ return cmp_signed_dist_to_plane(p,q,r,s,t) == LARGER; }
template <class R>
inline
bool
has_smaller_signed_distance_to_plane(const PointH3<R>& p,
const PointH3<R>& q,
const PointH3<R>& r,
const PointH3<R>& s,
const PointH3<R>& t)
{ return cmp_signed_dist_to_plane(p,q,r,s,t) == SMALLER; }
CGAL_END_NAMESPACE
#endif //CGAL_DISTANCE_PREDICATESH3_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,35 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_PREDICATES_ON_DIRECTIONSH2_H
#define CGAL_PREDICATES_ON_DIRECTIONSH2_H
#include <CGAL/Homogeneous/PointH2.h>
#include <CGAL/Homogeneous/VectorH2.h>
#include <CGAL/Homogeneous/DirectionH2.h>
#include <CGAL/Homogeneous/predicates_on_pointsH2.h>
// kind of obsolete...
#endif // CGAL_PREDICATES_ON_DIRECTIONSH2_H
@@ -0,0 +1,104 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_PREDICATES_ON_POINTSH2_H
#define CGAL_PREDICATES_ON_POINTSH2_H
#include <CGAL/Homogeneous/PointH2.h>
CGAL_BEGIN_NAMESPACE
template < class R>
CGAL_KERNEL_INLINE
bool
equal_xy(const PointH2<R>& p,
const PointH2<R>& q)
{
typedef typename R::RT RT;
// Using these references allows to spare calls to [pq].hw().
const RT& phw = p.hw();
const RT& qhw = q.hw();
return (p.hx()*qhw == q.hx()*phw) && (p.hy()*qhw == q.hy()*phw);
}
template < class R>
CGAL_KERNEL_INLINE
Comparison_result
compare_yx(const PointH2<R>& p, const PointH2<R>& q)
{
typedef typename R::RT RT;
const RT& phx = p.hx();
const RT& phy = p.hy();
const RT& phw = p.hw();
const RT& qhx = q.hx();
const RT& qhy = q.hy();
const RT& qhw = q.hw();
RT pV = phy*qhw;
RT qV = qhy*phw;
if ( pV == qV )
{
pV = phx*qhw;
qV = qhx*phw;
}
if ( pV < qV )
return SMALLER;
else
return ( qV < pV ) ? LARGER : EQUAL;
}
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
Oriented_side
_where_wrt_L_wedge( const PointH2<R>& p, const PointH2<R>& q )
{
Sign xs = CGAL_NTS sign( q.hx()*p.hw() - p.hx()*q.hw() ); // sign( qx - px )
Sign ys = CGAL_NTS sign( q.hy()*p.hw() - p.hy()*q.hw() ); // sign( qy - py )
if (( xs == NEGATIVE ) || ( ys == NEGATIVE ))
return ON_NEGATIVE_SIDE;
if (( xs == POSITIVE ) && ( ys == POSITIVE ))
return ON_POSITIVE_SIDE;
return ON_ORIENTED_BOUNDARY;
}
template < class R >
CGAL_KERNEL_MEDIUM_INLINE
Comparison_result
compare_deltax_deltay(const PointH2<R>& p,
const PointH2<R>& q,
const PointH2<R>& r,
const PointH2<R>& s)
{
return CGAL_NTS compare(
CGAL_NTS abs(p.hx()*q.hw() - q.hx()*p.hw()) * r.hw()*s.hw(),
CGAL_NTS abs(r.hy()*s.hw() - s.hy()*r.hw()) * p.hw()*q.hw());
}
CGAL_END_NAMESPACE
#endif // CGAL_PREDICATES_ON_POINTSH2_H
@@ -0,0 +1,129 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_PREDICATES_ON_POINTSH3_H
#define CGAL_PREDICATES_ON_POINTSH3_H
#include <CGAL/Homogeneous/PointH3.h>
CGAL_BEGIN_NAMESPACE
template < class R >
CGAL_KERNEL_MEDIUM_INLINE
bool lexicographically_xy_smaller(const PointH3<R> &p,
const PointH3<R> &q)
{
typedef typename R::RT RT;
RT pV = p.hx()*q.hw();
RT qV = q.hx()*p.hw();
if ( pV < qV )
{
return true;
}
if ( qV < pV )
{
return false;
}
// same x
pV = p.hy()*q.hw();
qV = q.hy()*p.hw();
if ( pV < qV )
{
return true;
}
return false;
}
template < class R>
CGAL_KERNEL_MEDIUM_INLINE
Comparison_result
compare_xy(const PointH3<R>& p, const PointH3<R>& q)
{
typedef typename R::RT RT;
RT pV = p.hx()*q.hw();
RT qV = q.hx()*p.hw();
if ( pV < qV )
{
return SMALLER;
}
if ( qV < pV ) // ( pV > qV )
{
return LARGER;
}
// same x
pV = p.hy()*q.hw();
qV = q.hy()*p.hw();
if ( pV < qV )
{
return SMALLER;
}
if ( qV < pV ) // ( pV > qV )
{
return LARGER;
}
// same x and y
return EQUAL;
}
template < class R >
CGAL_KERNEL_INLINE
bool
equal_xy(const PointH3<R> &p, const PointH3<R> &q)
{
return (p.hx() * q.hw() == q.hx() * p.hw() )
&& (p.hy() * q.hw() == q.hy() * p.hw() );
}
template < class R > // ??? -> ==
CGAL_KERNEL_INLINE
bool
equal_xyz(const PointH3<R> &p, const PointH3<R> &q)
{
return (p.hx() * q.hw() == q.hx() * p.hw() )
&& (p.hy() * q.hw() == q.hy() * p.hw() )
&& (p.hz() * q.hw() == q.hz() * p.hw() );
}
template < class R >
CGAL_KERNEL_INLINE
bool
less_x(const PointH3<R> &p, const PointH3<R> &q)
{ return (p.hx() * q.hw() < q.hx() * p.hw() ); }
template < class R >
CGAL_KERNEL_INLINE
bool
less_y(const PointH3<R> &p, const PointH3<R> &q)
{ return (p.hy() * q.hw() < q.hy() * p.hw() ); }
template < class R >
CGAL_KERNEL_INLINE
bool
less_z(const PointH3<R> &p, const PointH3<R> &q)
{ return (p.hz() * q.hw() < q.hz() * p.hw() ); }
CGAL_END_NAMESPACE
#endif // CGAL_PREDICATES_ON_POINTSH3_H
@@ -0,0 +1,62 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra
#ifndef CGAL_PREDICATES_ON_RTH2_H
#define CGAL_PREDICATES_ON_RTH2_H
CGAL_BEGIN_NAMESPACE
template <class RT>
CGAL_KERNEL_INLINE
Orientation
orientationH2( const RT& phx, const RT& phy, const RT& phw,
const RT& qhx, const RT& qhy, const RT& qhw,
const RT& rhx, const RT& rhy, const RT& rhw )
{
const RT RT0 = RT(0);
// | A B |
// | C D |
RT A = phx*rhw - phw*rhx;
RT B = phy*rhw - phw*rhy;
RT C = qhx*rhw - qhw*rhx;
RT D = qhy*rhw - qhw*rhy;
RT det = A*D - B*C;
if (det < RT0 )
{
return CLOCKWISE;
}
else
{
return (RT0 < det) ? COUNTERCLOCKWISE : COLLINEAR;
}
}
CGAL_END_NAMESPACE
#endif // CGAL_PREDICATES_ON_RTH2_H
@@ -0,0 +1,262 @@
// Copyright (c) 2001-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.
//
// $URL$
// $Id$
//
//
// Author(s) : Sylvain Pion <Sylvain.Pion@sophia.inria.fr>
// Menelaos Karavelas <mkaravel@cse.nd.edu>
#ifndef CGAL_HOMOGENEOUS_CONVERTER_H
#define CGAL_HOMOGENEOUS_CONVERTER_H
// This file contains the definition of a kernel converter, based on
// Homogeneous representation. It should work between *Homogeneous<A,B>
// and *Homogeneous<C,D>, provided you give an RT converter from A to C,
// and an FT converter from B to D.
#include <CGAL/basic.h>
#include <CGAL/NT_converter.h>
#include <CGAL/Enum_converter.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Bbox_3.h>
CGAL_BEGIN_NAMESPACE
template <class K1, class K2,
class RT_Converter = NT_converter<typename K1::RT, typename K2::RT>,
class FT_Converter = NT_converter<typename K1::FT, typename K2::FT> >
class Homogeneous_converter : public Enum_converter
{
private:
typedef Enum_converter Base;
public:
typedef K1 Source_kernel;
typedef K2 Target_kernel;
typedef RT_Converter Ring_number_type_converter;
typedef FT_Converter Field_number_type_converter;
#ifdef CGAL_CFG_USING_BASE_MEMBER_BUG
bool operator()(bool b) const { return Base::operator()(b); }
Sign operator()(Sign s) const { return Base::operator()(s); }
Oriented_side operator()(Oriented_side os) const {
return Base::operator()(os);
}
Bounded_side operator()(Bounded_side bs) const {
return Base::operator()(bs);
}
Comparison_result operator()(Comparison_result cr) const {
return Base::operator()(cr);
}
Angle operator()(Angle a) const { return Base::operator()(a); }
#else
using Base::operator();
#endif
Bbox_2
operator()(const Bbox_2& b)
{
return b;
}
Bbox_3
operator()(const Bbox_3& b)
{
return b;
}
typename K2::RT
operator()(const typename K1::RT &a) const
{
return c(a);
}
typename K2::FT
operator()(const typename K1::FT &a) const
{
return c(a);
}
typename K2::Point_2
operator()(const typename K1::Point_2 &a) const
{
return k.construct_point_2_object()(rc(a.hx()), rc(a.hy()),
rc(a.hw()));
}
typename K2::Vector_2
operator()(const typename K1::Vector_2 &a) const
{
return k.construct_vector_2_object()(rc(a.hx()), rc(a.hy()),
rc(a.hw()));
}
typename K2::Direction_2
operator()(const typename K1::Direction_2 &a) const
{
return k.construct_direction_2_object()(rc(a.dx()), rc(a.dy()));
}
typename K2::Segment_2
operator()(const typename K1::Segment_2 &a) const
{
return k.construct_segment_2_object()(operator()(a.source()),
operator()(a.target()));
}
typename K2::Line_2
operator()(const typename K1::Line_2 &a) const
{
return k.construct_line_2_object()(rc(a.a()), rc(a.b()), rc(a.c()));
}
typename K2::Ray_2
operator()(const typename K1::Ray_2 &a) const
{
return k.construct_ray_2_object()(operator()(a.source()),
operator()(a.second_point()));
}
typename K2::Circle_2
operator()(const typename K1::Circle_2 &a) const
{
return k.construct_circle_2_object()(operator()(a.center()),
fc(a.squared_radius()),
a.orientation());
}
typename K2::Triangle_2
operator()(const typename K1::Triangle_2 &a) const
{
return k.construct_triangle_2_object()(operator()(a.vertex(0)),
operator()(a.vertex(1)),
operator()(a.vertex(2)));
}
typename K2::Iso_rectangle_2
operator()(const typename K1::Iso_rectangle_2 &a) const
{
return k.construct_iso_rectangle_2_object()(operator()(a.min()),
operator()(a.max()));
}
typename K2::Point_3
operator()(const typename K1::Point_3 &a) const
{
return k.construct_point_3_object()(rc(a.hx()), rc(a.hy()),
rc(a.hz()), rc(a.hw()));
}
typename K2::Vector_3
operator()(const typename K1::Vector_3 &a) const
{
return k.construct_vector_3_object()(rc(a.hx()), rc(a.hy()),
rc(a.hz()), rc(a.hw()));
}
typename K2::Direction_3
operator()(const typename K1::Direction_3 &a) const
{
return k.construct_direction_3_object()(rc(a.dx()), rc(a.dy()),
rc(a.dz()));
}
typename K2::Segment_3
operator()(const typename K1::Segment_3 &a) const
{
return k.construct_segment_3_object()(operator()(a.source()),
operator()(a.target()));
}
typename K2::Line_3
operator()(const typename K1::Line_3 &a) const
{
return k.construct_line_3_object()(operator()(a.point()),
operator()(a.direction()));
}
typename K2::Ray_3
operator()(const typename K1::Ray_3 &a) const
{
return k.construct_ray_3_object()(operator()(a.source()),
operator()(a.second_point()));
}
typename K2::Sphere_3
operator()(const typename K1::Sphere_3 &a) const
{
return k.construct_sphere_3_object()(operator()(a.center()),
fc(a.squared_radius()),
a.orientation());
}
typename K2::Triangle_3
operator()(const typename K1::Triangle_3 &a) const
{
return k.construct_triangle_3_object()(operator()(a.vertex(0)),
operator()(a.vertex(1)),
operator()(a.vertex(2)));
}
typename K2::Tetrahedron_3
operator()(const typename K1::Tetrahedron_3 &a) const
{
return k.construct_tetrahedron_3_object()(operator()(a.vertex(0)),
operator()(a.vertex(1)),
operator()(a.vertex(2)),
operator()(a.vertex(3)));
}
typename K2::Plane_3
operator()(const typename K1::Plane_3 &a) const
{
return k.construct_plane_3_object()(rc(a.a()), rc(a.b()), rc(a.c()),
rc(a.d()));
}
typename K2::Iso_cuboid_3
operator()(const typename K1::Iso_cuboid_3 &a) const
{
return k.construct_iso_cuboid_3_object()(operator()(a.min()),
operator()(a.max()));
}
private:
RT_Converter rc;
FT_Converter fc;
K2 k;
};
// Specialization when converting to the same kernel,
// to avoid making copies.
template < class K, class C1, class C2 >
struct Homogeneous_converter <K, K, C1, C2>
{
template < typename T >
const T& operator()(const T&t) const { return t; }
};
CGAL_END_NAMESPACE
#endif // CGAL_HOMOGENEOUS_CONVERTER_H
@@ -0,0 +1,61 @@
// Copyright (c) 1999 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.
//
// $URL$
// $Id$
//
//
// Author(s) : Stefan Schirra, Sylvain Pion
#ifndef CGAL_SIMPLE_HOMOGENEOUS_H
#define CGAL_SIMPLE_HOMOGENEOUS_H
#include <CGAL/Homogeneous/Homogeneous_base.h>
#include <CGAL/Handle_for.h>
#include <CGAL/Kernel/Type_equality_wrapper.h>
#include <CGAL/Quotient.h>
CGAL_BEGIN_NAMESPACE
template < typename RT_, typename FT_, typename Kernel >
struct Homogeneous_base_no_ref_count
: public Homogeneous_base<RT_, FT_, Kernel >
{
typedef RT_ RT;
typedef FT_ FT;
// The mecanism that allows to specify reference-counting or not.
template < typename T >
struct Handle { typedef T type; };
template < typename Kernel2 >
struct Base {
typedef Homogeneous_base_no_ref_count<RT_,FT_,Kernel2> Type;
};
};
template < typename RT_, typename FT_ = Quotient<RT_> >
struct Simple_homogeneous
: public Type_equality_wrapper<
Homogeneous_base_no_ref_count<RT_, FT_,
Simple_homogeneous<RT_, FT_> >,
Simple_homogeneous<RT_, FT_> >
{};
CGAL_END_NAMESPACE
#endif // CGAL_SIMPLE_HOMOGENEOUS_H