1 /********************************************************************** 2 * 3 * GEOS - Geometry Engine Open Source 4 * http://geos.osgeo.org 5 * 6 * Copyright (C) 2001-2002 Vivid Solutions 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: geom/Quadrant.java rev. 1.8 (JTS-1.10) 16 * 17 **********************************************************************/ 18 19 #include <geos/geom/Quadrant.h> 20 21 #ifndef GEOS_INLINE 22 # include <geos/geom/Quadrant.inl> 23 #endif 24 25 using namespace geos::geom; 26 27 namespace geos { 28 namespace geom { // geos.geom 29 30 /* public static */ 31 int commonHalfPlane(int quad1,int quad2)32Quadrant::commonHalfPlane(int quad1, int quad2) 33 { 34 // if quadrants are the same they do not determine a unique 35 // common halfplane. 36 // Simply return one of the two possibilities 37 if(quad1 == quad2) { 38 return quad1; 39 } 40 int diff = (quad1 - quad2 + 4) % 4; 41 // if quadrants are not adjacent, they do not share a common halfplane 42 if(diff == 2) { 43 return -1; 44 } 45 // 46 int min = (quad1 < quad2) ? quad1 : quad2; 47 int max = (quad1 > quad2) ? quad1 : quad2; 48 // for this one case, the righthand plane is NOT the minimum index; 49 if(min == 0 && max == 3) { 50 return 3; 51 } 52 // in general, the halfplane index is the minimum of the two 53 // adjacent quadrants 54 return min; 55 } 56 57 /* public static */ 58 bool isInHalfPlane(int quad,int halfPlane)59Quadrant::isInHalfPlane(int quad, int halfPlane) 60 { 61 if(halfPlane == SE) { 62 return quad == SE || quad == SW; 63 } 64 return quad == halfPlane || quad == halfPlane + 1; 65 } 66 67 68 } // namespace geos.geom 69 } // namespace geos 70