1 // Copyright (c) 2000
2 // Utrecht University (The Netherlands),
3 // ETH Zurich (Switzerland),
4 // INRIA Sophia-Antipolis (France),
5 // Max-Planck-Institute Saarbruecken (Germany),
6 // and Tel-Aviv University (Israel). All rights reserved.
7 //
8 // This file is part of CGAL (www.cgal.org)
9 //
10 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Cartesian_kernel/include/CGAL/Cartesian/Triangle_3.h $
11 // $Id: Triangle_3.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
12 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
13 //
14 //
15 // Author(s) : Andreas Fabri
16
17 #ifndef CGAL_CARTESIAN_TRIANGLE_3_H
18 #define CGAL_CARTESIAN_TRIANGLE_3_H
19
20 #include <CGAL/Handle_for.h>
21 #include <CGAL/array.h>
22
23 namespace CGAL {
24
25 template <class R_>
26 class TriangleC3
27 {
28 typedef typename R_::FT FT;
29 typedef typename R_::Point_3 Point_3;
30 typedef typename R_::Vector_3 Vector_3;
31 typedef typename R_::Plane_3 Plane_3;
32 typedef typename R_::Triangle_3 Triangle_3;
33
34 typedef std::array<Point_3, 3> Rep;
35 typedef typename R_::template Handle<Rep>::type Base;
36
37 Base base;
38
39 public:
40 typedef R_ R;
41
TriangleC3()42 TriangleC3() {}
43
TriangleC3(const Point_3 & p,const Point_3 & q,const Point_3 & r)44 TriangleC3(const Point_3 &p, const Point_3 &q, const Point_3 &r)
45 : base(CGAL::make_array(p, q, r)) {}
46
47 bool operator==(const TriangleC3 &t) const;
48 bool operator!=(const TriangleC3 &t) const;
49
50 Plane_3 supporting_plane() const;
51
52 bool has_on(const Point_3 &p) const;
53 bool is_degenerate() const;
54
55 const Point_3 & vertex(int i) const;
56 const Point_3 & operator[](int i) const;
57
58 FT squared_area() const;
59 };
60
61 template < class R >
62 bool
63 TriangleC3<R>::operator==(const TriangleC3<R> &t) const
64 {
65 if (CGAL::identical(base, t.base))
66 return true;
67
68 int i;
69 for(i=0; i<3; i++)
70 if ( vertex(0) == t.vertex(i) )
71 break;
72
73 return (i<3) && vertex(1) == t.vertex(i+1) && vertex(2) == t.vertex(i+2);
74 }
75
76 template < class R >
77 inline
78 bool
79 TriangleC3<R>::operator!=(const TriangleC3<R> &t) const
80 {
81 return !(*this == t);
82 }
83
84 template < class R >
85 const typename TriangleC3<R>::Point_3 &
vertex(int i)86 TriangleC3<R>::vertex(int i) const
87 {
88 if (i<0) i=(i%3)+3;
89 else if (i>2) i=i%3;
90 return (i==0) ? get_pointee_or_identity(base)[0] :
91 (i==1) ? get_pointee_or_identity(base)[1] :
92 get_pointee_or_identity(base)[2];
93 }
94
95 template < class R >
96 inline
97 const typename TriangleC3<R>::Point_3 &
98 TriangleC3<R>::operator[](int i) const
99 {
100 return vertex(i);
101 }
102
103 template < class R >
104 CGAL_KERNEL_MEDIUM_INLINE
105 typename TriangleC3<R>::FT
squared_area()106 TriangleC3<R>::squared_area() const
107 {
108 return internal::squared_area(vertex(0), vertex(1), vertex(2), R());
109 }
110
111 template < class R >
112 inline
113 typename TriangleC3<R>::Plane_3
supporting_plane()114 TriangleC3<R>::supporting_plane() const
115 {
116 return Plane_3(vertex(0), vertex(1), vertex(2));
117 }
118
119 template < class R >
120 inline
121 bool
122 TriangleC3<R>::
has_on(const typename TriangleC3<R>::Point_3 & p)123 has_on(const typename TriangleC3<R>::Point_3 &p) const
124 {
125 return R().has_on_3_object()
126 (static_cast<const typename R::Triangle_3&>(*this), p);
127 }
128
129 template < class R >
130 bool
is_degenerate()131 TriangleC3<R>::is_degenerate() const
132 {
133 return collinear(vertex(0),vertex(1),vertex(2));
134 }
135
136 } //namespace CGAL
137
138 #endif // CGAL_CARTESIAN_TRIANGLE_3_H
139