A bit more angle cleanup.

This commit is contained in:
Jeff Young 2022-01-18 02:40:16 +00:00
parent 8ea66ee06e
commit b828355206
7 changed files with 29 additions and 24 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -144,14 +144,14 @@ void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle )
if( aNrSidesPerCircle > 1 ) if( aNrSidesPerCircle > 1 )
{ {
const float radius = 0.5f; const float radius = 0.5f;
const int delta = 3600 / aNrSidesPerCircle; const EDA_ANGLE delta = ANGLE_360 / aNrSidesPerCircle;
// Generate bottom // Generate bottom
glNormal3f( 0.0f, 0.0f,-1.0f ); glNormal3f( 0.0f, 0.0f,-1.0f );
glBegin( GL_TRIANGLE_FAN ); glBegin( GL_TRIANGLE_FAN );
glVertex3f( 0.0, 0.0, 0.0 ); // This is the V0 of the 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 ); SFVEC2D corner = SFVEC2D( 0.0, radius );
RotatePoint( &corner.x, &corner.y, ii ); RotatePoint( &corner.x, &corner.y, ii );
@ -166,7 +166,7 @@ void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle )
glBegin( GL_TRIANGLE_FAN ); glBegin( GL_TRIANGLE_FAN );
glVertex3f( 0.0, 0.0, 1.0 ); // This is the V0 of the 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 ); SFVEC2D corner = SFVEC2D( 0.0, radius );
@ -180,7 +180,7 @@ void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle )
// Generate contours // Generate contours
glBegin( GL_QUAD_STRIP ); 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 ); SFVEC2D corner = SFVEC2D( 0.0, radius );

View File

@ -242,7 +242,7 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c
for( int i = 0; i < 4; i++ ) for( int i = 0; i < 4; i++ )
{ {
VECTOR2I delta = corners[i] - rCentre; VECTOR2I delta = corners[i] - rCentre;
RotatePoint( delta, -rotation ); RotatePoint( delta, -EDA_ANGLE( rotation, TENTHS_OF_A_DEGREE_T ) );
delta += rCentre; delta += rCentre;
if( aRect.Contains( delta ) ) 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 // Rotate and test each corner
for( int j = 0; j < 4; j++ ) 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; corners[j] += rCentre;
if( Contains( corners[j] ) ) if( Contains( corners[j] ) )

View File

@ -307,7 +307,7 @@ void SCH_BUS_ENTRY_BASE::MirrorHorizontally( int aCenter )
void SCH_BUS_ENTRY_BASE::Rotate( const VECTOR2I& 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 ); RotatePoint( &m_size.x, &m_size.y, ANGLE_90 );
} }

View File

@ -28,6 +28,7 @@
#include <vector> #include <vector>
#include <math/vector2d.h> #include <math/vector2d.h>
#include <geometry/eda_angle.h>
class SHAPE_POLY_SET; class SHAPE_POLY_SET;
@ -57,6 +58,6 @@ void BuildConvexHull( std::vector<VECTOR2I>& aResult, const SHAPE_POLY_SET& aPol
* @param aRotation is the rotation of the convex hull. * @param aRotation is the rotation of the convex hull.
*/ */
void BuildConvexHull( std::vector<VECTOR2I>& aResult, const SHAPE_POLY_SET& aPolygons, void BuildConvexHull( std::vector<VECTOR2I>& aResult, const SHAPE_POLY_SET& aPolygons,
const VECTOR2I& aPosition, double aRotation ); const VECTOR2I& aPosition, const EDA_ANGLE& aRotation );
#endif // __CONVEX_HULL_H #endif // __CONVEX_HULL_H

View File

@ -133,12 +133,12 @@ void BuildConvexHull( std::vector<VECTOR2I>& aResult, const std::vector<VECTOR2I
void BuildConvexHull( std::vector<VECTOR2I>& aResult, const SHAPE_POLY_SET& aPolygons ) void BuildConvexHull( std::vector<VECTOR2I>& 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<VECTOR2I>& aResult, const SHAPE_POLY_SET& aPolygons, void BuildConvexHull( std::vector<VECTOR2I>& 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 // Build the convex hull of the SHAPE_POLY_SET
std::vector<VECTOR2I> buf; std::vector<VECTOR2I> buf;

View File

@ -685,7 +685,7 @@ void AR_MATRIX::TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, double
{ {
rotrow = row * m_GridRouting; rotrow = row * m_GridRouting;
rotcol = col * 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 ) if( rotrow <= uy0 )
continue; continue;

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 msg;
wxString cmp_name; wxString cmp_name;
int pad_count = 2; int pad_count = 2;
int angle = 0; EDA_ANGLE angle = ANGLE_0;
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>(); PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
@ -89,8 +89,7 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC ) if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC )
{ {
double fcoeff = 10.0, fval; msg = wxT( "0.0" );
msg.Printf( wxT( "%3.1f" ), angle / fcoeff );
WX_TEXT_ENTRY_DIALOG angledlg( &editFrame, _( "Angle in degrees:" ), WX_TEXT_ENTRY_DIALOG angledlg( &editFrame, _( "Angle in degrees:" ),
_( "Create Microwave Footprint" ), msg ); _( "Create Microwave Footprint" ), msg );
@ -99,16 +98,21 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
msg = angledlg.GetValue(); msg = angledlg.GetValue();
double fval;
if( !msg.ToDouble( &fval ) ) if( !msg.ToDouble( &fval ) )
{ {
DisplayError( &editFrame, _( "Incorrect number, abort" ) ); DisplayError( &editFrame, _( "Incorrect number, abort" ) );
abort = true; abort = true;
} }
angle = std::abs( KiROUND( fval * fcoeff ) ); angle = EDA_ANGLE( fval, DEGREES_T );
if( angle > 1800 ) if( angle < ANGLE_0 )
angle = 1800; angle = -angle;
if( angle > ANGLE_180 )
angle = ANGLE_180;
} }
if( abort ) if( abort )
@ -145,13 +149,13 @@ FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprint
pad->SetShape( PAD_SHAPE::CUSTOM ); pad->SetShape( PAD_SHAPE::CUSTOM );
pad->SetAnchorPadShape( PAD_SHAPE::RECT ); 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<VECTOR2I> polyPoints; std::vector<VECTOR2I> polyPoints;
polyPoints.reserve( numPoints ); polyPoints.reserve( numPoints );
polyPoints.emplace_back( wxPoint( 0, 0 ) ); polyPoints.emplace_back( wxPoint( 0, 0 ) );
int theta = -angle / 2; EDA_ANGLE theta = -angle / 2;
for( int ii = 1; ii < numPoints - 1; ii++ ) 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 ); RotatePoint( &pt.x, &pt.y, theta );
polyPoints.push_back( pt ); polyPoints.push_back( pt );
theta += 50; theta += EDA_ANGLE( 5.0, DEGREES_T );
if( theta > angle / 2 ) if( theta > angle / 2 )
theta = angle / 2; theta = angle / 2;