File: DirectionCd.h

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (133 lines) | stat: -rw-r--r-- 3,826 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2000,2001
// Utrecht University (The Netherlands),
// ETH Zurich (Switzerland),
// INRIA Sophia-Antipolis (France),
// Max-Planck-Institute Saarbruecken (Germany),
// and Tel-Aviv University (Israel).  All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Kernel_d/include/CGAL/Kernel_d/DirectionCd.h $
// $Id: include/CGAL/Kernel_d/DirectionCd.h b26b07a1242 $
// 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>
#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>
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]; }

public:
/*{\Mtypes 4}*/

typedef _FT RT;
typedef _FT FT;
typedef _LA LA;
typedef typename Tuple::const_iterator Delta_const_iterator;

class Base_direction {};

friend class VectorCd<FT,LA>;

DirectionCd(int d = 0) : Base( Tuple(d) ) {}

DirectionCd(const VectorCd<FT,LA>& v);

template <class InputIterator>
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)) ) {}
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()) ) {}

~DirectionCd() {}

int dimension() const { return ptr()->size(); }

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); }

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(); }

VectorCd<FT,LA> vector() const;

bool is_degenerate() const
{ return vector_rep().is_zero(); }

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();
  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;
  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); }

friend std::istream& operator>> <>
  (std::istream& I, DirectionCd<FT,LA>& d);
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 ----------------------------------