CADSTAR PCB: Correctly handle anticlockwise arcs
Also add some qa tests for EDA_SHAPE::SetAngleAndEnd Fixes https://gitlab.com/kicad/code/kicad/-/issues/13626
This commit is contained in:
parent
0ecad1ef2e
commit
963e82ee7f
|
@ -2883,14 +2883,14 @@ PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstar
|
|||
|
||||
EDA_ANGLE arcStartAngle( startPoint - centerPoint );
|
||||
EDA_ANGLE arcEndAngle( endPoint - centerPoint );
|
||||
EDA_ANGLE arcAngle = arcEndAngle - arcStartAngle;
|
||||
EDA_ANGLE arcAngle = ( arcEndAngle - arcStartAngle ).Normalize();
|
||||
//TODO: detect if we are supposed to draw a circle instead (i.e. two SEMICIRCLEs
|
||||
// with opposite start/end points and same centre point)
|
||||
|
||||
if( cw )
|
||||
shape->SetArcAngleAndEnd( arcAngle.Normalize() );
|
||||
else
|
||||
shape->SetArcAngleAndEnd( -arcAngle.Normalize(), true );
|
||||
if( !cw )
|
||||
arcAngle.NormalizeNegative(); // anticlockwise arc
|
||||
|
||||
shape->SetArcAngleAndEnd( arcAngle, true );
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ set( QA_COMMON_SRCS
|
|||
test_bitmap_base.cpp
|
||||
test_color4d.cpp
|
||||
test_coroutine.cpp
|
||||
test_eda_shape.cpp
|
||||
test_lib_table.cpp
|
||||
test_markup_parser.cpp
|
||||
test_kicad_string.cpp
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 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
|
||||
* as published by the Free Software Foundation; either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
|
||||
#include <eda_shape.h>
|
||||
#include <qa_utils/geometry/geometry.h> // For KI_TEST::IsVecWithinTol
|
||||
#include <geometry/shape_arc.h> // For SHAPE_ARC::DefaultAccuracyForPCB()
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( EdaShape )
|
||||
|
||||
class EDA_SHAPE_MOCK : public EDA_SHAPE
|
||||
{
|
||||
public:
|
||||
EDA_SHAPE_MOCK( SHAPE_T aShapeType ) : EDA_SHAPE( aShapeType, 0, FILL_T::NO_FILL ){};
|
||||
|
||||
protected:
|
||||
EDA_ANGLE getParentOrientation() const override { return ANGLE_0; }
|
||||
VECTOR2I getParentPosition() const override { return VECTOR2I(); }
|
||||
};
|
||||
|
||||
|
||||
struct SET_ANGLE_END_CASE
|
||||
{
|
||||
std::string m_CaseName;
|
||||
VECTOR2I m_Start;
|
||||
VECTOR2I m_Center;
|
||||
double m_Angle;
|
||||
VECTOR2I m_ExpectedEndBeforeSwap;
|
||||
bool m_ExpectedStartEndSwapped;
|
||||
};
|
||||
|
||||
|
||||
static const std::vector<SET_ANGLE_END_CASE> set_angle_end_cases =
|
||||
{
|
||||
{
|
||||
"Issue 13626: clockwise semicircle",
|
||||
{-428880000, 117229160 },
|
||||
{-430060565, 113472820 },
|
||||
180.0,
|
||||
{-431241130, 109716480 },
|
||||
false
|
||||
},
|
||||
{
|
||||
"Issue 13626: anticlockwise arc",
|
||||
{ -431241130, 109716480 },
|
||||
{ -434923630, 112954230 },
|
||||
-138.46654568595355,
|
||||
{ -439827050, 112936200 },
|
||||
true
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( SetAngleAndEnd )
|
||||
{
|
||||
for( const auto& c : set_angle_end_cases )
|
||||
{
|
||||
BOOST_TEST_INFO_SCOPE( c.m_CaseName );
|
||||
|
||||
EDA_SHAPE_MOCK shape( SHAPE_T::ARC );
|
||||
shape.SetStart( c.m_Start );
|
||||
shape.SetCenter( c.m_Center );
|
||||
|
||||
shape.SetArcAngleAndEnd( EDA_ANGLE( c.m_Angle, DEGREES_T ), true );
|
||||
|
||||
BOOST_CHECK_EQUAL( shape.EndsSwapped(), c.m_ExpectedStartEndSwapped );
|
||||
|
||||
VECTOR2I newEnd = shape.EndsSwapped() ? shape.GetStart() : shape.GetEnd();
|
||||
|
||||
BOOST_CHECK_PREDICATE(
|
||||
KI_TEST::IsVecWithinTol<VECTOR2I>,
|
||||
(newEnd) ( c.m_ExpectedEndBeforeSwap ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Reference in New Issue