⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 offsetpointgeneratortest.cpp

📁 在Linux下做的QuadTree的程序
💻 CPP
字号:
// $Id: OffsetPointGeneratorTest.cpp 1982 2007-06-01 13:43:59Z mloskot $// // Test Suite for geos::operation::overlay::OffsetPointGenerator class.// TUT#include <tut.h>// GEOS#include <geos/operation/overlay/OffsetPointGenerator.h>#include <geos/geom/GeometryFactory.h>#include <geos/geom/Point.h>#include <geos/geom/Geometry.h>#include <geos/algorithm/PointLocator.h>#include <geos/io/WKTReader.h>#include <geos/geom/Coordinate.h>#include <memory>#include <vector>namespace tut{	using namespace std;	using namespace geos::geom;	//	// Test Group	//	// Common data used by tests	struct test_offsetpointgenerator_data	{		geos::geom::GeometryFactory gf;		geos::io::WKTReader wktreader;		geos::algorithm::PointLocator locator;		typedef geos::geom::Geometry::AutoPtr GeomPtr;		GeomPtr g;		test_offsetpointgenerator_data()			:			gf(),			wktreader(&gf)		{		}		bool		pointsWithinDistance(vector<Coordinate>& coords, double dist)		{			// we expect some numerical instability here			// OffsetPointGenerator could produce points			// at *slightly* farther locations then			// requested			//			dist *= 1.0000001;			for (size_t i=0, n=coords.size(); i<n; ++i)			{				const Coordinate& c = coords[i];				auto_ptr<Geometry> pg(gf.createPoint(c));				double rdist =  g->distance(pg.get());				if ( rdist > dist )				{					return false;				}			}			return true;		}	};		typedef test_group<test_offsetpointgenerator_data> group;	typedef group::object object;	group test_offsetpointgenerator_group("geos::operation::overlay::OffsetPointGenerator");	//	// Test Cases	//	template<>	template<>	void object::test<1>()	{		using geos::operation::overlay::OffsetPointGenerator;		using geos::geom::Coordinate;		using geos::algorithm::PointLocator;		using std::auto_ptr;		using std::vector;		std::string wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))");		g.reset(wktreader.read(wkt));		double dist = 10;		OffsetPointGenerator gen(*g, dist);		auto_ptr< vector<Coordinate> > coords(gen.getPoints());		ensure_equals(coords->size(), (g->getNumPoints()-1)*2);		ensure(pointsWithinDistance(*coords, dist));	}	template<>	template<>	void object::test<2>()	{		using geos::operation::overlay::OffsetPointGenerator;		using geos::geom::Location;		using geos::geom::Coordinate;		using std::auto_ptr;		using std::vector;		std::string wkt("POLYGON((0 0, 10 0, 10 5, 10 10, 0 10, 0 0))");		g.reset(wktreader.read(wkt));		double dist = 0.0003;		OffsetPointGenerator gen(*g, dist);		auto_ptr< vector<Coordinate> > coords(gen.getPoints());		ensure_equals(coords->size(), 10u);		ensure(pointsWithinDistance(*coords, dist));	}	template<>	template<>	void object::test<3>()	{		using geos::operation::overlay::OffsetPointGenerator;		using geos::geom::Location;		using geos::geom::Coordinate;		using std::auto_ptr;		using std::vector;		std::string wkt("POINT(10 -10)");		g.reset(wktreader.read(wkt));		double dist = 0.0003;		OffsetPointGenerator gen(*g, dist);		auto_ptr< vector<Coordinate> > coords(gen.getPoints());		ensure_equals(coords->size(), 0u);		//ensure(pointsWithinDistance(*coords, dist));	}	template<>	template<>	void object::test<4>()	{		using geos::operation::overlay::OffsetPointGenerator;		using geos::geom::Location;		using geos::geom::Coordinate;		using std::auto_ptr;		using std::vector;		std::string wkt("LINESTRING(10 -10, 5 600)");		g.reset(wktreader.read(wkt));		double dist = 0.03;		OffsetPointGenerator gen(*g, dist);		auto_ptr< vector<Coordinate> > coords(gen.getPoints());		ensure_equals(coords->size(), 2u);		ensure(pointsWithinDistance(*coords, dist));	}	template<>	template<>	void object::test<5>()	{		using geos::operation::overlay::OffsetPointGenerator;		using geos::geom::Location;		using geos::geom::Coordinate;		using std::auto_ptr;		using std::vector;		std::string wkt("MULTILINESTRING((10 -10, 5 600), (1045 -12, 0 0, -435 34))");		g.reset(wktreader.read(wkt));		double dist = 0.2;		OffsetPointGenerator gen(*g, dist);		auto_ptr< vector<Coordinate> > coords(gen.getPoints());		ensure_equals(coords->size(), 6u);		ensure(pointsWithinDistance(*coords, dist));	}} // namespace tut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -