Skip to content

Commit

Permalink
Fix testImageCircle.cpp since introduction of (float)M_PI using M_PIf…
Browse files Browse the repository at this point in the history
… macro

- The arc angle corresponding to the part of the circle that is inside a roi could be negative
- Fix consists in adding 4*pi when negative
  • Loading branch information
fspindle committed Oct 27, 2023
1 parent bf36aa6 commit 2e3a5ab
Show file tree
Hide file tree
Showing 4 changed files with 324 additions and 317 deletions.
25 changes: 11 additions & 14 deletions modules/core/include/visp3/core/vpImageCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
*/

/*!
\file vpImageCircle.h
\brief Image circle, i.e. circle in the image space.
*/
* \file vpImageCircle.h
* \brief Image circle, i.e. circle in the image space.
*/

#ifndef _vpImageCircle_h_
#define _vpImageCircle_h_
Expand All @@ -50,8 +50,8 @@
#endif

/**
* \brief Class that defines a 2D circle in an image.
*/
* \brief Class that defines a 2D circle in an image.
*/
class VISP_EXPORT vpImageCircle
{
public:
Expand All @@ -72,28 +72,25 @@ class VISP_EXPORT vpImageCircle
vpImageCircle(const cv::Vec3f &vec);
#endif

/*!
* Default destructor.
*/
virtual ~vpImageCircle();

/*!
* Compute the angular coverage, in terms of radians, that is contained in the Region of Interest (RoI).
* \sa \ref vpImageCircle::computeArcLengthInRoI() "vpImageCircle::computeArcLengthInRoI(const vpRect &roi)"
* \sa computeArcLengthInRoI(), computeArcLengthInRoI(const vpRect &roi)
* \param[in] roi The rectangular RoI in which we want to know the number of pixels of the circle that are contained.
* \return Returns 2.f * M_PI for a circle that is fully visible in the RoI, or the sum of the angles of the arc(s) that is(are) visible in the RoI.
* \return Returns angular coverage of a circle in a ROI as an angle value in radians.
* More precisely, it returns 2.f * M_PI for a circle that is fully visible in the RoI, or the sum of the angles
* of the arc(s) that is(are) visible in the RoI.
*/
float computeAngularCoverageInRoI(const vpRect &roi) const;

/*!
* Compute the arc length, in terms of number of pixels, that is contained in the Region of Interest (RoI).
* \sa \ref vpImageCircle::computeAngularCoverageInRoI() "vpImageCircle::computeAngularCoverageInRoI(const vpRect &roi)"
* \sa computeAngularCoverageInRoI(), computeAngularCoverageInRoI(const vpRect &roi)
* \param[in] roi The rectangular RoI in which we want to know the number of pixels of the circle that are contained.
* \return The number of pixels of the circle that are contained in the RoI.
*/
float computeArcLengthInRoI(const vpRect &roi) const;

/*!
/*!
* Get the center of the image (2D) circle
* \return The center of the image (2D) circle.
*/
Expand Down
60 changes: 54 additions & 6 deletions modules/core/include/visp3/core/vpMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@

#endif

#endif

#ifndef M_PIf
#define M_PIf 3.14159265358979323846f
#endif

#ifndef M_PI_2f
#define M_PI_2f (M_PIf / 2.0f)
#endif

#ifndef M_PI_4f
#define M_PI_4f (M_PIf / 4.0f)

#include <visp3/core/vpException.h>
#include <visp3/core/vpImagePoint.h>

Expand All @@ -88,12 +101,11 @@ class vpRxyzVector;
class vpTranslationVector;

/*!
\class vpMath
\ingroup group_core_math_tools
\brief Provides simple mathematics computation tools that are not
available in the C mathematics library (math.h)
*/
* \class vpMath
* \ingroup group_core_math_tools
* \brief Provides simple mathematics computation tools that are not
* available in the C mathematics library (math.h)
*/
class VISP_EXPORT vpMath
{
public:
Expand All @@ -117,6 +129,42 @@ class VISP_EXPORT vpMath

static vpColVector rad(const vpColVector &r);

/*!
* Convert angle between \f$-\pi\f$ and \f$\pi\f$.
*
* \param[in] theta The input angle we want to ensure it is in the interval \f$[-\pi ; \pi]\f$.
* \return The corresponding angle in the interval \f$[-\pi ; \pi]\f$.
*/
static float getAngleBetweenMinPiAndPi(const float &theta)
{
float theta1 = theta;
if (theta1 > M_PIf) {
theta1 -= 2.0f * M_PIf;
}
else if (theta1 < -M_PIf) {
theta1 += 2.0f * M_PIf;
}
return theta1;
}

/*!
* Convert angle between \f$-\pi\f$ and \f$\pi\f$.
*
* \param[in] theta The input angle we want to ensure it is in the interval \f$[-\pi ; \pi]\f$.
* \return The corresponding angle in the interval \f$[-\pi ; \pi]\f$.
*/
static double getAngleBetweenMinPiAndPi(const double &theta)
{
double theta1 = theta;
if (theta1 > M_PI) {
theta1 -= 2.0 * M_PI;
}
else if (theta1 < -M_PI) {
theta1 += 2.0 * M_PI;
}
return theta1;
}

/*!
Compute x square value.
\return Square value \f$ x^2 \f$.
Expand Down
Loading

0 comments on commit 2e3a5ab

Please sign in to comment.