/src/geos/src/noding/IntersectionAdder.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) 2006 Refractions Research Inc. |
7 | | * |
8 | | * This is free software; you can redistribute and/or modify it under |
9 | | * the terms of the GNU Lesser General Licence as published |
10 | | * by the Free Software Foundation. |
11 | | * See the COPYING file for more information. |
12 | | * |
13 | | ********************************************************************** |
14 | | * |
15 | | * Last port: noding/IntersectionAdder.java rev. 1.6 (JTS-1.9) |
16 | | * |
17 | | **********************************************************************/ |
18 | | |
19 | | #include <geos/noding/IntersectionAdder.h> |
20 | | #include <geos/noding/SegmentString.h> |
21 | | #include <geos/noding/NodedSegmentString.h> |
22 | | #include <geos/algorithm/LineIntersector.h> |
23 | | #include <geos/geom/Coordinate.h> |
24 | | #include <geos/util.h> |
25 | | |
26 | | using namespace geos::geom; |
27 | | |
28 | | namespace geos { |
29 | | namespace noding { // geos.noding |
30 | | |
31 | | /*private*/ |
32 | | bool |
33 | | IntersectionAdder::isTrivialIntersection(const SegmentString* e0, |
34 | | std::size_t segIndex0, const SegmentString* e1, std::size_t segIndex1) |
35 | 81.2M | { |
36 | 81.2M | if(e0 != e1) { |
37 | 26.7M | return false; |
38 | 26.7M | } |
39 | | |
40 | 54.5M | if(li.getIntersectionNum() != 1) { |
41 | 5.96M | return false; |
42 | 5.96M | } |
43 | | |
44 | 48.6M | if(isAdjacentSegments(segIndex0, segIndex1)) { |
45 | 1.54M | return true; |
46 | 1.54M | } |
47 | | |
48 | 47.0M | if(! e0->isClosed()) { |
49 | 28.2M | return false; |
50 | 28.2M | } |
51 | | |
52 | 18.7M | auto maxSegIndex = e0->size() - 1; |
53 | 18.7M | if((segIndex0 == 0 && segIndex1 == maxSegIndex) |
54 | 18.7M | || (segIndex1 == 0 && segIndex0 == maxSegIndex)) { |
55 | 0 | return true; |
56 | 0 | } |
57 | 18.7M | return false; |
58 | | |
59 | 18.7M | } |
60 | | |
61 | | /*public*/ |
62 | | void |
63 | | IntersectionAdder::processIntersections( |
64 | | SegmentString* e0, std::size_t segIndex0, |
65 | | SegmentString* e1, std::size_t segIndex1) |
66 | 166M | { |
67 | | // don't bother intersecting a segment with itself |
68 | 166M | if(e0 == e1 && segIndex0 == segIndex1) { |
69 | 0 | return; |
70 | 0 | } |
71 | | |
72 | 166M | numTests++; |
73 | | |
74 | 166M | const CoordinateSequence& seq0 = *e0->getCoordinates(); |
75 | 166M | const CoordinateSequence& seq1 = *e1->getCoordinates(); |
76 | | |
77 | 166M | li.computeIntersection(seq0, segIndex0, seq1, segIndex1); |
78 | | |
79 | | // No intersection, nothing to do |
80 | 166M | if(! li.hasIntersection()) { |
81 | 85.4M | return; |
82 | 85.4M | } |
83 | | |
84 | | //intersectionFound = true; |
85 | 81.2M | numIntersections++; |
86 | | |
87 | 81.2M | if(li.isInteriorIntersection()) { |
88 | 54.4M | numInteriorIntersections++; |
89 | 54.4M | hasInterior = true; |
90 | 54.4M | } |
91 | | |
92 | | // if the segments are adjacent they have at least |
93 | | // one trivial intersection, |
94 | | // the shared endpoint. Don't bother adding it if it |
95 | | // is the only intersection. |
96 | 81.2M | if(! isTrivialIntersection(e0, segIndex0, e1, segIndex1)) { |
97 | 79.7M | hasIntersectionVar = true; |
98 | | |
99 | 79.7M | NodedSegmentString* ee0 = detail::down_cast<NodedSegmentString*>(e0); |
100 | 79.7M | NodedSegmentString* ee1 = detail::down_cast<NodedSegmentString*>(e1); |
101 | 79.7M | ee0->addIntersections(&li, segIndex0, 0); |
102 | 79.7M | ee1->addIntersections(&li, segIndex1, 1); |
103 | | |
104 | 79.7M | if(li.isProper()) { |
105 | 42.2M | numProperIntersections++; |
106 | | //Debug.println(li.toString()); |
107 | | //Debug.println(li.getIntersection(0)); |
108 | 42.2M | properIntersectionPoint = li.getIntersection(0); |
109 | 42.2M | hasProper = true; |
110 | 42.2M | hasProperInterior = true; |
111 | 42.2M | } |
112 | 79.7M | } |
113 | 81.2M | } |
114 | | |
115 | | } // namespace geos.noding |
116 | | } // namespace geos |