Prefer EDA_ANGLE to naked radians.

This commit is contained in:
Jeff Young 2022-01-20 18:10:14 +00:00
parent 854987f663
commit 4a05b36bc6
4 changed files with 46 additions and 35 deletions

View File

@ -35,6 +35,7 @@
#include <gal/definitions.h> #include <gal/definitions.h>
#include <geometry/shape_poly_set.h> #include <geometry/shape_poly_set.h>
#include <math/util.h> // for KiROUND #include <math/util.h> // for KiROUND
#include <trigo.h>
#include <bitmap_base.h> #include <bitmap_base.h>
#include <algorithm> #include <algorithm>
@ -390,8 +391,10 @@ void CAIRO_GAL_BASE::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadiu
VECTOR2D mid = roundp( xform( aCenterPoint ) ); VECTOR2D mid = roundp( xform( aCenterPoint ) );
double width = xform( aWidth / 2.0 ); double width = xform( aWidth / 2.0 );
VECTOR2D startPointS = VECTOR2D( r, 0.0 ).Rotate( startAngleS ); VECTOR2D startPointS = VECTOR2D( r, 0.0 );
VECTOR2D endPointS = VECTOR2D( r, 0.0 ).Rotate( endAngleS ); VECTOR2D endPointS = VECTOR2D( r, 0.0 );
RotatePoint( startPointS, -EDA_ANGLE( startAngleS, RADIANS_T ) );
RotatePoint( endPointS, -EDA_ANGLE( endAngleS, RADIANS_T ) );
cairo_save( m_currentContext ); cairo_save( m_currentContext );

View File

@ -72,7 +72,7 @@ static void drawCursorStrings( KIGFX::VIEW* aView, const VECTOR2D& aCursor,
cursorStrings.push_back( DimensionLabel( "r", aRulerVec.EuclideanNorm(), aUnits ) ); cursorStrings.push_back( DimensionLabel( "r", aRulerVec.EuclideanNorm(), aUnits ) );
EDA_ANGLE angle( -aRulerVec.Angle(), RADIANS_T ); EDA_ANGLE angle = -EDA_ANGLE( aRulerVec );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), angle.AsDegrees(), cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), angle.AsDegrees(),
EDA_UNITS::DEGREES ) ); EDA_UNITS::DEGREES ) );
@ -152,17 +152,19 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT
{ {
KIGFX::GAL* gal = aView->GetGAL(); KIGFX::GAL* gal = aView->GetGAL();
KIFONT::FONT* font = KIFONT::FONT::GetFont(); KIFONT::FONT* font = KIFONT::FONT::GetFont();
VECTOR2D tickLine = aLine.Rotate( -M_PI_2 );
double tickSpace; double tickSpace;
TICK_FORMAT tickFormat = getTickFormatForScale( gal->GetWorldScale(), tickSpace, aUnits ); TICK_FORMAT tickFormat = getTickFormatForScale( gal->GetWorldScale(), tickSpace, aUnits );
double majorTickLen = aMinorTickLen * ( majorTickLengthFactor + 1 ); double majorTickLen = aMinorTickLen * ( majorTickLengthFactor + 1 );
VECTOR2D tickLine = aLine;
RotatePoint( tickLine, ANGLE_90 );
// number of ticks in whole ruler // number of ticks in whole ruler
int numTicks = (int) std::ceil( aLine.EuclideanNorm() / tickSpace ); int numTicks = (int) std::ceil( aLine.EuclideanNorm() / tickSpace );
// work out which way up the tick labels go // work out which way up the tick labels go
TEXT_DIMS labelDims = GetConstantGlyphHeight( gal, -1 ); TEXT_DIMS labelDims = GetConstantGlyphHeight( gal, -1 );
double labelAngle = -tickLine.Angle(); EDA_ANGLE labelAngle = - EDA_ANGLE( tickLine );
VECTOR2I labelOffset = tickLine.Resize( majorTickLen ); VECTOR2I labelOffset = tickLine.Resize( majorTickLen );
if( aDrawingDropShadows ) if( aDrawingDropShadows )
@ -178,15 +180,15 @@ void drawTicksAlongLine( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECT
labelAttrs.m_Size = labelDims.GlyphSize; labelAttrs.m_Size = labelDims.GlyphSize;
labelAttrs.m_StrokeWidth = labelDims.StrokeWidth; labelAttrs.m_StrokeWidth = labelDims.StrokeWidth;
if( aLine.Angle() > 0 ) if( EDA_ANGLE( aLine ) > ANGLE_0 )
{ {
labelAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT; labelAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
labelAttrs.m_Angle = EDA_ANGLE( labelAngle, RADIANS_T ); labelAttrs.m_Angle = labelAngle;
} }
else else
{ {
labelAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT; labelAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT;
labelAttrs.m_Angle = EDA_ANGLE( labelAngle + M_PI, RADIANS_T ); labelAttrs.m_Angle = labelAngle + ANGLE_180;
} }
BOX2D viewportD = aView->GetViewport(); BOX2D viewportD = aView->GetViewport();
@ -242,9 +244,12 @@ void drawBacksideTicks( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTO
double aTickLen, int aNumDivisions, bool aDrawingDropShadows ) double aTickLen, int aNumDivisions, bool aDrawingDropShadows )
{ {
KIGFX::GAL* gal = aView->GetGAL(); KIGFX::GAL* gal = aView->GetGAL();
const double backTickSpace = aLine.EuclideanNorm() / aNumDivisions;
const VECTOR2D backTickVec = aLine.Rotate( M_PI_2 ).Resize( aTickLen );
TEXT_DIMS textDims = GetConstantGlyphHeight( gal, -1 ); TEXT_DIMS textDims = GetConstantGlyphHeight( gal, -1 );
const double backTickSpace = aLine.EuclideanNorm() / aNumDivisions;
VECTOR2D backTickVec = aLine;
RotatePoint( backTickVec, -ANGLE_90 );
backTickVec.Resize( aTickLen );
BOX2D viewportD = aView->GetViewport(); BOX2D viewportD = aView->GetViewport();
BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) ); BOX2I viewport( VECTOR2I( viewportD.GetPosition() ), VECTOR2I( viewportD.GetSize() ) );

View File

@ -63,6 +63,7 @@
#include <math/util.h> // for KiROUND #include <math/util.h> // for KiROUND
#include <trigo.h> // for RotatePoint
#include <gerbview.h> #include <gerbview.h>
#include <gerbview_frame.h> #include <gerbview_frame.h>
@ -109,38 +110,39 @@ static VECTOR2I computeCenter( VECTOR2I aStart, VECTOR2I aEnd, int& aRadius, boo
* the Y center positions are on the vertical line starting at end.x/2, 0 * the Y center positions are on the vertical line starting at end.x/2, 0
* and solve aRadius^2 = X^2 + Y^2 (2 values) * and solve aRadius^2 = X^2 + Y^2 (2 values)
*/ */
double seg_angle = end.Angle(); //in radian EDA_ANGLE seg_angle( end );
VECTOR2D h_segm = end.Rotate( - seg_angle ); VECTOR2D h_segm = end;
RotatePoint( h_segm, seg_angle );
double cX = h_segm.x/2; double cX = h_segm.x/2;
double cY1 = sqrt( (double)aRadius*aRadius - cX*cX ); double cY1 = sqrt( (double)aRadius*aRadius - cX*cX );
double cY2 = -cY1; double cY2 = -cY1;
VECTOR2D center1( cX, cY1 ); VECTOR2D center1( cX, cY1 );
center1 = center1.Rotate( seg_angle ); RotatePoint( center1, -seg_angle );
double arc_angle1 = (end - center1).Angle() - (VECTOR2D(0.0,0.0) - center1).Angle(); EDA_ANGLE arc_angle1 = EDA_ANGLE( end - center1 ) - EDA_ANGLE( VECTOR2D( 0.0, 0.0 ) - center1 );
VECTOR2D center2( cX, cY2 ); VECTOR2D center2( cX, cY2 );
center2 = center2.Rotate( seg_angle ); RotatePoint( center2, -seg_angle );
double arc_angle2 = (end - center2).Angle() - (VECTOR2D(0.0,0.0) - center2).Angle(); EDA_ANGLE arc_angle2 = EDA_ANGLE( end - center2 ) - EDA_ANGLE( VECTOR2D( 0.0, 0.0 ) - center2 );
if( !aRotCCW ) if( !aRotCCW )
{ {
if( arc_angle1 < 0.0 ) if( arc_angle1 < ANGLE_0 )
arc_angle1 += 2*M_PI; arc_angle1 += ANGLE_360;
if( arc_angle2 < 0.0 ) if( arc_angle2 < ANGLE_0 )
arc_angle2 += 2*M_PI; arc_angle2 += ANGLE_360;
} }
else else
{ {
if( arc_angle1 > 0.0 ) if( arc_angle1 > ANGLE_0 )
arc_angle1 -= 2*M_PI; arc_angle1 -= ANGLE_360;
if( arc_angle2 > 0.0 ) if( arc_angle2 > ANGLE_0 )
arc_angle2 -= 2*M_PI; arc_angle2 -= ANGLE_360;
} }
// Arc angle must be <= 180.0 degrees. // Arc angle must be <= 180.0 degrees.
// So choose the center that create a arc angle <= 180.0 // So choose the center that create a arc angle <= 180.0
if( std::abs( arc_angle1 ) <= M_PI ) if( std::abs( arc_angle1 ) <= ANGLE_180 )
{ {
center.x = KiROUND( center1.x ); center.x = KiROUND( center1.x );
center.y = KiROUND( center1.y ); center.y = KiROUND( center1.y );

View File

@ -1415,8 +1415,9 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadDimensions()
} }
else else
{ {
double angle = crossbarVector.Angle() + ( M_PI / 2 ); EDA_ANGLE angle( crossbarVector );
height = heightVector.x * cos( angle ) + heightVector.y * sin( angle ); angle += ANGLE_90;
height = heightVector.x * angle.Cos() + heightVector.y * angle.Sin();
} }
dimension->SetHeight( height ); dimension->SetHeight( height );