45 constexpr double IU2_TO_MM2 = 1e-10;
48 result.overlap = aReference;
49 result.overlap.BooleanIntersection( aComparison );
52 result.additions = aComparison;
53 result.additions.BooleanSubtract( aReference );
56 result.removals = aReference;
57 result.removals.BooleanSubtract( aComparison );
60 result.additionsArea =
result.additions.Area() * IU2_TO_MM2;
61 result.removalsArea =
result.removals.Area() * IU2_TO_MM2;
67 if(
result.referenceArea > 0.0 )
77 result.additions.Fracture();
78 result.removals.Fracture();
88double ConvertArea(
double aMm2,
DIFF_UNITS aUnits )
121 wxString suffix = GetUnitSuffix( aUnits );
124 out += wxString::Format( wxS(
"Comparing: %s vs %s\n\n" ), aFile1, aFile2 );
126 out += wxString::Format( wxS(
"Reference area: %.2f %s^2\n" ), ConvertArea( aResult.
referenceArea, aUnits ),
128 out += wxString::Format( wxS(
"Comparison area: %.2f %s^2\n" ), ConvertArea( aResult.
comparisonArea, aUnits ),
130 out += wxString::Format( wxS(
"Overlap area: %.2f %s^2\n\n" ), ConvertArea( aResult.
overlapArea, aUnits ),
134 wxString remSign = aResult.
removalsPercent > 0 ? wxS(
"-" ) : wxS(
"" );
137 out += wxString::Format( wxS(
"Additions: %.2f %s^2 (%s%.2f%% of reference)\n" ),
139 out += wxString::Format( wxS(
"Removals: %.2f %s^2 (%s%.2f%% of reference)\n" ),
141 out += wxString::Format( wxS(
"Net change: %s%.2f %s^2 (%s%.2f%%)\n" ), netSign,
152 wxString unitStr = GetUnitSuffix( aUnits );
156 j[
"reference_file"] = aFile1.ToStdString();
157 j[
"comparison_file"] = aFile2.ToStdString();
158 j[
"units"] = unitStr.ToStdString();
160 j[
"reference"] = { {
"area", ConvertArea( aResult.
referenceArea, aUnits ) } };
162 j[
"comparison"] = { {
"area", ConvertArea( aResult.
comparisonArea, aUnits ) } };
164 j[
"overlap"] = { {
"area", ConvertArea( aResult.
overlapArea, aUnits ) } };
166 j[
"additions"] = { {
"area", ConvertArea( aResult.
additionsArea, aUnits ) },
176 bool withinThreshold =
177 ( aMaxDiffPercent <= 0.0 ) ? ( totalDiffPercent == 0.0 ) : ( totalDiffPercent <= aMaxDiffPercent );
179 j[
"within_threshold"] = withinThreshold;
180 j[
"max_diff_percent"] = aMaxDiffPercent;
181 j[
"total_diff_percent"] = totalDiffPercent;
201 if( pts.size() >= 3 )
218 if( poly.OutlineCount() > 0 )
220 BOX2I polyBox = poly.BBox();
229 bbox.
Merge( polyBox );
250 if( !plotter.
StartPlot( wxEmptyString ) )
261 return plotter.
SaveFile( aOutputPath );
constexpr size_type GetWidth() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr size_type GetHeight() const
constexpr const Vec & GetOrigin() const
A color representation with 4 components: red, green, blue, alpha.
PNG rasterization plotter using Cairo graphics library.
void SetPixelSize(int aWidth, int aHeight)
Set the output image dimensions in pixels.
bool SaveFile(const wxString &aPath)
Save the rendered image to a PNG file.
void SetBackgroundColor(const COLOR4D &aColor)
Set the background color for the image.
void SetResolution(int aDPI)
Set the output resolution in dots per inch.
virtual bool EndPlot() override
void SetAntialias(bool aEnable)
Enable or disable anti-aliasing.
virtual void SetColor(const COLOR4D &aColor) override
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth, void *aData=nullptr) override
Draw a polygon ( filled or not ).
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual bool StartPlot(const wxString &aPageNumber) override
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
@ FILLED_SHAPE
Fill with object color.
wxString FormatDiffResultText(const GERBER_DIFF_RESULT &aResult, const wxString &aFile1, const wxString &aFile2, DIFF_UNITS aUnits)
Format a diff result as human-readable text.
GERBER_DIFF_RESULT CalculateGerberDiff(const SHAPE_POLY_SET &aReference, const SHAPE_POLY_SET &aComparison)
Calculate the geometric differences between two poly sets.
VECTOR2I CalculateAlignment(const SHAPE_POLY_SET &aReference, const SHAPE_POLY_SET &aComparison)
Calculate the alignment offset to make a comparison poly set align with a reference.
nlohmann::json FormatDiffResultJson(const GERBER_DIFF_RESULT &aResult, const wxString &aFile1, const wxString &aFile2, DIFF_UNITS aUnits, double aMaxDiffPercent)
Format a diff result as JSON.
bool RenderDiffToPng(const GERBER_DIFF_RESULT &aResult, const wxString &aOutputPath, const DIFF_RENDER_OPTIONS &aOptions)
Render a diff result to PNG with colored regions.
DIFF_UNITS
Units for diff result formatting.
GERBER_PLOTTER_VIEWPORT CalculatePlotterViewport(const BOX2I &aBBox, int aDpi, int aWidth, int aHeight)
Compute pixel dimensions and plotter scale from a bounding box and DPI/size settings.
Options for diff PNG rendering.
KIGFX::COLOR4D colorRemovals
Red.
KIGFX::COLOR4D colorAdditions
Green.
int height
0 = calculate from DPI
KIGFX::COLOR4D colorOverlap
Gray.
KIGFX::COLOR4D colorBackground
White.
int width
0 = calculate from DPI
Result of a Gerber diff calculation containing the geometric differences and area statistics.
SHAPE_POLY_SET removals
Areas in file1 but not file2 (file1 AND NOT file2)
double removalsPercent
Removals as percent of reference area.
double additionsArea
Area of additions in mm^2.
SHAPE_POLY_SET overlap
Areas present in both files (file1 AND file2)
double referenceArea
Total area of file1 in mm^2.
double overlapArea
Area of overlap in mm^2.
double comparisonArea
Total area of file2 in mm^2.
double netChangePercent
Net change as percent of reference area.
double removalsArea
Area of removals in mm^2.
double additionsPercent
Additions as percent of reference area.
SHAPE_POLY_SET additions
Areas in file2 but not file1 (file2 AND NOT file1)
Computed plotter viewport parameters from a bounding box and render settings.
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I