12#ifndef ARCANE_UTILS_REAL2_H
13#define ARCANE_UTILS_REAL2_H
17#include "arcane/utils/Numeric.h"
48 ARCCORE_CHECK_AT(i, 2);
63 ARCCORE_CHECK_AT(i, 2);
78 ARCCORE_CHECK_AT(i, 2);
93 ARCCORE_CHECK_AT(i, 2);
100 ARCCORE_CHECK_AT(i, 2);
126 constexpr ARCCORE_HOST_DEVICE
Real2()
157 inline constexpr ARCCORE_HOST_DEVICE
explicit Real2(
const Real3& v);
178 constexpr ARCCORE_HOST_DEVICE
static Real2 null() {
return Real2(0., 0.); }
183 constexpr ARCCORE_HOST_DEVICE
Real2 copy()
const {
return (*
this); }
227 std::istream& assign(std::istream& i);
230 std::ostream& print(std::ostream& o)
const;
233 std::ostream& printXy(std::ostream& o)
const;
349 return Real2(vec.
x * sca, vec.
y * sca);
355 return Real2(vec.
x * sca, vec.
y * sca);
361 return Real2(vec.
x / sca, vec.
y / sca);
375 return (v1.
x < v2.
x);
398 return _eq(
x, b.
x) && _eq(
y, b.
y);
416 ARCCORE_DEPRECATED_2021(
"Use math::squareNormL2(*this) instead")
420 ARCCORE_DEPRECATED_2021(
"Use math::normL2(*this) instead")
421 inline ARCCORE_HOST_DEVICE
Real abs() const;
430 inline constexpr ARCCORE_HOST_DEVICE
bool isNearlyZero() const;
434 ARCCORE_HOST_DEVICE
Real normL2() const;
444 inline
Real2& normalize();
453 constexpr ARCCORE_HOST_DEVICE static
bool _eq(
Real a,
Real b);
456 ARCCORE_HOST_DEVICE static
Real _sqrt(
Real a);
470 inline constexpr ARCCORE_HOST_DEVICE
bool isNearlyZero(
const Real2& v)
472 return math::isNearlyZero(v.
x) && math::isNearlyZero(v.
y);
478 return v.
x * v.
x + v.
y * v.
y;
496 Real d = math::normL2(v);
510 Real d = math::normL2(v);
520inline constexpr ARCCORE_HOST_DEVICE
bool Real2::
523 return math::isNearlyZero(*
this);
526inline constexpr ARCCORE_HOST_DEVICE
bool Real2::
532inline ARCCORE_HOST_DEVICE Real Real2::
535 return math::sqrt(a);
538inline ARCCORE_HOST_DEVICE
Real Real2::
541 return math::normL2(*
this);
550inline ARCCORE_HOST_DEVICE
Real Real2::
553 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 operator-() const
Creates a pair opposite to the current pair.
std::ostream & printXy(std::ostream &o) const
Writes the pair to stream o in the form (x,y).
constexpr __host__ __device__ Real2 & operator-=(Real2 b)
Subtracts b from the pair.
constexpr __host__ __device__ bool operator!=(Real2 b) const
Compares two pairs. For the concept of equality, see operator==().
constexpr __host__ __device__ Real2 & operator=(Real v)
Assigns the pair (v,v) to the instance.
constexpr __host__ __device__ Real squareNormL2() const
Returns the squared norm of the pair $ .
constexpr __host__ __device__ bool operator==(Real2 b) const
Compares the current instance component by component to b.
constexpr __host__ __device__ Real2 & addSame(Real b)
Adds b to each component of the pair.
friend std::ostream & operator<<(std::ostream &o, Real2 t)
Writes the pair t to the stream o.
constexpr __host__ __device__ Real2 & reset()
Resets the pair using default constructors.
constexpr __host__ __device__ Real2()
Constructs the zero vector.
friend std::istream & operator>>(std::istream &i, Real2 &t)
Reads the pair t from the stream o.
constexpr __host__ __device__ Real2 & operator/=(Real2 b)
Divides each component of the pair by the corresponding component of b.
__host__ __device__ Real2 absolute() const
Absolute value component by component.
constexpr __host__ __device__ Real2 & operator*=(Real2 b)
Multiplies each component of the pair by the corresponding component of b.
constexpr __host__ __device__ Real2 & sub(Real2 b)
Subtracts b from the pair.
constexpr __host__ __device__ Real2 operator*(Real2 b) const
Creates a pair that equals this pair, where each component has been multiplied by the corresponding c...
constexpr __host__ __device__ Real2(Real v)
Constructs the instance with the triplet (v,v,v).
constexpr __host__ __device__ Real2(ConstArrayView< Real > av)
Constructs the pair (av[0], av[1]).
constexpr __host__ __device__ Real2 & subSame(Real b)
Subtracts b from each component of the pair.
constexpr __host__ __device__ Real2 & assign(Real2 f)
Copies the pair f.
constexpr __host__ __device__ Real2 & div(Real2 b)
Divides each component of the pair by the corresponding component of b.
constexpr __host__ __device__ Real2 & mul(Real2 b)
Multiplies each component of the pair by the corresponding component of b.
constexpr __host__ __device__ ConstArrayView< Real > constView() const
Returns a constant view of the two elements of the vector.
constexpr __host__ __device__ Real2 & add(Real2 b)
Adds b to the pair.
constexpr __host__ __device__ ArrayView< Real > view()
Returns a view of the two elements of the vector.
constexpr __host__ __device__ Real2 operator/(Real2 b) const
Creates a pair that equals this pair, where each component has been divided by the corresponding comp...
friend constexpr __host__ __device__ Real2 operator*(Real sca, Real2 vec)
Multiplication by a scalar.
constexpr __host__ __device__ Real2 operator+(Real2 b) const
Creates a pair that equals this pair added to b.
constexpr __host__ __device__ Real2(const Real2POD &f)
Constructs a copy identical to f.
constexpr __host__ __device__ Real2 operator-(Real2 b) const
Creates a pair that equals b subtracted from this pair.
constexpr __host__ __device__ Real2 copy() const
Returns a copy of the pair.
constexpr __host__ __device__ void operator/=(Real b)
Divides each component of the pair by the real number b.
__host__ __device__ Real abs2() const
Returns the squared norm of the pair $ .
friend constexpr __host__ __device__ Real2 operator/(Real2 vec, Real sca)
Division by a scalar.
friend constexpr __host__ __device__ bool operator<(Real2 v1, Real2 v2)
Comparison operator.
constexpr __host__ __device__ Real2 & mulSame(Real b)
Multiplies each component of the pair by b.
constexpr __host__ __device__ Real2(Real ax, Real ay)
Constructs the pair (ax,ay).
constexpr __host__ __device__ Real2 & operator+=(Real2 b)
Adds b to the pair.
constexpr __host__ __device__ void operator*=(Real b)
Multiplies each component of the pair by the real number b.
constexpr __host__ __device__ Real2 & assign(Real ax, Real ay)
Assigns the triplet (ax,ay,az) to the instance.
constexpr __host__ __device__ Real2 & divSame(Real b)
Divides each component of the pair by b.
Real2(const Real2 &f)=default
Constructs a copy identical to f.
friend constexpr __host__ __device__ Real2 operator*(Real2 vec, Real sca)
Multiplication by a scalar.
Class managing a 3-dimensional real vector.
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.
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Tests the bit-by-bit equality between two values.
-- 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) const
__host__ __device__ void setComponent(Integer i, Real value)
Positions the i th component at value.
__host__ __device__ Real & operator()(Integer i)
__host__ __device__ Real operator()(Integer i) const
__host__ __device__ Real & operator[](Integer i)