1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * @file Test the geom-pathstroke functionality.
7 * Hendrik Roehm <git@roehm.ws>
9 * Copyright (C) 2023 Authors
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 #include "helper/geom-pathstroke.h"
16 #include <gtest/gtest.h>
18 #include "object/sp-path.h"
19 #include <2geom/pathvector.h>
21 #include "test-with-svg-object-pairs.h"
23 class GeomPathstrokeTest
: public Inkscape::TestWithSvgObjectPairs
27 : Inkscape::TestWithSvgObjectPairs("data/geom-pathstroke.svg", 8) {}
30 double approximate_directed_hausdorff_distance(const Geom::Path
*path1
, const Geom::Path
*path2
)
32 auto const time_range
= path1
->timeRange();
34 for (size_t i
= 0; i
<= 25; i
+= 1) {
35 auto const time
= time_range
.valueAt(static_cast<double>(i
) / 25);
36 auto const search_point
= path1
->pointAt(time
);
38 path2
->nearestTime(search_point
, &dist
);
39 if (dist
> dist_max
) {
47 TEST_F(GeomPathstrokeTest
, BoundedHausdorffDistance
)
49 double const tolerance
= 0.1;
50 // same as 0.1 inch in the document (only works without viewBox and transformations)
51 auto const offset_width
= -9.6;
53 unsigned case_index
= 0;
54 for (auto test_case
: getTestCases()) {
55 auto const *test_item
= cast
<SPPath
>(test_case
.test_object
);
56 auto const *comp_item
= cast
<SPPath
>(test_case
.reference_object
);
57 ASSERT_TRUE(test_item
&& comp_item
);
59 // Note that transforms etc are not considered. Therefore the objects shoud have equal transforms.
60 auto const test_curve
= test_item
->curve();
61 auto const comp_curve
= comp_item
->curve();
62 ASSERT_TRUE(test_curve
&& comp_curve
);
64 auto const &test_pathvector
= test_curve
->get_pathvector();
65 auto const &comp_pathvector
= comp_curve
->get_pathvector();
66 ASSERT_EQ(test_pathvector
.size(), 1);
67 ASSERT_EQ(comp_pathvector
.size(), 1);
69 auto const &test_path
= test_pathvector
.at(0);
70 auto const &comp_path
= comp_pathvector
.at(0);
72 auto const offset_path
= Inkscape::half_outline(test_path
, offset_width
, 0, Inkscape::JOIN_EXTRAPOLATE
, 0.);
73 double const error1
= approximate_directed_hausdorff_distance(&offset_path
, &comp_path
);
74 double const error2
= approximate_directed_hausdorff_distance(&comp_path
, &offset_path
);
75 double const error
= std::max(error1
, error2
);
77 EXPECT_LE(error
, tolerance
) << "Hausdorff distance above tolerance in test case #" << case_index
78 << "\nactual d " << sp_svg_write_path(Geom::PathVector(offset_path
), true)
79 << "\nexpected d " << sp_svg_write_path(Geom::PathVector(comp_path
), true)
88 c-file-style:"stroustrup"
89 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
94 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :