File: PointLocatorTest.cpp

package info (click to toggle)
geos 3.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 10,060 kB
  • ctags: 8,674
  • sloc: cpp: 64,513; xml: 23,384; sh: 8,965; ruby: 1,295; makefile: 1,124; python: 824; ansic: 289
file content (103 lines) | stat: -rw-r--r-- 2,403 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// $Id: PointLocatorTest.cpp 1842 2006-09-07 15:28:03Z strk $
// 
// Test Suite for geos::algorithm::PointLocator 
// Ported from JTS junit/algorithm/PointLocator.java

// TUT
#include <tut.h>
// GEOS
#include <geos/io/WKTReader.h>
#include <geos/algorithm/PointLocator.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Geometry.h> // required for use in auto_ptr
#include <geos/geom/Coordinate.h>
#include <sstream>
#include <memory>

namespace geos {
	namespace geom {
		class Geometry;
	}
}

using namespace geos::geom; // for Location

namespace tut
{
	//
	// Test Group
	//

	// dummy data, not used
	struct test_pointlocator_data {};

	typedef test_group<test_pointlocator_data> group;
	typedef group::object object;

	group test_pointlocator_group("geos::algorithm::PointLocator");

	// These are static to avoid namespace pollution
	// The struct test_*_data above is probably there
	// for the same reason...
	//
	static PrecisionModel pm;
	static GeometryFactory gf(&pm);
        static geos::io::WKTReader reader(&gf);

	typedef std::auto_ptr<Geometry> GeomPtr;

	void runPtLocator(int expected, const Coordinate& pt,
			const std::string& wkt)
	{
		GeomPtr geom(reader.read(wkt));
		geos::algorithm::PointLocator pointLocator;
		int loc = pointLocator.locate(pt, geom.get());
		ensure_equals(loc, expected);
	}


	//
	// Test Cases
	//

	// 1 - Test box
	template<>
	template<>
	void object::test<1>()
	{         
		runPtLocator(Location::INTERIOR, Coordinate(10, 10),
		    "POLYGON ((0 0, 0 20, 20 20, 20 0, 0 0))");
	}

	// 2 - Test complex ring
	template<>
	template<>
	void object::test<2>()
	{         
		runPtLocator(Location::INTERIOR, Coordinate(0, 0),
			"POLYGON ((-40 80, -40 -80, 20 0, 20 -100, 40 40, 80 -80, 100 80, 140 -20, 120 140, 40 180,     60 40, 0 120, -20 -20, -40 80))");
	}

	// 3 - Test PointLocator LinearRing LineString
	template<>
	template<>
	void object::test<3>()
	{         
		runPtLocator(Location::BOUNDARY, Coordinate(0, 0),
                     "GEOMETRYCOLLECTION( LINESTRING(0 0, 10 10), LINEARRING(10 10, 10 20, 20 10, 10 10))");
	}

	// 4 - Test PointLocator Point inside LinearRing
	template<>
	template<>
	void object::test<4>()
	{         
	    runPtLocator(Location::EXTERIOR, Coordinate(11, 11),
	                     "LINEARRING(10 10, 10 20, 20 10, 10 10)");
	}
		      


} // namespace tut