Coverage Report

Created: 2025-08-30 06:52

/src/geos/src/triangulate/tri/TriangulationBuilder.cpp
Line
Count
Source (jump to first uncovered line)
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7
 *
8
 * This is free software; you can redistribute and/or modify it under
9
 * the terms of the GNU Lesser General Public Licence as published
10
 * by the Free Software Foundation.
11
 * See the COPYING file for more information.
12
 *
13
 **********************************************************************/
14
15
16
#include <geos/geom/Coordinate.h>
17
#include <geos/triangulate/tri/Tri.h>
18
#include <geos/triangulate/tri/TriList.h>
19
#include <geos/triangulate/tri/TriangulationBuilder.h>
20
21
22
namespace geos {        // geos
23
namespace triangulate { // geos.triangulate
24
namespace tri {         // geos.triangulate.tri
25
26
27
/* public static */
28
void
29
TriangulationBuilder::build(TriList<Tri>& triList)
30
0
{
31
0
    TriangulationBuilder tb(triList);
32
0
}
33
34
/* private */
35
TriangulationBuilder::TriangulationBuilder(TriList<Tri>& triList)
36
0
{
37
0
    for (auto* tri : triList) {
38
0
        add(tri);
39
0
    }
40
0
}
41
42
/* private */
43
Tri*
44
TriangulationBuilder::find(const Coordinate& p0, const Coordinate& p1) const
45
0
{
46
0
    const TriEdge e(p0, p1);
47
0
    auto it = triMap.find(e);
48
0
    if (it == triMap.end()) {
49
        // not found
50
0
        return nullptr;
51
0
    }
52
0
    else {
53
        // found
54
0
        return it->second;
55
0
    }
56
0
}
57
58
/* private */
59
void
60
TriangulationBuilder::add(Tri* tri)
61
0
{
62
0
    const Coordinate& p0 = tri->getCoordinate(0);
63
0
    const Coordinate& p1 = tri->getCoordinate(1);
64
0
    const Coordinate& p2 = tri->getCoordinate(2);
65
66
    // get adjacent triangles, if any
67
0
    Tri* n0 = find(p0, p1);
68
0
    Tri* n1 = find(p1, p2);
69
0
    Tri* n2 = find(p2, p0);
70
71
0
    tri->setAdjacent(n0, n1, n2);
72
0
    addAdjacent(tri, n0, p0, p1);
73
0
    addAdjacent(tri, n1, p1, p2);
74
0
    addAdjacent(tri, n2, p2, p0);
75
0
}
76
77
/* private */
78
void
79
TriangulationBuilder::addAdjacent(Tri* tri, Tri* adj, const Coordinate& p0, const Coordinate& p1)
80
0
{
81
    /**
82
     * If adjacent is null, this tri is first one to be recorded for edge
83
     */
84
0
    if (adj == nullptr) {
85
86
0
        triMap.emplace(
87
0
            std::piecewise_construct,
88
0
            std::forward_as_tuple(p0, p1),
89
0
            std::forward_as_tuple(tri));
90
91
        // TriEdge e(p0, p1);
92
        // triMap.insert(std::make_pair(e, tri));
93
0
        return;
94
0
    }
95
0
    adj->setAdjacent(p1, tri);
96
0
}
97
98
99
} // namespace geos.triangulate.tri
100
} // namespace geos.triangulate
101
} // namespace geos
102