GEOS 3.6.2
SegmentPointComparator.h
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 <geos/export.h>
23#include <geos/geom/Coordinate.h>
24#include <cassert>
25
26namespace geos {
27namespace noding { // geos.noding
28
39class GEOS_DLL SegmentPointComparator {
40
41public:
42
51 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 if (p0.equals2D(p1)) return 0;
56
57 int xSign = relativeSign(p0.x, p1.x);
58 int ySign = relativeSign(p0.y, p1.y);
59
60 switch (octant) {
61 case 0: return compareValue(xSign, ySign);
62 case 1: return compareValue(ySign, xSign);
63 case 2: return compareValue(ySign, -xSign);
64 case 3: return compareValue(-xSign, ySign);
65 case 4: return compareValue(-xSign, -ySign);
66 case 5: return compareValue(-ySign, -xSign);
67 case 6: return compareValue(-ySign, xSign);
68 case 7: return compareValue(xSign, -ySign);
69 }
70 assert(0); // invalid octant value
71 return 0;
72
73 }
74
75 static int relativeSign(double x0, double x1)
76 {
77 if (x0 < x1) return -1;
78 if (x0 > x1) return 1;
79 return 0;
80 }
81
82 static int compareValue(int compareSign0, int compareSign1)
83 {
84 if (compareSign0 < 0) return -1;
85 if (compareSign0 > 0) return 1;
86 if (compareSign1 < 0) return -1;
87 if (compareSign1 > 0) return 1;
88 return 0;
89 }
90
91};
92
93} // namespace geos.noding
94} // namespace geos
95
96#endif // GEOS_NODING_SEGMENTPOINTCOMPARATOR_H
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
double y
y-coordinate
Definition Coordinate.h:83
double x
x-coordinate
Definition Coordinate.h:80
Definition SegmentPointComparator.h:39
static int compare(int octant, const geom::Coordinate &p0, const geom::Coordinate &p1)
Definition SegmentPointComparator.h:51
Classes to compute nodings for arrangements of line segments and line segment sequences.
Definition PreparedLineString.h:27
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25