Hatched circle shape: fix incorrect clipping of hatches.

- Fix size of converted polygon in Pcbnew
- Fix approximation of converted polygon in Eeschema: one cannot use ARC_HIGH_DEF
as error in Eeschema because this value is defined for Pcbnew, and not suitable
in Eeschema.
This commit is contained in:
jean-pierre charras 2025-05-17 14:01:02 +02:00
parent 484c35c44f
commit 8480b27042
5 changed files with 42 additions and 4 deletions

View File

@ -355,6 +355,15 @@ wxString EDA_SHAPE::SHAPE_T_asString() const
}
int EDA_SHAPE::GetArcToSegMaxErrorIU( bool aHighDefinition ) const
{
// Returning ARC_HIGH_DEF or ARC_LOW_DEF is suitable only for
// Pcbnew calculations
// For other cases a GetArcToSegMaxErrorIU() must be probably override this one
return aHighDefinition ? ARC_HIGH_DEF : ARC_LOW_DEF;
}
void EDA_SHAPE::setPosition( const VECTOR2I& aPos )
{
move( aPos - getPosition() );
@ -609,8 +618,8 @@ void EDA_SHAPE::UpdateHatching() const
break;
case SHAPE_T::CIRCLE:
TransformCircleToPolygon( shapeBuffer, getCenter(), GetRadius() + GetWidth(),
ARC_HIGH_DEF, ERROR_INSIDE );
TransformCircleToPolygon( shapeBuffer, getCenter(), GetRadius(),
GetArcToSegMaxErrorIU(), ERROR_INSIDE );
break;
case SHAPE_T::POLY:

View File

@ -49,6 +49,14 @@ EDA_ITEM* SCH_SHAPE::Clone() const
}
int SCH_SHAPE::GetArcToSegMaxErrorIU( bool aHighDefinition ) const
{
// Returns the equivalent of ARC_HIGH_DEF or ARC_LOW_DEF in eeschema IU
return aHighDefinition ?
schIUScale.mmToIU( ARC_HIGH_DEF_MM ) : schIUScale.mmToIU( ARC_LOW_DEF_MM );
}
void SCH_SHAPE::swapData( SCH_ITEM* aItem )
{
SCH_ITEM::SwapFlags( aItem );

View File

@ -76,6 +76,14 @@ public:
return GetHatchLineWidth() * 40;
}
/**
* @return a suitable value for error approximation when converting arc/circle to segments
* this value is in internal units
* @param aHightDef = true for high definition
* high def = similar to ARC_HIGH_DEF but in Eeschema IU, low def = similar to ARC_LOW_DEF
*/
int GetArcToSegMaxErrorIU( bool aHighDefinition = true ) const override;
void SetFilled( bool aFilled ) override;
const BOX2I GetBoundingBox() const override;

View File

@ -112,14 +112,19 @@ constexpr EDA_IU_SCALE drawSheetIUScale = EDA_IU_SCALE( PL_IU_PER_MM );
constexpr EDA_IU_SCALE schIUScale = EDA_IU_SCALE( SCH_IU_PER_MM );
constexpr EDA_IU_SCALE unityScale = EDA_IU_SCALE( 1 );
// Allowed error to approximate an arg by segments, in millimeters
constexpr double ARC_LOW_DEF_MM = 0.02;
constexpr double ARC_HIGH_DEF_MM = 0.005;
#ifndef SWIG
// The max error is the distance between the middle of a segment, and the circle
// for circle/arc to segment approximation.
// Warning: too small values can create very long calculation time in zone filling
// 0.05 to 0.005 mm are reasonable values
constexpr int ARC_LOW_DEF = pcbIUScale.mmToIU( 0.02 );
constexpr int ARC_HIGH_DEF = pcbIUScale.mmToIU( 0.005 );
// Allowed error to approximate an arg by segments, in Pcbnew IU
constexpr int ARC_LOW_DEF = pcbIUScale.mmToIU( ARC_LOW_DEF_MM );
constexpr int ARC_HIGH_DEF = pcbIUScale.mmToIU( ARC_HIGH_DEF_MM );
#endif
#endif // _BASE_UNITS_H_

View File

@ -381,6 +381,14 @@ public:
return makeEffectiveShapes( aEdgeOnly );
}
/**
* @return a suitable value for error approximation when converting arc/circle to segments
* this value is in internal units
* @param aHightDef = true for high definition
* for boards, high def = ARC_HIGH_DEF, low def = ARC_LOW_DEF
*/
virtual int GetArcToSegMaxErrorIU( bool aHighDefinition = true ) const;
void ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList );
void SetLength( const double& aLength );