mathconst_p.h (2483B)
1 // This file is part of Blend2D project <https://blend2d.com> 2 // 3 // See blend2d.h or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 6 #ifndef BLEND2D_SUPPORT_MATHCONST_P_H_INCLUDED 7 #define BLEND2D_SUPPORT_MATHCONST_P_H_INCLUDED 8 9 #include "../api-internal_p.h" 10 11 //! \cond INTERNAL 12 //! \addtogroup blend2d_support 13 //! \{ 14 15 namespace bl { 16 namespace Math { 17 18 //! \name Math Constants 19 //! \{ 20 21 static constexpr double kPI = 3.14159265358979323846; //!< pi. 22 static constexpr double kPI_MUL_1p5 = 4.71238898038468985769; //!< pi * 1.5. 23 static constexpr double kPI_MUL_2 = 6.28318530717958647692; //!< pi * 2. 24 static constexpr double kPI_DIV_2 = 1.57079632679489661923; //!< pi / 2. 25 static constexpr double kPI_DIV_3 = 1.04719755119659774615; //!< pi / 3. 26 static constexpr double kPI_DIV_4 = 0.78539816339744830962; //!< pi / 4. 27 static constexpr double kSQRT_0p5 = 0.70710678118654746172; //!< sqrt(0.5). 28 static constexpr double kSQRT_2 = 1.41421356237309504880; //!< sqrt(2). 29 static constexpr double kSQRT_3 = 1.73205080756887729353; //!< sqrt(3). 30 31 static constexpr double kAfter0 = 1e-40; //!< Safe value after 0.0 for root finding/intervals. 32 static constexpr double kBefore1 = 0.999999999999999889; //!< Safe value before 1.0 for root finding/intervals. 33 34 static constexpr double kANGLE_EPSILON = 1e-8; 35 36 //! Constant that is used to approximate elliptic arcs with cubic curves. Since it's an approximation there are 37 //! various approaches that can be used to calculate the best value. The most used KAPPA is: 38 //! 39 //! k = (4/3) * (sqrt(2) - 1) ~= 0.55228474983 40 //! 41 //! which has a maximum error of 0.00027253. However, according to this post 42 //! 43 //! http://spencermortensen.com/articles/bezier-circle/ 44 //! 45 //! the maximum error can be further reduced by 28% if we change the approximation constraint to have the maximum 46 //! radial distance from the circle to the curve as small as possible. The an alternative constant 47 //! 48 //! k = 1/2 +- sqrt(12 - 20*c - 3*c^2)/(4 - 6*c) ~= 0.551915024494. 49 //! 50 //! can be used to reduce the maximum error to 0.00019608. We don't use the alternative, because we need to calculate 51 //! the KAPPA for arcs that are not 90deg, in that case the KAPPA must be calculated for such angles. 52 static constexpr double kKAPPA = 0.55228474983; 53 54 } // {Math} 55 } // {bl} 56 57 //! \} 58 //! \endcond 59 60 #endif // BLEND2D_SUPPORT_MATHCONST_P_H_INCLUDED