/src/geos/src/operation/overlayng/IntersectionPointBuilder.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 | | #include <geos/operation/overlayng/IntersectionPointBuilder.h> |
16 | | |
17 | | #include <geos/operation/overlayng/OverlayEdge.h> |
18 | | #include <geos/operation/overlayng/OverlayGraph.h> |
19 | | #include <geos/operation/overlayng/OverlayLabel.h> |
20 | | #include <geos/geom/GeometryFactory.h> |
21 | | |
22 | | using namespace geos::geom; |
23 | | |
24 | | namespace geos { // geos |
25 | | namespace operation { // geos.operation |
26 | | namespace overlayng { // geos.operation.overlayng |
27 | | |
28 | | |
29 | | /*public*/ |
30 | | std::vector<std::unique_ptr<Point>> |
31 | | IntersectionPointBuilder::getPoints() |
32 | 6.77k | { |
33 | 6.77k | addResultPoints(); |
34 | 6.77k | std::vector<std::unique_ptr<Point>> rsltPts; |
35 | 6.77k | for (auto& pt : points) { |
36 | 5.36k | rsltPts.emplace_back(pt.release()); |
37 | 5.36k | } |
38 | 6.77k | return rsltPts; |
39 | 6.77k | } |
40 | | |
41 | | /*private*/ |
42 | | void |
43 | | IntersectionPointBuilder::addResultPoints() |
44 | 6.77k | { |
45 | 157k | for (OverlayEdge* nodeEdge : graph->getNodeEdges()) { |
46 | 157k | if (isResultPoint(nodeEdge)) { |
47 | 5.36k | points.emplace_back(geometryFactory->createPoint(nodeEdge->getCoordinate())); |
48 | 5.36k | } |
49 | 157k | } |
50 | 6.77k | } |
51 | | |
52 | | /*private*/ |
53 | | bool |
54 | | IntersectionPointBuilder::isResultPoint(OverlayEdge* nodeEdge) const |
55 | 157k | { |
56 | 157k | bool isEdgeOfA = false; |
57 | 157k | bool isEdgeOfB = false; |
58 | | |
59 | 157k | OverlayEdge* edge = nodeEdge; |
60 | 575k | do { |
61 | 575k | if (edge->isInResult()) { |
62 | 7.74k | return false; |
63 | 7.74k | } |
64 | 567k | const OverlayLabel* label = edge->getLabel(); |
65 | 567k | isEdgeOfA |= isEdgeOf(label, 0); |
66 | 567k | isEdgeOfB |= isEdgeOf(label, 1); |
67 | 567k | edge = static_cast<OverlayEdge*>(edge->oNext()); |
68 | 567k | } |
69 | 567k | while (edge != nodeEdge); |
70 | 149k | bool isNodeInBoth = isEdgeOfA && isEdgeOfB; |
71 | 149k | return isNodeInBoth; |
72 | 157k | } |
73 | | |
74 | | /*private*/ |
75 | | bool |
76 | | IntersectionPointBuilder::isEdgeOf(const OverlayLabel* label, uint8_t i) const |
77 | 1.13M | { |
78 | 1.13M | if (!isAllowCollapseLines && label->isBoundaryCollapse()) { |
79 | 0 | return false; |
80 | 0 | } |
81 | 1.13M | return label->isBoundary(i) || label->isLine(i); |
82 | 1.13M | } |
83 | | |
84 | | |
85 | | |
86 | | |
87 | | } // namespace geos.operation.overlayng |
88 | | } // namespace geos.operation |
89 | | } // namespace geos |