12#ifndef ARCANE_UTILS_REAL3_H
13#define ARCANE_UTILS_REAL3_H
17#include "arcane/utils/Numeric.h"
18#include "arcane/utils/Real2.h"
50 ARCCORE_CHECK_AT(i, 3);
65 ARCCORE_CHECK_AT(i, 3);
80 ARCCORE_CHECK_AT(i, 3);
95 ARCCORE_CHECK_AT(i, 3);
102 ARCCORE_CHECK_AT(i, 3);
136 constexpr ARCCORE_HOST_DEVICE
Real3()
202 constexpr ARCCORE_HOST_DEVICE
static Real3 null() {
return Real3(0., 0., 0.); }
203 constexpr ARCCORE_HOST_DEVICE
static Real3 zero() {
return Real3(0., 0., 0.); }
208 constexpr ARCCORE_HOST_DEVICE
Real3 copy()
const {
return (*
this); }
254 std::istream& assign(std::istream& i);
257 std::ostream& print(std::ostream& o)
const;
260 std::ostream& printXyz(std::ostream& o)
const;
386 return Real3(vec.
x * sca, vec.
y * sca, vec.
z * sca);
392 return Real3(vec.
x * sca, vec.
y * sca, vec.
z * sca);
398 return Real3(vec.
x / sca, vec.
y / sca, vec.
z / sca);
417 return (v1.
x < v2.
x);
440 return _eq(
x, b.
x) && _eq(
y, b.
y) && _eq(
z, b.
z);
459 inline ARCCORE_HOST_DEVICE
Real normL2()
const;
462 ARCCORE_DEPRECATED_2021(
"Use math::squareNormL2(const Real3&) instead")
463 constexpr ARCCORE_HOST_DEVICE
Real abs2()
const {
return x *
x +
y *
y +
z *
z; }
466 ARCCORE_DEPRECATED_2021(
"Use math::normL2(const Real3&) instead")
467 inline ARCCORE_HOST_DEVICE
Real abs() const;
470 inline constexpr ARCCORE_HOST_DEVICE
bool isNearlyZero() const;
473 inline
Real3& normalize();
482 inline constexpr ARCCORE_HOST_DEVICE static
bool _eq(
Real a,
Real b);
485 inline ARCCORE_HOST_DEVICE static
Real _sqrt(
Real a);
491inline constexpr ARCCORE_HOST_DEVICE
Real2::
507 return v.
x * v.
x + v.
y * v.
y + v.
z * v.
z;
516 inline constexpr ARCCORE_HOST_DEVICE
bool isNearlyZero(
const Real3& v)
518 return math::isNearlyZero(v.
x) && math::isNearlyZero(v.
y) && math::isNearlyZero(v.
z);
536 Real d = math::normL2(v);
550 Real d = math::normL2(v);
563 return math::mutableNormalize(*
this);
566inline constexpr ARCCORE_HOST_DEVICE
bool Real3::
569 return math::isNearlyZero(*
this);
572inline constexpr ARCCORE_HOST_DEVICE
bool Real3::
575 return math::isEqual(a, b);
578ARCCORE_HOST_DEVICE
inline Real Real3::
581 return math::sqrt(a);
584inline ARCCORE_HOST_DEVICE
Real Real3::
587 return math::normL2(*
this);
590inline ARCCORE_HOST_DEVICE
Real Real3::
593 return math::normL2(*
this);
Modifiable view of an array of type T.
Constant view of an array of type T.
Class managing a 2-dimensional real vector.
constexpr __host__ __device__ Real2()
Constructs the zero vector.
Class managing a 3-dimensional real vector.
constexpr __host__ __device__ void operator*=(Real b)
Multiplies each component of the triplet by the real number b.
Real3(const Real3 &f)=default
Constructs a triplet identical to f.
friend constexpr __host__ __device__ Real3 operator/(Real3 vec, Real sca)
Division by a scalar.
Real3 & operator=(const Real3 &f)=default
Copy assignment operator.
constexpr __host__ __device__ Real3 & operator/=(Real3 b)
Divides each component of the triplet by the corresponding component of b.
constexpr __host__ __device__ Real3 operator*(Real3 b) const
Creates a triplet that equals this triplet whose each component has been multiplied by the correspond...
constexpr __host__ __device__ Real3(Real ax, Real ay, Real az)
Constructs the triplet (ax,ay,az).
constexpr __host__ __device__ ArrayView< Real > view()
Returns a view of the three elements of the vector.
constexpr __host__ __device__ Real3 & subSame(Real b)
Subtracts b from each component of the triplet.
friend constexpr __host__ __device__ Real3 operator*(Real3 vec, Real sca)
Multiplication by a scalar.
constexpr __host__ __device__ Real3 operator-() const
Creates a triplet opposite to the current triplet.
constexpr __host__ __device__ Real3 operator+(Real3 b) const
Creates a triplet that equals this triplet added to b.
constexpr __host__ __device__ Real3 & operator*=(Real3 b)
Multiplies each component of the triplet by the corresponding component of b.
constexpr __host__ __device__ bool operator!=(Real3 b) const
Compares two triplets. For the notion of equality, see operator==().
constexpr __host__ __device__ Real3 operator/(Real3 b) const
Creates a triplet that equals this triplet whose each component has been divided by the corresponding...
constexpr __host__ __device__ bool operator==(Real3 b) const
Compares the current instance component by component to b.
constexpr __host__ __device__ Real3 & mulSame(Real b)
Multiplies each component of the triplet by b.
constexpr __host__ __device__ Real3 & operator=(Real v)
Assigns the triplet (v,v,v) to the instance.
constexpr __host__ __device__ Real3 & add(Real3 b)
Adds b to the triplet.
constexpr __host__ __device__ Real3(const Real3POD &f)
Constructs a triplet identical to f.
friend constexpr __host__ __device__ Real3 operator*(Real sca, Real3 vec)
Multiplication by a scalar.
constexpr __host__ __device__ Real3 & addSame(Real b)
Adds b to each component of the triplet.
constexpr __host__ __device__ Real3(Real v)
Constructs the instance with the triplet (v,v,v).
constexpr __host__ __device__ ConstArrayView< Real > constView() const
Returns a constant view of the three elements of the vector.
constexpr __host__ __device__ void operator/=(Real b)
Divides each component of the triplet by the real number b.
std::ostream & printXyz(std::ostream &o) const
Writes the triplet to the stream o in the form (x,y,z).
constexpr __host__ __device__ Real3 & operator-=(Real3 b)
Subtracts b from the triplet.
constexpr __host__ __device__ Real3(ConstArrayView< Real > av)
Constructs the triplet (av[0], av[1], av[2]).
friend constexpr __host__ __device__ bool operator<(Real3 v1, Real3 v2)
Comparison operator.
constexpr __host__ __device__ Real squareNormL2() const
Returns the square of the L2 norm of the triplet $ .
friend std::istream & operator>>(std::istream &i, Real3 &t)
Reads the triplet t from the stream o.
constexpr __host__ __device__ Real3(const Real2 &f)
Constructs a triplet identical to f.
constexpr __host__ __device__ Real3 copy() const
Returns a copy of the triplet.
constexpr __host__ __device__ Real3 & reset()
Resets the triplet using default constructors.
constexpr __host__ __device__ Real3 & divSame(Real b)
Divides each component of the triplet by b.
constexpr __host__ __device__ Real3()
Constructs the zero vector.
constexpr __host__ __device__ Real3 & sub(Real3 b)
Subtracts b from the triplet.
__host__ __device__ Real3 absolute() const
Absolute value component by component.
constexpr __host__ __device__ Real3 & operator+=(Real3 b)
Adds b to the triplet.
constexpr __host__ __device__ Real3 operator-(Real3 b) const
Creates a triplet that equals b subtracted from this triplet.
constexpr __host__ __device__ Real3 & div(Real3 b)
Divides each component of the triplet by the corresponding component of b.
constexpr __host__ __device__ Real3 & assign(Real ax, Real ay, Real az)
Assigns the triplet (ax,ay,az) to the instance.
constexpr __host__ __device__ Real abs2() const
Returns the square of the norm of the triplet $ .
constexpr __host__ __device__ Real3 & assign(Real3 f)
Copies the triplet f.
friend std::ostream & operator<<(std::ostream &o, Real3 t)
Writes the triplet t to the stream o.
constexpr __host__ __device__ Real3 & mul(Real3 b)
Multiplies each component of the triplet by the corresponding component of b.
Namespace for mathematical functions.
Real2 normalizeL2(const Real2 &v)
Returns the pair v normalized by the L2 norm.
constexpr __host__ __device__ Real squareNormL2(const Real2 &v)
Returns the squared norm of the pair $ .
__host__ __device__ double sqrt(double v)
Square root of v.
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
Real2 & mutableNormalize(Real2 &v)
Normalizes the pair.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
Real y
second component of the pair
Real x
first component of the pair
__host__ __device__ Real & operator()(Integer i)
__host__ __device__ Real operator[](Integer i) const
Real y
second component of the triplet
Real z
third component of the triplet
__host__ __device__ Real operator()(Integer i) const
__host__ __device__ void setComponent(Integer i, Real value)
Sets the i-th component to value.
__host__ __device__ Real & operator[](Integer i)
Real x
first component of the triplet