7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-19 22:51:40 +00:00

Remove C macro in favor of class template

This commit is contained in:
Seth Hillbrand 2024-11-21 17:59:29 -08:00
parent d90f2842c8
commit 9e72d426db
4 changed files with 23 additions and 20 deletions

View File

@ -157,7 +157,7 @@ void CAIRO_GAL_BASE::arc_angles_xform_and_normalize( double& aStartAngle, double
}
// Normalize arc angles
SWAP( startAngle, >, endAngle );
normalize( startAngle, endAngle );
// now rotate arc according to the rotation transform matrix
// Remark:
@ -1778,9 +1778,9 @@ void CAIRO_GAL_BASE::DrawGrid()
int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
int gridEndY = KiROUND( ( worldEndPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
// Ensure start coordinate > end coordinate
SWAP( gridStartX, >, gridEndX );
SWAP( gridStartY, >, gridEndY );
// Ensure start coordinate < end coordinate
normalize( gridStartX, gridEndX );
normalize( gridStartY, gridEndY );
// Ensure the grid fills the screen
--gridStartX;

View File

@ -970,7 +970,7 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
double endAngle = startAngle + aAngle.AsRadians();
// Normalize arc angles
SWAP( startAngle, >, endAngle );
normalize( startAngle, endAngle );
const double alphaIncrement = calcAngleStep( aRadius );
@ -1058,7 +1058,7 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
double endAngle = startAngle + aAngle.AsRadians();
// Swap the angles, if start angle is greater than end angle
SWAP( startAngle, >, endAngle );
normalize( startAngle, endAngle );
// Calculate the seg count to approximate the arc with aMaxError or less
int segCount360 = GetArcToSegmentCount( aRadius, aMaxError, FULL_CIRCLE );
@ -1786,9 +1786,9 @@ void OPENGL_GAL::DrawGrid()
int gridStartY = KiROUND( ( worldStartPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
int gridEndY = KiROUND( ( worldEndPoint.y - m_gridOrigin.y ) / gridScreenSize.y );
// Ensure start coordinate > end coordinate
SWAP( gridStartX, >, gridEndX );
SWAP( gridStartY, >, gridEndY );
// Ensure start coordinate < end coordinate
normalize( gridStartX, gridEndX );
normalize( gridStartY, gridEndY );
// Ensure the grid fills the screen
--gridStartX;

View File

@ -27,17 +27,6 @@
#ifndef DEFINITIONS_H_
#define DEFINITIONS_H_
/// Swap the variables if a condition is met.
#define SWAP( varA, condition, varB ) \
assert( typeid( varA ).hash_code() == typeid( varB ).hash_code() ); \
\
if( varA condition varB ) \
{ \
decltype( varA ) tmp = varA; \
varA = varB; \
varB = tmp; \
}
namespace KIGFX
{
/**

View File

@ -1043,6 +1043,20 @@ protected:
*/
virtual bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions );
/**
* Ensure that the first element is smaller than the second
*/
template <typename T>
void normalize( T &a, T &b )
{
if( a > b )
{
T tmp = a;
a = b;
b = tmp;
}
}
GAL_DISPLAY_OPTIONS& m_options;
UTIL::LINK m_observerLink;