KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_poly_set.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
19#include <trigo.h>
20
22#include <qa_utils/numeric.h>
24
25#include "geom_test_utils.h"
26
27
28BOOST_AUTO_TEST_SUITE( ShapePolySet )
29
30BOOST_AUTO_TEST_CASE( RemoveNullSegments )
31{
32 SHAPE_POLY_SET base_set;
33
34 base_set.NewOutline();
35 base_set.Append( 0, 0, -1, -1, true );
36 base_set.Append( 0, 10, -1, -1, true );
37 base_set.Append( 10, 10, -1, -1, true );
38 base_set.Append( 10, 10, -1, -1, true );
39 base_set.Append( 10, 10, -1, -1, true );
40 base_set.Append( 10, 10, -1, -1, true );
41 base_set.Append( 10, 0, -1, -1, true );
42
43 int removed = base_set.RemoveNullSegments();
44
45 BOOST_CHECK_EQUAL( removed, 3 );
46 BOOST_CHECK_EQUAL( base_set.VertexCount(), 4 );
47
48 base_set.DeletePolygon( 0 );
49
50 base_set.NewOutline();
51 base_set.Append( 0, 0, -1, -1, true );
52 base_set.Append( 0, 10, -1, -1, true );
53 base_set.Append( 0, 10, -1, -1, true );
54 base_set.Append( 10, 10, -1, -1, true );
55 base_set.Append( 10, 10, -1, -1, true );
56 base_set.Append( 10, 0, -1, -1, true );
57 base_set.Append( 10, 0, -1, -1, true );
58 base_set.Append( 0, 0, -1, -1, true );
59
60 removed = base_set.RemoveNullSegments();
61
62 BOOST_CHECK_EQUAL( removed, 4 );
63 BOOST_CHECK_EQUAL( base_set.VertexCount(), 4 );
64
65}
66
67BOOST_AUTO_TEST_SUITE_END()
Represent a set of closed polygons.
int VertexCount(int aOutline=-1, int aHole=-1) const
Return the number of vertices in a given outline/hole.
void DeletePolygon(int aIdx)
Delete aIdx-th polygon from the set.
int RemoveNullSegments()
Look for null segments; ie, segments whose ends are exactly the same and deletes them.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
Numerical test predicates.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(RemoveNullSegments)