1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2001-2002 Vivid Solutions Inc.
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.
13 **********************************************************************
15 * Last port: geomgraph/Quadrant.java rev. 1.8 (JTS-1.10)
17 **********************************************************************/
21 #include <geos/geomgraph/Quadrant.h>
22 #include <geos/util/IllegalArgumentException.h>
24 #include <geos/geom/Coordinate.h>
27 using namespace geos::geom
;
30 namespace geomgraph
{ // geos.geomgraph
34 Quadrant::quadrant(double dx
, double dy
)
36 if (dx
== 0.0 && dy
== 0.0) {
38 s
<<"Cannot compute the quadrant for point ";
39 s
<<"("<<dx
<<","<<dy
<<")"<<endl
;
40 throw util::IllegalArgumentException(s
.str());
57 Quadrant::quadrant(const Coordinate
& p0
, const Coordinate
& p1
)
59 if (p1
.x
== p0
.x
&& p1
.y
== p0
.y
)
61 throw util::IllegalArgumentException("Cannot compute the quadrant for two identical points " + p0
.toString());
80 Quadrant::isOpposite(int quad1
, int quad2
)
82 if (quad1
==quad2
) return false;
83 int diff
=(quad1
-quad2
+4)%4;
84 // if quadrants are not adjacent, they are opposite
85 if (diff
==2) return true;
91 Quadrant::commonHalfPlane(int quad1
, int quad2
)
93 // if quadrants are the same they do not determine a unique
95 // Simply return one of the two possibilities
96 if (quad1
==quad2
) return quad1
;
97 int diff
=(quad1
-quad2
+4)%4;
98 // if quadrants are not adjacent, they do not share a common halfplane
99 if (diff
==2) return -1;
101 int min
=(quad1
<quad2
)? quad1
:quad2
;
102 int max
=(quad1
>quad2
)? quad1
:quad2
;
103 // for this one case, the righthand plane is NOT the minimum index;
104 if (min
==0 && max
==3) return 3;
105 // in general, the halfplane index is the minimum of the two
106 // adjacent quadrants
112 Quadrant::isInHalfPlane(int quad
, int halfPlane
)
115 return quad
==SE
|| quad
==SW
;
117 return quad
==halfPlane
|| quad
==halfPlane
+1;
122 Quadrant::isNorthern(int quad
)
124 return quad
==NE
|| quad
==NW
;
127 } // namespace geos.geomgraph
130 /**********************************************************************
132 * Revision 1.10 2006/03/15 17:16:29 strk
133 * streamlined headers inclusion
135 * Revision 1.9 2006/03/09 16:46:47 strk
136 * geos::geom namespace definition, first pass at headers split
138 * Revision 1.8 2006/03/06 19:40:46 strk
139 * geos::util namespace. New GeometryCollection::iterator interface, many cleanups.
141 * Revision 1.7 2006/03/03 10:46:21 strk
142 * Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46)
144 * Revision 1.6 2006/02/19 19:46:49 strk
145 * Packages <-> namespaces mapping for most GEOS internal code (uncomplete, but working). Dir-level libs for index/ subdirs.
147 * Revision 1.5 2006/02/09 15:52:47 strk
148 * GEOSException derived from std::exception; always thrown and cought by const ref.
150 * Revision 1.4 2005/02/05 05:44:47 strk
151 * Changed geomgraph nodeMap to use Coordinate pointers as keys, reduces
152 * lots of other Coordinate copies.
154 * Revision 1.3 2005/01/28 09:47:51 strk
155 * Replaced sprintf uses with ostringstream.
157 * Revision 1.2 2004/07/02 13:28:26 strk
158 * Fixed all #include lines to reflect headers layout change.
159 * Added client application build tips in README.
161 * Revision 1.1 2004/03/19 09:48:45 ybychkov
162 * "geomgraph" and "geomgraph/indexl" upgraded to JTS 1.4
164 * Revision 1.10 2003/11/07 01:23:42 pramsey
165 * Add standard CVS headers licence notices and copyrights to all cpp and h
169 **********************************************************************/