dust3d/thirdparty/cgal/CGAL-5.1/include/CGAL/Kernel_d/DirectionCd.h

134 lines
3.8 KiB
C
Raw Normal View History

2020-10-13 12:44:25 +00:00
// Copyright (c) 2000,2001
// Utrecht University (The Netherlands),
// ETH Zurich (Switzerland),
// INRIA Sophia-Antipolis (France),
// Max-Planck-Institute Saarbruecken (Germany),
2020-10-13 12:44:25 +00:00
// and Tel-Aviv University (Israel). All rights reserved.
//
2020-10-13 12:44:25 +00:00
// This file is part of CGAL (www.cgal.org)
//
2020-10-13 12:44:25 +00:00
// $URL: https://github.com/CGAL/cgal/blob/v5.1/Kernel_d/include/CGAL/Kernel_d/DirectionCd.h $
// $Id: DirectionCd.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Michael Seel
#ifndef CGAL_DIRECTIONCD_H
#define CGAL_DIRECTIONCD_H
#include <CGAL/basic.h>
2020-10-13 12:44:25 +00:00
#include <CGAL/Kernel_d/Tuple_d.h>
namespace CGAL {
template <class FT, class LA> class DirectionCd;
template <class FT, class LA>
std::istream& operator>>(std::istream&, DirectionCd<FT,LA>&);
template <class FT, class LA>
std::ostream& operator<<(std::ostream&, const DirectionCd<FT,LA>&);
template <class _FT, class _LA>
2020-10-13 12:44:25 +00:00
class DirectionCd : public Handle_for< Tuple_d<_FT,_LA> > {
typedef Tuple_d<_FT,_LA> Tuple;
typedef Handle_for<Tuple> Base;
typedef DirectionCd<_FT,_LA> Self;
using Base::ptr;
const typename _LA::Vector& vector_rep() const { return ptr()->v; }
_FT& entry(int i) { return ptr()->v[i]; }
const _FT& entry(int i) const { return ptr()->v[i]; }
2020-10-13 12:44:25 +00:00
public:
/*{\Mtypes 4}*/
typedef _FT RT;
typedef _FT FT;
typedef _LA LA;
typedef typename Tuple::const_iterator Delta_const_iterator;
class Base_direction {};
2020-10-13 12:44:25 +00:00
friend class VectorCd<FT,LA>;
DirectionCd(int d = 0) : Base( Tuple(d) ) {}
DirectionCd(const VectorCd<FT,LA>& v);
template <class InputIterator>
2020-10-13 12:44:25 +00:00
DirectionCd(int d, InputIterator first, InputIterator last) :
Base( Tuple(d,first,last) ) {}
DirectionCd(int d, Base_direction, int i) : Base( Tuple(d) )
{ if ( d==0 ) return;
CGAL_assertion_msg((0<=i&&i<d), "DirectionCd::base: index out of range.");
entry(i) = 1;
}
DirectionCd(const FT& x, const FT y) : Base( Tuple(x,y) ) {}
DirectionCd(int a, int b) : Base( Tuple(FT(a),FT(b)) ) {}
2020-10-13 12:44:25 +00:00
DirectionCd(const FT& x, const FT& y, const FT& z) :
Base( Tuple(x,y,z) ) {}
DirectionCd(int a, int b, int c) : Base( Tuple(FT(a),FT(b),FT(c), MatchHelper()) ) {}
2020-10-13 12:44:25 +00:00
~DirectionCd() {}
int dimension() const { return ptr()->size(); }
2020-10-13 12:44:25 +00:00
FT delta(int i) const
{ CGAL_assertion_msg((0<=i && i<(dimension())),
"DirectionCd::delta(): index out of range.");
return entry(i);
}
FT D() { return FT(1); }
2020-10-13 12:44:25 +00:00
FT operator[](int i) const
{ return delta(i); }
Delta_const_iterator deltas_begin() const { return ptr()->begin(); }
Delta_const_iterator deltas_end() const { return ptr()->end(); }
2020-10-13 12:44:25 +00:00
VectorCd<FT,LA> vector() const;
2020-10-13 12:44:25 +00:00
bool is_degenerate() const
{ return vector_rep().is_zero(); }
2020-10-13 12:44:25 +00:00
DirectionCd<FT,LA> transform(const Aff_transformationCd<FT,LA>& t) const;
DirectionCd<FT,LA> opposite() const
{ DirectionCd<FT,LA> result(*this); // creates a copied object!
result.copy_on_write(); // creates a copied object!
result.ptr()->invert();
2020-10-13 12:44:25 +00:00
return result;
}
DirectionCd<FT,LA> operator- () const
{ return opposite(); }
static Comparison_result cmp(
const DirectionCd<FT,LA>& h1, const DirectionCd<FT,LA>& h2);
bool operator==(const DirectionCd<FT,LA>& w) const
{ if ( this->identical(w) ) return true;
if ( dimension()!=w.dimension() ) return false;
2020-10-13 12:44:25 +00:00
return (DirectionCd<RT,LA>::cmp(*this,w) == EQUAL);
}
bool operator!=(const DirectionCd<FT,LA>& w) const
{ return !operator==(w); }
FT dx() const { return delta(0); }
FT dy() const { return delta(1); }
FT dz() const { return delta(2); }
2020-10-13 12:44:25 +00:00
friend std::istream& operator>> <>
(std::istream& I, DirectionCd<FT,LA>& d);
2020-10-13 12:44:25 +00:00
friend std::ostream& operator<< <>
(std::ostream& O, const DirectionCd<FT,LA>& d);
}; // end of class DirectionCd
} //namespace CGAL
#endif // CGAL_DIRECTIONCD_H
//----------------------- end of file ----------------------------------