| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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 Public Licence as published |
|
10
|
|
|
|
|
|
|
* by the Free Software Foundation. |
|
11
|
|
|
|
|
|
|
* See the COPYING file for more information. |
|
12
|
|
|
|
|
|
|
* |
|
13
|
|
|
|
|
|
|
********************************************************************** |
|
14
|
|
|
|
|
|
|
* |
|
15
|
|
|
|
|
|
|
* Last port: noding/SegmentPointComparator.java r320 (JTS-1.12) |
|
16
|
|
|
|
|
|
|
* |
|
17
|
|
|
|
|
|
|
**********************************************************************/ |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#ifndef GEOS_NODING_SEGMENTPOINTCOMPARATOR_H |
|
20
|
|
|
|
|
|
|
#define GEOS_NODING_SEGMENTPOINTCOMPARATOR_H |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#include |
|
23
|
|
|
|
|
|
|
#include |
|
24
|
|
|
|
|
|
|
#include |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
namespace geos { |
|
27
|
|
|
|
|
|
|
namespace noding { // geos.noding |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
/** |
|
30
|
|
|
|
|
|
|
* Implements a robust method of comparing the relative position of two |
|
31
|
|
|
|
|
|
|
* points along the same segment. |
|
32
|
|
|
|
|
|
|
* The coordinates are assumed to lie "near" the segment. |
|
33
|
|
|
|
|
|
|
* This means that this algorithm will only return correct results |
|
34
|
|
|
|
|
|
|
* if the input coordinates |
|
35
|
|
|
|
|
|
|
* have the same precision and correspond to rounded values |
|
36
|
|
|
|
|
|
|
* of exact coordinates lying on the segment. |
|
37
|
|
|
|
|
|
|
* |
|
38
|
|
|
|
|
|
|
*/ |
|
39
|
|
|
|
|
|
|
class GEOS_DLL SegmentPointComparator { |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
public: |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
/** |
|
44
|
|
|
|
|
|
|
* Compares two Coordinates for their relative position along a |
|
45
|
|
|
|
|
|
|
* segment lying in the specified Octant. |
|
46
|
|
|
|
|
|
|
* |
|
47
|
|
|
|
|
|
|
* @return -1 node0 occurs first |
|
48
|
|
|
|
|
|
|
* @return 0 the two nodes are equal |
|
49
|
|
|
|
|
|
|
* @return 1 node1 occurs first |
|
50
|
|
|
|
|
|
|
*/ |
|
51
|
1
|
|
|
|
|
|
static int compare(int octant, const geom::Coordinate& p0, |
|
52
|
|
|
|
|
|
|
const geom::Coordinate& p1) |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
|
|
|
|
|
|
// nodes can only be equal if their coordinates are equal |
|
55
|
1
|
50
|
|
|
|
|
if (p0.equals2D(p1)) return 0; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
|
int xSign = relativeSign(p0.x, p1.x); |
|
58
|
1
|
|
|
|
|
|
int ySign = relativeSign(p0.y, p1.y); |
|
59
|
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
|
switch (octant) { |
|
61
|
0
|
|
|
|
|
|
case 0: return compareValue(xSign, ySign); |
|
62
|
0
|
|
|
|
|
|
case 1: return compareValue(ySign, xSign); |
|
63
|
0
|
|
|
|
|
|
case 2: return compareValue(ySign, -xSign); |
|
64
|
0
|
|
|
|
|
|
case 3: return compareValue(-xSign, ySign); |
|
65
|
1
|
|
|
|
|
|
case 4: return compareValue(-xSign, -ySign); |
|
66
|
0
|
|
|
|
|
|
case 5: return compareValue(-ySign, -xSign); |
|
67
|
0
|
|
|
|
|
|
case 6: return compareValue(-ySign, xSign); |
|
68
|
0
|
|
|
|
|
|
case 7: return compareValue(xSign, -ySign); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
assert(0); // invalid octant value |
|
71
|
0
|
|
|
|
|
|
return 0; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
|
static int relativeSign(double x0, double x1) |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
2
|
100
|
|
|
|
|
if (x0 < x1) return -1; |
|
78
|
1
|
50
|
|
|
|
|
if (x0 > x1) return 1; |
|
79
|
1
|
|
|
|
|
|
return 0; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
|
static int compareValue(int compareSign0, int compareSign1) |
|
83
|
|
|
|
|
|
|
{ |
|
84
|
1
|
50
|
|
|
|
|
if (compareSign0 < 0) return -1; |
|
85
|
1
|
50
|
|
|
|
|
if (compareSign0 > 0) return 1; |
|
86
|
0
|
0
|
|
|
|
|
if (compareSign1 < 0) return -1; |
|
87
|
0
|
0
|
|
|
|
|
if (compareSign1 > 0) return 1; |
|
88
|
0
|
|
|
|
|
|
return 0; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
}; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} // namespace geos.noding |
|
94
|
|
|
|
|
|
|
} // namespace geos |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#endif // GEOS_NODING_SEGMENTPOINTCOMPARATOR_H |