Arcane  4.2.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
Vector3.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Vector3.h (C) 2000-2026 */
9/* */
10/* Vecteur à 3 dimensions. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_VECTOR3_H
13#define ARCANE_UTILS_VECTOR3_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include <iostream>
20#include <array>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31/*!
32 * \brief Classe gérant un vecteur de dimension 3 de type \a T
33 *
34 * Les 3 éléments du vecteur peuvent être accédés par \a x, \a y ou \a z.
35 */
36template <typename T>
38{
39 public:
40
41 using ThatClass = Vector3<T>;
42 using value_type = T;
43
44 public:
45
46 T x = {};
47 T y = {};
48 T z = {};
49
50 public:
51
52 //! Construit le vecteur nul.
53 Vector3() = default;
54
55 //! Construit le triplet (ax,ay,az)
56 constexpr ARCCORE_HOST_DEVICE Vector3(const T& ax, const T& ay, const T& az)
57 : x(ax)
58 , y(ay)
59 , z(az)
60 {
61 }
62
63 //! Construit l'instance avec le triplet (v,v,v).
64 constexpr ARCCORE_HOST_DEVICE explicit Vector3(const T& v)
65 : x(v)
66 , y(v)
67 , z(v)
68 {
69 }
70
71 //! Construit l'instance avec le tableau \a v
72 constexpr explicit Vector3(const std::array<T, 3>& v)
73 : x(v[0])
74 , y(v[1])
75 , z(v[2])
76 {
77 }
78
79 //! Construit l'instance avec la liste \a v
80 constexpr Vector3(std::initializer_list<T> v)
81 {
82 _setFromList(v);
83 }
84
85 //! Positionne l'instance avec la liste \a v
86 constexpr Vector3& operator=(std::initializer_list<T> v)
87 {
88 _setFromList(v);
89 return (*this);
90 }
91
92 public:
93
94 friend constexpr ARCCORE_HOST_DEVICE bool
95 operator<(const Vector3<T>& v1, const Vector3<T>& v2)
96 {
97 if (v1.x == v2.x) {
98 if (v1.y == v2.y)
99 return v1.z < v2.z;
100 else
101 return v1.y < v2.y;
102 }
103 return (v1.x < v2.x);
104 }
105
106 //! Ecrit le triplet \a t sur le flot \a o
107 friend std::ostream& operator<<(std::ostream& o, const Vector3<T>& t)
108 {
109 t._print(o);
110 return o;
111 }
112
113 friend constexpr ARCCORE_HOST_DEVICE bool
114 operator==(const Vector3<T>& v1, const Vector3<T>& v2)
115 {
116 return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
117 }
118
119 friend constexpr ARCCORE_HOST_DEVICE bool
120 operator!=(const Vector3<T>& v1, const Vector3<T>& v2)
121 {
122 return !(v1 == v2);
123 }
124
125 public:
126
127 //! Ajoute \a b à l'instance
128 constexpr ARCCORE_HOST_DEVICE void operator+=(const T& b)
129 {
130 x += b;
131 y += b;
132 z += b;
133 }
134
135 //! Ajoute \a b à l'instance
136 constexpr ARCCORE_HOST_DEVICE void operator+=(const ThatClass& b)
137 {
138 x += b.x;
139 y += b.y;
140 z += b.z;
141 }
142
143 //! Soustrait \a b de l'instance
144 constexpr ARCCORE_HOST_DEVICE void operator-=(const T& b)
145 {
146 x -= b;
147 y -= b;
148 z -= b;
149 }
150
151 //! Soustrait \a b de l'instance
152 constexpr ARCCORE_HOST_DEVICE void operator-=(const ThatClass& b)
153 {
154 x -= b.x;
155 y -= b.y;
156 z -= b.z;
157 }
158
159 //! Multiplie chaque composante de l'instance par \a b
160 constexpr ARCCORE_HOST_DEVICE void operator*=(const T& b)
161 {
162 x *= b;
163 y *= b;
164 z *= b;
165 }
166
167 //! Divise chaque composante de l'instance par \a b
168 constexpr ARCCORE_HOST_DEVICE void operator/=(const T& b)
169 {
170 x /= b;
171 y /= b;
172 z /= b;
173 }
174
175 //! Additionne composante par composante \a a et \a b
176 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator+(const ThatClass& a, const ThatClass& b)
177 {
178 return ThatClass(a.x + b.x, a.y + b.y, a.z + b.z);
179 }
180
181 //! Retourne \a a en ajoutant \a b à chaque composante
182 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator+(const ThatClass& a, const T& b)
183 {
184 return ThatClass(a.x + b, a.y + b, a.z + b);
185 }
186
187 //! Retourne \a b en ajoutant \a a à chaque composante
188 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator+(const T& a, const ThatClass& b)
189 {
190 return ThatClass(a + b.x, a + b.y, a + b.z);
191 }
192
193 //! Soustrait chaque composante de \a a par chaque composante de \a b
194 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator-(const ThatClass& a, const ThatClass& b)
195 {
196 return ThatClass(a.x - b.x, a.y - b.y, a.z - b.z);
197 }
198
199 //! Soustrait chaque composante de \a a par \a b
200 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator-(const ThatClass& a, const T& b)
201 {
202 return ThatClass(a.x - b, a.y - b, a.z - b);
203 }
204
205 //! Retourne l'opposé de l'instance
206 constexpr ARCCORE_HOST_DEVICE ThatClass operator-() const { return ThatClass(-x, -y, -z); }
207
208
209 //! Multiplie chaque composante de \a b par \a a
210 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator*(const T& a, const ThatClass& b)
211 {
212 return ThatClass(b.x * a, b.y * a, b.z * a);
213 }
214
215 //! Multiplie chaque composante de \a a par \a b
216 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator*(const ThatClass& a, const T& b)
217 {
218 return ThatClass(a.x * b, a.y * b, a.z * b);
219 }
220
221 //! Divise chaque composante de \a a par \a b
222 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator/(const ThatClass& a, const T& b)
223 {
224 return ThatClass(a.x / b, a.y / b, a.z / b);
225 }
226
227 private:
228
229 void _print(std::ostream& o) const
230 {
231 o << '{' << x << ',' << y << ',' << z << '}';
232 }
233 constexpr void _setFromList(std::initializer_list<T> v)
234 {
235 auto s = v.size();
236 auto ptr = v.begin();
237 if (s > 0)
238 x = *ptr;
239 ++ptr;
240 if (s > 1)
241 y = *ptr;
242 ++ptr;
243 if (s > 2)
244 z = *ptr;
245 }
246};
247
248/*---------------------------------------------------------------------------*/
249/*---------------------------------------------------------------------------*/
250
251} // namespace Arcane
252
253/*---------------------------------------------------------------------------*/
254/*---------------------------------------------------------------------------*/
255
256#endif
Déclarations des types utilisés dans Arcane.
Classe gérant un vecteur de dimension 3 de type T.
Definition Vector3.h:38
constexpr __host__ __device__ void operator-=(const T &b)
Soustrait b de l'instance.
Definition Vector3.h:144
friend std::ostream & operator<<(std::ostream &o, const Vector3< T > &t)
Ecrit le triplet t sur le flot o.
Definition Vector3.h:107
constexpr Vector3(std::initializer_list< T > v)
Construit l'instance avec la liste v.
Definition Vector3.h:80
friend constexpr __host__ __device__ ThatClass operator/(const ThatClass &a, const T &b)
Divise chaque composante de a par b.
Definition Vector3.h:222
friend constexpr __host__ __device__ ThatClass operator*(const T &a, const ThatClass &b)
Multiplie chaque composante de b par a.
Definition Vector3.h:210
constexpr __host__ __device__ void operator/=(const T &b)
Divise chaque composante de l'instance par b.
Definition Vector3.h:168
constexpr __host__ __device__ void operator*=(const T &b)
Multiplie chaque composante de l'instance par b.
Definition Vector3.h:160
constexpr __host__ __device__ Vector3(const T &ax, const T &ay, const T &az)
Construit le triplet (ax,ay,az).
Definition Vector3.h:56
constexpr Vector3(const std::array< T, 3 > &v)
Construit l'instance avec le tableau v.
Definition Vector3.h:72
friend constexpr __host__ __device__ ThatClass operator-(const ThatClass &a, const ThatClass &b)
Soustrait chaque composante de a par chaque composante de b.
Definition Vector3.h:194
constexpr __host__ __device__ ThatClass operator-() const
Retourne l'opposé de l'instance.
Definition Vector3.h:206
friend constexpr __host__ __device__ ThatClass operator+(const T &a, const ThatClass &b)
Retourne b en ajoutant a à chaque composante.
Definition Vector3.h:188
constexpr __host__ __device__ void operator-=(const ThatClass &b)
Soustrait b de l'instance.
Definition Vector3.h:152
constexpr Vector3 & operator=(std::initializer_list< T > v)
Positionne l'instance avec la liste v.
Definition Vector3.h:86
friend constexpr __host__ __device__ ThatClass operator*(const ThatClass &a, const T &b)
Multiplie chaque composante de a par b.
Definition Vector3.h:216
friend constexpr __host__ __device__ ThatClass operator+(const ThatClass &a, const T &b)
Retourne a en ajoutant b à chaque composante.
Definition Vector3.h:182
constexpr __host__ __device__ void operator+=(const ThatClass &b)
Ajoute b à l'instance.
Definition Vector3.h:136
constexpr __host__ __device__ void operator+=(const T &b)
Ajoute b à l'instance.
Definition Vector3.h:128
Vector3()=default
Construit le vecteur nul.
constexpr __host__ __device__ Vector3(const T &v)
Construit l'instance avec le triplet (v,v,v).
Definition Vector3.h:64
friend constexpr __host__ __device__ ThatClass operator-(const ThatClass &a, const T &b)
Soustrait chaque composante de a par b.
Definition Vector3.h:200
friend constexpr __host__ __device__ ThatClass operator+(const ThatClass &a, const ThatClass &b)
Additionne composante par composante a et b.
Definition Vector3.h:176
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool operator<(const Item &item1, const Item &item2)
Compare deux entités.
Definition Item.h:551