Skip to content

Commit

Permalink
Coding - Reorganize code with constexpr Open-Cascade-SAS#85
Browse files Browse the repository at this point in the history
Continue rework Precision.hxx and Standard type definitions
  • Loading branch information
dpasukhi committed Sep 30, 2024
1 parent 5cc7cbe commit e83a646
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 46 deletions.
14 changes: 7 additions & 7 deletions src/Precision/Precision.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public:
//! length of the tangent of the curve or the surface.
//!
//! Value is P / T
static inline Standard_Real Parametric (const Standard_Real P, const Standard_Real T) { return P / T; }
static constexpr Standard_Real Parametric (const Standard_Real P, const Standard_Real T) { return P / T; }

//! Returns a precision value in parametric space, which may be used :
//! - to test the coincidence of two points in the real space,
Expand Down Expand Up @@ -256,7 +256,7 @@ public:
//! 2.Pi without impacting on the resulting point.
//! Therefore, take great care when adjusting a parametric
//! tolerance to your own algorithm.
static inline Standard_Real PConfusion (const Standard_Real T) { return Parametric (Confusion(), T); }
static constexpr Standard_Real PConfusion (const Standard_Real T) { return Parametric (Confusion(), T); }

//! Returns square of PConfusion.
//! Created for speed and convenience.
Expand All @@ -275,7 +275,7 @@ public:
//! segment whose length is equal to 100. (default value), or T.
//! The parametric tolerance of intersection is equal to :
//! - Precision::Intersection() / 100., or Precision::Intersection() / T.
static inline Standard_Real PIntersection (const Standard_Real T) { return Parametric(Intersection(),T); }
static constexpr Standard_Real PIntersection (const Standard_Real T) { return Parametric(Intersection(),T); }

//! Returns a precision value in parametric space, which may
//! be used by approximation algorithms. The purpose of this
Expand All @@ -290,13 +290,13 @@ public:
//! segment whose length is equal to 100. (default value), or T.
//! The parametric tolerance of intersection is equal to :
//! - Precision::Approximation() / 100., or Precision::Approximation() / T.
static inline Standard_Real PApproximation (const Standard_Real T) { return Parametric(Approximation(),T); }
static constexpr Standard_Real PApproximation (const Standard_Real T) { return Parametric(Approximation(),T); }

//! Convert a real space precision to a parametric
//! space precision on a default curve.
//!
//! Value is Parametric(P,1.e+2)
static inline Standard_Real Parametric (const Standard_Real P) { return P * 0.01; }
static constexpr Standard_Real Parametric (const Standard_Real P) { return P * 0.01; }

//! Used to test distances in parametric space on a
//! default curve.
Expand All @@ -322,11 +322,11 @@ public:

//! Returns True if R may be considered as a positive
//! infinite number. Currently R > 1e100
static inline Standard_Boolean IsPositiveInfinite (const Standard_Real R) { return R >= (0.5 * Precision::Infinite()); }
static constexpr Standard_Boolean IsPositiveInfinite (const Standard_Real R) { return R >= (0.5 * Precision::Infinite()); }

//! Returns True if R may be considered as a negative
//! infinite number. Currently R < -1e100
static inline Standard_Boolean IsNegativeInfinite (const Standard_Real R) { return R <= -(0.5 * Precision::Infinite()); }
static constexpr Standard_Boolean IsNegativeInfinite (const Standard_Real R) { return R <= -(0.5 * Precision::Infinite()); }

//! Returns a big number that can be considered as
//! infinite. Use -Infinite() for a negative big number.
Expand Down
4 changes: 2 additions & 2 deletions src/Standard/Standard_Character.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
// ------------------------------------------------------------------
// IsEqual : Returns Standard_True if two characters have the same value
// ------------------------------------------------------------------
inline Standard_Boolean IsEqual(const Standard_Character One,
const Standard_Character Two)
constexpr Standard_Boolean IsEqual(const Standard_Character One,
const Standard_Character Two)
{ return One == Two; }

// ===============================================
Expand Down
14 changes: 7 additions & 7 deletions src/Standard/Standard_Integer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@
// ------------------------------------------------------------------
// Abs : Returns the absolute value of an Integer
// ------------------------------------------------------------------
inline Standard_Integer Abs (const Standard_Integer Value)
constexpr Standard_Integer Abs (const Standard_Integer Value)
{
return Value >= 0 ? Value : -Value;
}

// ------------------------------------------------------------------
// IsEven : Returns Standard_True if an integer is even
// ------------------------------------------------------------------
inline Standard_Boolean IsEven (const Standard_Integer Value)
constexpr Standard_Boolean IsEven (const Standard_Integer Value)
{ return Value % 2 == 0; }


// ------------------------------------------------------------------
// IsOdd : Returns Standard_True if an integer is odd
// ------------------------------------------------------------------
inline Standard_Boolean IsOdd (const Standard_Integer Value)
constexpr Standard_Boolean IsOdd (const Standard_Integer Value)
{ return Value % 2 == 1; }

// ------------------------------------------------------------------
// Max : Returns the maximum integer between two integers
// ------------------------------------------------------------------
inline Standard_Integer Max (const Standard_Integer Val1,
constexpr Standard_Integer Max (const Standard_Integer Val1,
const Standard_Integer Val2)
{
return Val1 >= Val2 ? Val1 : Val2;
Expand All @@ -57,7 +57,7 @@ inline Standard_Integer Max (const Standard_Integer Val1,
// ------------------------------------------------------------------
// Min : Returns the minimum integer between two integers
// ------------------------------------------------------------------
inline Standard_Integer Min (const Standard_Integer Val1,
constexpr Standard_Integer Min (const Standard_Integer Val1,
const Standard_Integer Val2)
{
return Val1 <= Val2 ? Val1 : Val2;
Expand All @@ -66,14 +66,14 @@ inline Standard_Integer Min (const Standard_Integer Val1,
// ------------------------------------------------------------------
// Modulus : Returns the remainder of division between two integers
// ------------------------------------------------------------------
inline Standard_Integer Modulus (const Standard_Integer Value,
constexpr Standard_Integer Modulus (const Standard_Integer Value,
const Standard_Integer Divisor)
{ return Value % Divisor; }

// ------------------------------------------------------------------
// Square : Returns the square of an integer
// ------------------------------------------------------------------
inline Standard_Integer Square(const Standard_Integer Value)
constexpr Standard_Integer Square(const Standard_Integer Value)
{ return Value * Value; }

// ------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/Standard/Standard_Real.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ static int HardwareLowBitsOfDouble()
}
}

static int HighBitsOfDouble = HardwareHighBitsOfDouble();
static int LowBitsOfDouble = HardwareLowBitsOfDouble();
static const int HighBitsOfDouble = HardwareHighBitsOfDouble();
static const int LowBitsOfDouble = HardwareLowBitsOfDouble();

double NextAfter(const double x, const double y)
{
Expand Down
22 changes: 8 additions & 14 deletions src/Standard/Standard_Real.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,10 @@ inline Standard_Real Cos (const Standard_Real Value)
// If 'Value' is 0 then returns minimal positive value
// of Standard_Real type.
//-------------------------------------------------------------------
inline Standard_Real Epsilon (const Standard_Real Value)
inline Standard_Real Epsilon (const Standard_Real Value)
{
Standard_Real aEpsilon;

if (Value>=0.0){
aEpsilon = NextAfter(Value, RealLast()) - Value;
} else {
aEpsilon = Value - NextAfter(Value, RealFirst());
}
return aEpsilon;
return Value >= 0.0 ? (NextAfter(Value, RealLast()) - Value)
: (Value - NextAfter(Value, RealFirst()));
}

//-------------------------------------------------------------------
Expand Down Expand Up @@ -222,7 +216,7 @@ inline Standard_Real Log10 (const Standard_Real Value)
//-------------------------------------------------------------------
// Max : Returns the maximum value of two reals
//-------------------------------------------------------------------
inline Standard_Real Max (const Standard_Real Val1,
constexpr Standard_Real Max (const Standard_Real Val1,
const Standard_Real Val2)
{
return Val1 >= Val2 ? Val1 : Val2;
Expand All @@ -231,7 +225,7 @@ inline Standard_Real Max (const Standard_Real Val1,
//-------------------------------------------------------------------
// Min : Returns the minimum value of two reals
//-------------------------------------------------------------------
inline Standard_Real Min (const Standard_Real Val1,
constexpr Standard_Real Min (const Standard_Real Val1,
const Standard_Real Val2)
{
return Val1 <= Val2 ? Val1 : Val2;
Expand All @@ -254,7 +248,7 @@ inline Standard_Real RealPart (const Standard_Real Value)
// If input value is out of valid range for integers,
// minimal or maximal possible integer is returned.
//-------------------------------------------------------------------
inline Standard_Integer RealToInt (const Standard_Real theValue)
constexpr Standard_Integer RealToInt (const Standard_Real theValue)
{
// Note that on WNT under MS VC++ 8.0 conversion of double value less
// than INT_MIN or greater than INT_MAX to integer will cause signal
Expand All @@ -273,7 +267,7 @@ inline Standard_Integer RealToInt (const Standard_Real theValue)
// for Standard_ShortReal, minimal or maximal
// Standard_ShortReal is returned.
// =======================================================================
inline Standard_ShortReal RealToShortReal (const Standard_Real theVal)
constexpr Standard_ShortReal RealToShortReal (const Standard_Real theVal)
{
return theVal < -FLT_MAX ? -FLT_MAX
: theVal > FLT_MAX ? FLT_MAX
Expand Down Expand Up @@ -306,7 +300,7 @@ inline Standard_Real ASinh(const Standard_Real Value)
//-------------------------------------------------------------------
// Square : Returns a real to the power 2
//-------------------------------------------------------------------
inline Standard_Real Square(const Standard_Real Value)
constexpr Standard_Real Square(const Standard_Real Value)
{ return Value * Value; }

//-------------------------------------------------------------------
Expand Down
20 changes: 6 additions & 14 deletions src/Standard/Standard_ShortReal.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,19 @@ constexpr Standard_Integer ShortRealSize()
//-------------------------------------------------------------------
// Max : Returns the maximum value of two ShortReals
//-------------------------------------------------------------------
inline Standard_ShortReal Max (const Standard_ShortReal Val1,
const Standard_ShortReal Val2)
constexpr Standard_ShortReal Max(const Standard_ShortReal Val1,
const Standard_ShortReal Val2)
{
if (Val1 >= Val2) {
return Val1;
} else {
return Val2;
}
return Val1 >= Val2 ? Val1 : Val2;
}

//-------------------------------------------------------------------
// Min : Returns the minimum value of two ShortReals
//-------------------------------------------------------------------
inline Standard_ShortReal Min (const Standard_ShortReal Val1,
const Standard_ShortReal Val2)
constexpr Standard_ShortReal Min(const Standard_ShortReal Val1,
const Standard_ShortReal Val2)
{
if (Val1 <= Val2) {
return Val1;
} else {
return Val2;
}
return Val1 <= Val2 ? Val1 : Val2;
}

#endif
Expand Down

0 comments on commit e83a646

Please sign in to comment.