📄 geosalgorithm.h
字号:
/********************************************************************** * $Id: geosAlgorithm.h,v 1.9.2.1 2005/05/23 16:39:05 strk Exp $ * * GEOS - Geometry Engine Open Source * http://geos.refractions.net * * Copyright (C) 2001-2002 Vivid Solutions Inc. * Copyright (C) 2005 Refractions Research Inc. * * This is free software; you can redistribute and/or modify it under * the terms of the GNU Lesser General Public Licence as published * by the Free Software Foundation. * See the COPYING file for more information. * **********************************************************************/#ifndef GEOS_ALGORITHM_H#define GEOS_ALGORITHM_H#include <memory>#include <geos/geom.h>#include <geos/util.h>#include <geos/platform.h>#include <geos/indexBintree.h>#include <geos/indexStrtree.h>#include <geos/indexStrtree.h>#include <geos/indexChain.h>namespace geos {class Coordinate;/* * \class NotRepresentableException geosAlgorithm.h geos/geosAlgorithm.h * \brief * Indicates that a HCoordinate has been computed which is * not representable on the Cartesian plane. * * @version 1.4 * @see HCoordinate */class NotRepresentableException: public GEOSException {public: NotRepresentableException(); NotRepresentableException(string msg); ~NotRepresentableException();};class PointInRing{public: virtual ~PointInRing(){}; virtual bool isInside(const Coordinate& pt)=0;};class CGAlgorithms {public: enum { CLOCKWISE=-1, COLLINEAR, COUNTERCLOCKWISE }; enum { RIGHT=-1, LEFT, STRAIGHT }; CGAlgorithms(){}; /** * Test whether a point lies inside a ring. * The ring may be oriented in either direction. * If the point lies on the ring boundary the result * of this method is unspecified. * * This algorithm does not attempt to first check the *point against the envelope of the ring. * * @param p point to check for ring inclusion * @param ring assumed to have first point identical to last point * @return <code>true</code> if p is inside ring */ static bool isPointInRing(const Coordinate& p, const CoordinateSequence* ring); /** * Test whether a point lies on a linestring. * * @return true true if * the point is a vertex of the line or lies in the interior of a line * segment in the linestring */ static bool isOnLine(const Coordinate& p, const CoordinateSequence* pt); /* * Computes whether a ring defined by an array of Coordinate is * oriented counter-clockwise. * * - The list of points is assumed to have the first and last * points equal. * - This will handle coordinate lists which contain repeated points. * - If the ring is invalid, the answer returned may not be correct. * * * @param ring an array of coordinates forming a ring * @return <code>true</code> if the ring is oriented counter-clockwise. */ static bool isCCW(const CoordinateSequence* ring); /** * Computes the orientation of a point q to the directed line segment p1-p2. * The orientation of a point relative to a directed line segment indicates * which way you turn to get to q after travelling from p1 to p2. * * @return 1 if q is counter-clockwise from p1-p2 * @return -1 if q is clockwise from p1-p2 * @return 0 if q is collinear with p1-p2 */ static int computeOrientation(const Coordinate& p1, const Coordinate& p2, const Coordinate& q); static double distancePointLine(const Coordinate& p,const Coordinate& A,const Coordinate& B); /** * Computes the perpendicular distance from a point p * to the (infinite) line containing the points AB * * @param p the point to compute the distance for * @param A one point of the line * @param B another point of the line (must be different to A) * @return the distance from p to line AB */ static double distancePointLinePerpendicular(const Coordinate& p,const Coordinate& A,const Coordinate& B); static double distanceLineLine(const Coordinate& A, const Coordinate& B, const Coordinate& C, const Coordinate& D); static double signedArea(const CoordinateSequence* ring); /** * Computes the length of a linestring specified by a sequence of points. * * @param pts the points specifying the linestring * @return the length of the linestring */ static double length(const CoordinateSequence* pts); /** * Returns the index of the direction of the point <code>q</code> * relative to a * vector specified by <code>p1-p2</code>. * * @param p1 the origin point of the vector * @param p2 the final point of the vector * @param q the point to compute the direction to * * @return 1 if q is counter-clockwise (left) from p1-p2 * @return -1 if q is clockwise (right) from p1-p2 * @return 0 if q is collinear with p1-p2 */ static int orientationIndex(const Coordinate& p1,const Coordinate& p2,const Coordinate& q);};/// Represents a homogeneous coordinate for 2-D coordinates.class HCoordinate {public: static Coordinate* intersection(Coordinate& p1,Coordinate& p2,Coordinate& q1,Coordinate& q2); double x,y,w; HCoordinate(); HCoordinate(double _x, double _y, double _w); HCoordinate(Coordinate& p); HCoordinate(HCoordinate p1, HCoordinate p2); double getX(); double getY(); Coordinate* getCoordinate();};class SimplePointInRing: public PointInRing {public: SimplePointInRing(LinearRing *ring); virtual ~SimplePointInRing(); bool isInside(const Coordinate& pt);private: const CoordinateSequence* pts;};class LineIntersector{public: // Return a Z value being the interpolation of Z from p0 and p1 at // the given point p static double interpolateZ(const Coordinate &p, const Coordinate &p0, const Coordinate &p1); static double computeEdgeDistance(const Coordinate& p, const Coordinate& p0, const Coordinate& p1); static double nonRobustComputeEdgeDistance(const Coordinate& p,const Coordinate& p1,const Coordinate& p2); LineIntersector(); virtual ~LineIntersector(); /* * Tests whether either intersection point is an interior point of * one of the input segments. * * @return <code>true</code> if either intersection point is in * the interior of one of the input segments */ virtual bool isInteriorIntersection(); /* * Tests whether either intersection point is an interior point * of the specified input segment. * * @return <code>true</code> if either intersection point is in * the interior of the input segment */ virtual bool isInteriorIntersection(int inputLineIndex); virtual void setMakePrecise(const PrecisionModel *newPM); virtual void setPrecisionModel(const PrecisionModel *newPM); /* * Compute the intersection of a point p and the line p1-p2. * This function computes the boolean value of the hasIntersection test. * The actual value of the intersection (if there is one) * is equal to the value of <code>p</code>. */ virtual void computeIntersection(const Coordinate& p,const Coordinate& p1,const Coordinate& p2)=0; enum { DONT_INTERSECT, DO_INTERSECT, COLLINEAR }; virtual void computeIntersection(const Coordinate& p1,const Coordinate& p2,const Coordinate& p3, const Coordinate& p4); virtual string toString() const; virtual bool hasIntersection() const; virtual int getIntersectionNum() const; virtual const Coordinate& getIntersection(int intIndex) const; static bool isSameSignAndNonZero(double a,double b); virtual bool isIntersection(const Coordinate& pt) const; virtual bool isProper() const; virtual const Coordinate& getIntersectionAlongSegment(int segmentIndex,int intIndex); virtual int getIndexAlongSegment(int segmentIndex,int intIndex); virtual double getEdgeDistance(int geomIndex,int intIndex) const;protected: /** * If makePrecise is true, computed intersection coordinates will be made precise * using Coordinate#makePrecise */ const PrecisionModel *precisionModel; int result; Coordinate inputLines[2][2]; Coordinate intPt[2]; /** * The indexes of the endpoints of the intersection lines, in order along * the corresponding line */ int intLineIndex[2][2]; bool isProperVar; Coordinate pa; Coordinate pb; virtual bool isCollinear() const; virtual int computeIntersect(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2)=0; virtual bool isEndPoint() const; virtual void computeIntLineIndex(); virtual void computeIntLineIndex(int segmentIndex);};class RobustDeterminant {public: static int signOfDet2x2(double x1,double y1,double x2,double y2);};class RobustLineIntersector: public LineIntersector {public: RobustLineIntersector(); virtual ~RobustLineIntersector(); void computeIntersection(const Coordinate& p,const Coordinate& p1,const Coordinate& p2); int computeIntersect(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2);private:// bool between(Coordinate& p1,Coordinate& p2,Coordinate& q); int computeCollinearIntersection(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2); Coordinate* intersection(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2) const; void normalize(Coordinate *n1,Coordinate *n2,Coordinate *n3,Coordinate *n4,Coordinate *normPt) const; double smallestInAbsValue(double x1,double x2,double x3,double x4) const; /** * Test whether a point lies in the envelopes of both input segments. * A correctly computed intersection point should return <code>true</code> * for this test. * Since this test is for debugging purposes only, no attempt is * made to optimize the envelope test. * * @return <code>true</code> if the input point lies within both input segment envelopes */ bool isInSegmentEnvelopes(const Coordinate& intPt);};class NonRobustLineIntersector: public LineIntersector {public: NonRobustLineIntersector(); void computeIntersection(const Coordinate& p,const Coordinate& p1,const Coordinate& p2);protected: int computeIntersect(const Coordinate& p1,const Coordinate& p2,const Coordinate& p3,const Coordinate& p4);private: int computeCollinearIntersection(const Coordinate& p1,const Coordinate& p2,const Coordinate& p3,const Coordinate& p4); double rParameter(const Coordinate& p1,const Coordinate& p2,const Coordinate& p) const;};/* * Stub version of RobustCGAlgorithms for backwards compatibility. * Will be deprecated in next release - use CGAlgorithms instead. */class RobustCGAlgorithms: public CGAlgorithms {};class NonRobustCGAlgorithms: public CGAlgorithms {public: NonRobustCGAlgorithms(); ~NonRobustCGAlgorithms(); /** * Computes whether a ring defined by an array of {@link Coordinate} is * oriented counter-clockwise. * <p> * This will handle coordinate lists which contain repeated points. * * @param ring an array of coordinates forming a ring * @return <code>true</code> if the ring is oriented counter-clockwise. */ static bool isPointInRing(const Coordinate& p, const CoordinateSequence* ring);// static bool isOnLine(const Coordinate& p, const CoordinateSequence* pt) const; /** * Computes whether a ring defined by an array of {@link Coordinate} is * oriented counter-clockwise. * <p> * This will handle coordinate lists which contain repeated points. * * @param ring an array of coordinates forming a ring * @return <code>true</code> if the ring is oriented counter-clockwise. * @throws IllegalArgumentException if the ring is degenerate (does not contain 3 different points) */ static bool isCCW(const CoordinateSequence* ring); static int computeOrientation(const Coordinate& p1,const Coordinate& p2,const Coordinate& q);};class SimplePointInAreaLocator {public: static int locate(const Coordinate& p, const Geometry *geom); static bool containsPointInPolygon(const Coordinate& p,const Polygon *poly);private: static bool containsPoint(const Coordinate& p,const Geometry *geom);};/* * \class PointLocator geosAlgorithm.h geos/geosAlgorithm.h * * \brief
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -