26#include <boost/test/unit_test.hpp>
44 char m_PaintOp =
'\0';
45 double m_Radius = 0.0;
49bool isPaintOperator(
const std::string& aToken )
51 return aToken ==
"s" || aToken ==
"b" || aToken ==
"f";
55bool isPathOperator(
const std::string& aToken )
57 return aToken ==
"m" || aToken ==
"c" || isPaintOperator( aToken );
61CIRCLE_PATH parseCirclePath(
const std::string& aBuffer )
64 std::istringstream buffer( aBuffer );
67 while( std::getline( buffer, line ) )
69 std::vector<std::string> tokens;
70 std::istringstream lineStream( line );
73 while( lineStream >> token )
74 tokens.push_back( token );
76 if( tokens.size() < 27 || !isPaintOperator( tokens.back() ) )
79 std::vector<double> coordinates;
81 for(
const std::string& tok : tokens )
83 if( isPathOperator( tok ) )
88 coordinates.push_back( std::stod( tok ) );
90 catch(
const std::exception& )
97 if( coordinates.size() != 26 )
100 double minX = coordinates[0];
101 double maxX = coordinates[0];
103 for(
size_t ii = 0; ii < coordinates.size(); ii += 2 )
105 minX = std::min( minX, coordinates[ii] );
106 maxX = std::max( maxX, coordinates[ii] );
109 result.m_PaintOp = tokens.back()[0];
110 result.m_Radius = ( maxX - minX ) / 2.0;
119CIRCLE_PATH plotOneCircle(
int aDiameter,
FILL_T aFill,
int aWidth,
int aDefaultPenWidth,
120 double aIusPerDecimil = 1.0 )
123 const wxString pdfPath = tempDir.CreateChildFileStr( wxT(
"output.pdf" ) );
142 CIRCLE_PATH
path = parseCirclePath( buffer );
143 BOOST_REQUIRE_MESSAGE(
path.m_PaintOp !=
'\0',
"No circle path found in the PDF content" );
156 BOOST_CHECK_CLOSE(
path.m_Radius, 10000.0, 0.01 );
165 BOOST_CHECK_CLOSE(
path.m_Radius, 10000.0, 0.01 );
174 BOOST_CHECK_CLOSE(
path.m_Radius, 11000.0, 0.01 );
183 BOOST_CHECK_CLOSE(
path.m_Radius, 11000.0 / 25.4, 0.01 );
193 BOOST_CHECK_CLOSE(
path.m_Radius, 11000.0, 0.01 );
202 BOOST_CHECK_CLOSE(
path.m_Radius, 10000.0, 0.01 );
void SetDefaultPenWidth(int aWidth)
virtual bool EndPlot() override
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width) override
Circle drawing for PDF.
virtual bool OpenFile(const wxString &aFullFilename) override
Open or create the plot file aFullFilename.
virtual bool StartPlot(const wxString &aPageNumber) override
The PDF engine supports multiple pages; the first one is opened 'for free' the following are to be cl...
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
PDF can have multiple pages, so SetPageSettings can be called with the outputFile open (but not insid...
void SetRenderSettings(RENDER_SETTINGS *aSettings)
static const int USE_DEFAULT_LINE_WIDTH
Minimal concrete render settings suitable for plotters in tests.
@ FILLED_SHAPE
Fill with object color.
bool ReadPdfWithDecompressedStreams(const wxString &aPdfPath, std::string &aOutBuffer)
Read a PDF file and append best-effort decompressed contents of any Flate streams to the returned buf...
Plotting engines similar to ps (PostScript, Gerber, svg)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(StrokeNarrowerThanDiameterIsStroked)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I