KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_gal_xor_mode.cpp File Reference

Tests for GAL XOR/difference mode (issue #18983). More...

#include <boost/test/unit_test.hpp>
#include <gal/color4d.h>
#include <cairo.h>
#include <cmath>

Go to the source code of this file.

Functions

static COLOR4D getPixelColor (cairo_surface_t *surface, int x, int y)
 Helper to get a pixel color from a Cairo ARGB32 surface.
 
static bool colorsApproxEqual (const COLOR4D &a, const COLOR4D &b, double tolerance=0.02)
 Helper to check if two colors are approximately equal.
 
 BOOST_AUTO_TEST_CASE (CairoDifferenceIdenticalColors)
 Test that CAIRO_OPERATOR_DIFFERENCE correctly computes |src - dst| for identical overlapping colors (should result in black).
 
 BOOST_AUTO_TEST_CASE (CairoDifferenceDifferentColors)
 Test that CAIRO_OPERATOR_DIFFERENCE shows the difference for different colors.
 
 BOOST_AUTO_TEST_CASE (CairoDifferenceNonOverlapping)
 Test that non-overlapping content (source on empty destination) shows the source.
 
 BOOST_AUTO_TEST_CASE (CairoDifferencePartialOverlap)
 Test partial overlap scenario - simulating gerbview XOR mode with two layers.
 

Detailed Description

Tests for GAL XOR/difference mode (issue #18983).

These tests verify that CAIRO_OPERATOR_DIFFERENCE correctly computes |src - dst| for XOR-style layer comparison in gerbview.

Definition in file test_gal_xor_mode.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( CairoDifferenceDifferentColors )

Test that CAIRO_OPERATOR_DIFFERENCE shows the difference for different colors.

Definition at line 126 of file test_gal_xor_mode.cpp.

References colorsApproxEqual(), expected, getPixelColor(), and result.

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( CairoDifferenceIdenticalColors )

Test that CAIRO_OPERATOR_DIFFERENCE correctly computes |src - dst| for identical overlapping colors (should result in black).

Definition at line 81 of file test_gal_xor_mode.cpp.

References colorsApproxEqual(), expected, getPixelColor(), and result.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( CairoDifferenceNonOverlapping )

Test that non-overlapping content (source on empty destination) shows the source.

Definition at line 169 of file test_gal_xor_mode.cpp.

References colorsApproxEqual(), expected, getPixelColor(), and result.

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( CairoDifferencePartialOverlap )

Test partial overlap scenario - simulating gerbview XOR mode with two layers.

Definition at line 213 of file test_gal_xor_mode.cpp.

References KIGFX::COLOR4D::b, colorsApproxEqual(), KIGFX::COLOR4D::g, getPixelColor(), and KIGFX::COLOR4D::r.

◆ colorsApproxEqual()

static bool colorsApproxEqual ( const COLOR4D & a,
const COLOR4D & b,
double tolerance = 0.02 )
static

Helper to check if two colors are approximately equal.

Definition at line 69 of file test_gal_xor_mode.cpp.

References std::abs(), KIGFX::COLOR4D::b, KIGFX::COLOR4D::g, and KIGFX::COLOR4D::r.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ getPixelColor()

static COLOR4D getPixelColor ( cairo_surface_t * surface,
int x,
int y )
static

Helper to get a pixel color from a Cairo ARGB32 surface.

Definition at line 47 of file test_gal_xor_mode.cpp.

References getPixelColor().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and getPixelColor().