1 /**
2 * \file
3 * \brief Performance test for Boolops
4 *//*
5 * Authors:
6 * Krzysztof Kosiński <tweenk.pl@gmail.com>
7 *
8 * Copyright 2015 Authors
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it either under the terms of the GNU Lesser General Public
12 * License version 2.1 as published by the Free Software Foundation
13 * (the "LGPL") or, at your option, under the terms of the Mozilla
14 * Public License Version 1.1 (the "MPL"). If you do not alter this
15 * notice, a recipient may use your version of this file under either
16 * the MPL or the LGPL.
17 *
18 * You should have received a copy of the LGPL along with this library
19 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * You should have received a copy of the MPL along with this library
22 * in the file COPYING-MPL-1.1
23 *
24 * The contents of this file are subject to the Mozilla Public License
25 * Version 1.1 (the "License"); you may not use this file except in
26 * compliance with the License. You may obtain a copy of the License at
27 * http://www.mozilla.org/MPL/
28 *
29 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31 * the specific language governing rights and limitations.
32 */
33
34 #include <2geom/intersection-graph.h>
35 #include <2geom/svg-path-parser.h>
36 #include <iostream>
37 #include <glib.h>
38
39 using namespace Geom;
40
main(int argc,char ** argv)41 int main(int argc, char **argv)
42 {
43 if (argc != 4) {
44 std::cout << "boolops: wrong number of arguments; no tests run!" << std::endl;
45 exit(0); // TODO: add suitable arguments in CMake target / actually do some tests here
46 }
47
48 PathVector a = read_svgd(argv[2]);
49 PathVector b = read_svgd(argv[3]);
50 unsigned const ops = atoi(argv[1]);
51
52 OptRect abox = a.boundsExact();
53 OptRect bbox = a.boundsExact();
54 if (!abox) {
55 std::cout << argv[1] << " contains an empty path" << std::endl;
56 std::exit(1);
57 }
58 if (!bbox) {
59 std::cout << argv[2] << " contains an empty path" << std::endl;
60 std::exit(1);
61 }
62
63 a *= Translate(-abox->corner(0));
64 b *= Translate(-bbox->corner(0));
65
66 long num_intersections = 0;
67 long num_outcv = 0;
68
69 // for reproducibility.
70 g_random_set_seed(1234);
71
72 for (unsigned i = 0; i < ops; ++i) {
73 Point delta;
74 delta[X] = g_random_double_range(-bbox->width(), abox->width());
75 delta[Y] = g_random_double_range(-bbox->height(), abox->height());
76
77 PathVector bt = b * Translate(delta);
78
79 PathIntersectionGraph pig(a, bt);
80 PathVector x = pig.getIntersection();
81 num_intersections += pig.intersectionPoints().size();
82 num_outcv += x.curveCount();
83 }
84
85 std::cout << "Completed " << ops << " operations.\n"
86 << "Total intersections: " << num_intersections << "\n"
87 << "Total output curves: " << num_outcv << std::endl;
88
89 return 0;
90 }
91
92 /*
93 Local Variables:
94 mode:c++
95 c-file-style:"stroustrup"
96 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
97 indent-tabs-mode:nil
98 fill-column:99
99 End:
100 */
101 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
102