From b82835520655fb66b49bd4cde8759f7ad3f6b8e1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 18 Jan 2022 02:40:16 +0000 Subject: [PATCH] A bit more angle cleanup. --- .../3d_rendering/opengl/opengl_utils.cpp | 10 ++++---- common/eda_rect.cpp | 4 ++-- eeschema/sch_bus_entry.cpp | 2 +- libs/kimath/include/geometry/convex_hull.h | 3 ++- libs/kimath/src/geometry/convex_hull.cpp | 4 ++-- pcbnew/autorouter/ar_matrix.cpp | 6 ++--- pcbnew/microwave/microwave_footprint.cpp | 24 +++++++++++-------- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/3d-viewer/3d_rendering/opengl/opengl_utils.cpp b/3d-viewer/3d_rendering/opengl/opengl_utils.cpp index f8930e3b0b..a1994fb62f 100644 --- a/3d-viewer/3d_rendering/opengl/opengl_utils.cpp +++ b/3d-viewer/3d_rendering/opengl/opengl_utils.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Mario Luzeiro - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -144,14 +144,14 @@ void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle ) if( aNrSidesPerCircle > 1 ) { const float radius = 0.5f; - const int delta = 3600 / aNrSidesPerCircle; + const EDA_ANGLE delta = ANGLE_360 / aNrSidesPerCircle; // Generate bottom glNormal3f( 0.0f, 0.0f,-1.0f ); glBegin( GL_TRIANGLE_FAN ); glVertex3f( 0.0, 0.0, 0.0 ); // This is the V0 of the FAN - for( int ii = 0; ii < 1800; ii += delta ) + for( EDA_ANGLE ii = ANGLE_0; ii < ANGLE_180; ii += delta ) { SFVEC2D corner = SFVEC2D( 0.0, radius ); RotatePoint( &corner.x, &corner.y, ii ); @@ -166,7 +166,7 @@ void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle ) glBegin( GL_TRIANGLE_FAN ); glVertex3f( 0.0, 0.0, 1.0 ); // This is the V0 of the FAN - for( int ii = 1800; ii > 0; ii -= delta ) + for( EDA_ANGLE ii = ANGLE_180; ii > ANGLE_0; ii -= delta ) { SFVEC2D corner = SFVEC2D( 0.0, radius ); @@ -180,7 +180,7 @@ void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle ) // Generate contours glBegin( GL_QUAD_STRIP ); - for( int ii = 1800; ii > 0; ii -= delta ) + for( EDA_ANGLE ii = ANGLE_180; ii > ANGLE_0; ii -= delta ) { SFVEC2D corner = SFVEC2D( 0.0, radius ); diff --git a/common/eda_rect.cpp b/common/eda_rect.cpp index c52225c148..5daefa9b10 100644 --- a/common/eda_rect.cpp +++ b/common/eda_rect.cpp @@ -242,7 +242,7 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c for( int i = 0; i < 4; i++ ) { VECTOR2I delta = corners[i] - rCentre; - RotatePoint( delta, -rotation ); + RotatePoint( delta, -EDA_ANGLE( rotation, TENTHS_OF_A_DEGREE_T ) ); delta += rCentre; if( aRect.Contains( delta ) ) @@ -262,7 +262,7 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c // Rotate and test each corner for( int j = 0; j < 4; j++ ) { - RotatePoint( corners[j], rotation ); + RotatePoint( corners[j], EDA_ANGLE( rotation, TENTHS_OF_A_DEGREE_T ) ); corners[j] += rCentre; if( Contains( corners[j] ) ) diff --git a/eeschema/sch_bus_entry.cpp b/eeschema/sch_bus_entry.cpp index e0e0720e06..fc0382c4f5 100644 --- a/eeschema/sch_bus_entry.cpp +++ b/eeschema/sch_bus_entry.cpp @@ -307,7 +307,7 @@ void SCH_BUS_ENTRY_BASE::MirrorHorizontally( int aCenter ) void SCH_BUS_ENTRY_BASE::Rotate( const VECTOR2I& aCenter ) { - RotatePoint( m_pos, aCenter, 900 ); + RotatePoint( m_pos, aCenter, ANGLE_90 ); RotatePoint( &m_size.x, &m_size.y, ANGLE_90 ); } diff --git a/libs/kimath/include/geometry/convex_hull.h b/libs/kimath/include/geometry/convex_hull.h index 9943334eb5..cfebc2dd5a 100644 --- a/libs/kimath/include/geometry/convex_hull.h +++ b/libs/kimath/include/geometry/convex_hull.h @@ -28,6 +28,7 @@ #include #include +#include class SHAPE_POLY_SET; @@ -57,6 +58,6 @@ void BuildConvexHull( std::vector& aResult, const SHAPE_POLY_SET& aPol * @param aRotation is the rotation of the convex hull. */ void BuildConvexHull( std::vector& aResult, const SHAPE_POLY_SET& aPolygons, - const VECTOR2I& aPosition, double aRotation ); + const VECTOR2I& aPosition, const EDA_ANGLE& aRotation ); #endif // __CONVEX_HULL_H diff --git a/libs/kimath/src/geometry/convex_hull.cpp b/libs/kimath/src/geometry/convex_hull.cpp index 1c21e36f43..51a528ebab 100644 --- a/libs/kimath/src/geometry/convex_hull.cpp +++ b/libs/kimath/src/geometry/convex_hull.cpp @@ -133,12 +133,12 @@ void BuildConvexHull( std::vector& aResult, const std::vector& aResult, const SHAPE_POLY_SET& aPolygons ) { - BuildConvexHull( aResult, aPolygons, VECTOR2I( 0, 0 ), 0.0 ); + BuildConvexHull( aResult, aPolygons, VECTOR2I( 0, 0 ), ANGLE_0 ); } void BuildConvexHull( std::vector& aResult, const SHAPE_POLY_SET& aPolygons, - const VECTOR2I& aPosition, double aRotation ) + const VECTOR2I& aPosition, const EDA_ANGLE& aRotation ) { // Build the convex hull of the SHAPE_POLY_SET std::vector buf; diff --git a/pcbnew/autorouter/ar_matrix.cpp b/pcbnew/autorouter/ar_matrix.cpp index 8464e6c047..2e66a445c3 100644 --- a/pcbnew/autorouter/ar_matrix.cpp +++ b/pcbnew/autorouter/ar_matrix.cpp @@ -622,7 +622,7 @@ void AR_MATRIX::traceArc( int ux0, int uy0, int ux1, int uy1, double ArcAngle, i void AR_MATRIX::TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, double angle, - LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic ) + LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic ) { int row, col; int cx, cy; // Center of rectangle @@ -685,7 +685,7 @@ void AR_MATRIX::TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, double { rotrow = row * m_GridRouting; rotcol = col * m_GridRouting; - RotatePoint( &rotcol, &rotrow, cx, cy, -angle ); + RotatePoint( &rotcol, &rotrow, cx, cy, -EDA_ANGLE( angle, TENTHS_OF_A_DEGREE_T ) ); if( rotrow <= uy0 ) continue; @@ -710,7 +710,7 @@ void AR_MATRIX::TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, double void AR_MATRIX::TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, LSET aLayerMask, - int color, AR_MATRIX::CELL_OP op_logic ) + int color, AR_MATRIX::CELL_OP op_logic ) { int row, col; int row_min, row_max, col_min, col_max; diff --git a/pcbnew/microwave/microwave_footprint.cpp b/pcbnew/microwave/microwave_footprint.cpp index 740dcdd10e..5850915478 100644 --- a/pcbnew/microwave/microwave_footprint.cpp +++ b/pcbnew/microwave/microwave_footprint.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -39,7 +39,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint wxString msg; wxString cmp_name; int pad_count = 2; - int angle = 0; + EDA_ANGLE angle = ANGLE_0; PCB_EDIT_FRAME& editFrame = *getEditFrame(); @@ -89,8 +89,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC ) { - double fcoeff = 10.0, fval; - msg.Printf( wxT( "%3.1f" ), angle / fcoeff ); + msg = wxT( "0.0" ); WX_TEXT_ENTRY_DIALOG angledlg( &editFrame, _( "Angle in degrees:" ), _( "Create Microwave Footprint" ), msg ); @@ -99,16 +98,21 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint msg = angledlg.GetValue(); + double fval; + if( !msg.ToDouble( &fval ) ) { DisplayError( &editFrame, _( "Incorrect number, abort" ) ); abort = true; } - angle = std::abs( KiROUND( fval * fcoeff ) ); + angle = EDA_ANGLE( fval, DEGREES_T ); - if( angle > 1800 ) - angle = 1800; + if( angle < ANGLE_0 ) + angle = -angle; + + if( angle > ANGLE_180 ) + angle = ANGLE_180; } if( abort ) @@ -145,13 +149,13 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint pad->SetShape( PAD_SHAPE::CUSTOM ); pad->SetAnchorPadShape( PAD_SHAPE::RECT ); - int numPoints = ( angle / 50 ) + 3; // Note: angles are in 0.1 degrees + int numPoints = ( angle.AsDegrees() / 5.0 ) + 3; std::vector polyPoints; polyPoints.reserve( numPoints ); polyPoints.emplace_back( wxPoint( 0, 0 ) ); - int theta = -angle / 2; + EDA_ANGLE theta = -angle / 2; for( int ii = 1; ii < numPoints - 1; ii++ ) { @@ -159,7 +163,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint RotatePoint( &pt.x, &pt.y, theta ); polyPoints.push_back( pt ); - theta += 50; + theta += EDA_ANGLE( 5.0, DEGREES_T ); if( theta > angle / 2 ) theta = angle / 2;