| 1 | // $Id: isPointInRingTest.cpp 2344 2009-04-09 21:46:30Z mloskot $
|
|---|
| 2 | //
|
|---|
| 3 | // Test Suite for CGAlgorithms::isPointInRing() function
|
|---|
| 4 |
|
|---|
| 5 | // tut
|
|---|
| 6 | #include <tut.hpp>
|
|---|
| 7 | // geos
|
|---|
| 8 | #include <geos/algorithm/CGAlgorithms.h>
|
|---|
| 9 | #include <geos/geom/Polygon.h>
|
|---|
| 10 | #include <geos/geom/Geometry.h>
|
|---|
| 11 | #include <geos/geom/CoordinateSequence.h>
|
|---|
| 12 | #include <geos/geom/Coordinate.h>
|
|---|
| 13 | #include <geos/io/WKTReader.h>
|
|---|
| 14 | // std
|
|---|
| 15 | #include <string>
|
|---|
| 16 | #include <cassert>
|
|---|
| 17 |
|
|---|
| 18 | using namespace geos::algorithm;
|
|---|
| 19 |
|
|---|
| 20 | namespace tut
|
|---|
| 21 | {
|
|---|
| 22 | //
|
|---|
| 23 | // Test Group
|
|---|
| 24 | //
|
|---|
| 25 |
|
|---|
| 26 | struct test_ispointinring_data
|
|---|
| 27 | {
|
|---|
| 28 | typedef std::auto_ptr<geos::geom::Geometry> GeomPtr;
|
|---|
| 29 |
|
|---|
| 30 | geos::geom::CoordinateSequence* cs_;
|
|---|
| 31 | geos::io::WKTReader reader_;
|
|---|
| 32 |
|
|---|
| 33 | test_ispointinring_data()
|
|---|
| 34 | : cs_(0)
|
|---|
| 35 | {
|
|---|
| 36 | assert(0 == cs_);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | ~test_ispointinring_data()
|
|---|
| 40 | {
|
|---|
| 41 | delete cs_;
|
|---|
| 42 | cs_ = 0;
|
|---|
| 43 | }
|
|---|
| 44 | };
|
|---|
| 45 |
|
|---|
| 46 | typedef test_group<test_ispointinring_data> group;
|
|---|
| 47 | typedef group::object object;
|
|---|
| 48 |
|
|---|
| 49 | group test_ispointintring_group("geos::algorithm::CGAlgorithms::isPointInRing");
|
|---|
| 50 |
|
|---|
| 51 | //
|
|---|
| 52 | // Test Cases
|
|---|
| 53 | //
|
|---|
| 54 |
|
|---|
| 55 | // Test of point in simple Polygon
|
|---|
| 56 | template<>
|
|---|
| 57 | template<>
|
|---|
| 58 | void object::test<1>()
|
|---|
| 59 | {
|
|---|
| 60 | const std::string wkt("POLYGON ((0 0, 0 20, 20 20, 20 0, 0 0))");
|
|---|
| 61 | GeomPtr geom(reader_.read(wkt));
|
|---|
| 62 |
|
|---|
| 63 | geos::geom::Coordinate pt(10, 10);
|
|---|
| 64 |
|
|---|
| 65 | cs_ = geom->getCoordinates();
|
|---|
| 66 | bool isInRing = CGAlgorithms::isPointInRing(pt, cs_);
|
|---|
| 67 |
|
|---|
| 68 | ensure_equals( true, isInRing );
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | // Test of point in bigger Polygon
|
|---|
| 72 | template<>
|
|---|
| 73 | template<>
|
|---|
| 74 | void object::test<2>()
|
|---|
| 75 | {
|
|---|
| 76 | const std::string wkt("POLYGON ((-40 80, -40 -80, 20 0, 20 -100, 40 40, \
|
|---|
| 77 | 80 -80, 100 80, 140 -20, 120 140, 40 180, 60 40, \
|
|---|
| 78 | 0 120, -20 -20, -40 80))");
|
|---|
| 79 | GeomPtr geom(reader_.read(wkt));
|
|---|
| 80 |
|
|---|
| 81 | geos::geom::Coordinate pt(0, 0);
|
|---|
| 82 |
|
|---|
| 83 | cs_ = geom->getCoordinates();
|
|---|
| 84 | bool isInRing = CGAlgorithms::isPointInRing(pt, cs_);
|
|---|
| 85 |
|
|---|
| 86 | ensure_equals( true, isInRing );
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | } // namespace tut
|
|---|
| 90 |
|
|---|