File: isPointInRingTest.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (87 lines) | stat: -rw-r--r-- 1,832 bytes parent folder | download | duplicates (4)
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
//
// Test Suite for PointLocation::isInRing() function

// tut
#include <tut/tut.hpp>
// geos
#include <geos/algorithm/PointLocation.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/Coordinate.h>
#include <geos/io/WKTReader.h>
// std
#include <string>
#include <cassert>

using namespace geos::algorithm;

namespace tut {
//
// Test Group
//

struct test_ispointinring_data {
    typedef std::unique_ptr<geos::geom::Geometry> GeomPtr;

    std::unique_ptr<geos::geom::CoordinateSequence> cs_;
    geos::io::WKTReader reader_;

    test_ispointinring_data()
        : cs_(nullptr)
    {
        assert(nullptr == cs_);
    }

    ~test_ispointinring_data()
    {
    }
};

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

group test_ispointintring_group("geos::algorithm::CGAlgorithms::isPointInRing");

//
// Test Cases
//

// Test of point in simple Polygon
template<>
template<>
void object::test<1>
()
{
    const std::string wkt("POLYGON ((0 0, 0 20, 20 20, 20 0, 0 0))");
    GeomPtr geom(reader_.read(wkt));

    geos::geom::Coordinate pt(10, 10);

    cs_ = geom->getCoordinates();
    bool isInRing = PointLocation::isInRing(pt, cs_.get());

    ensure_equals(true, isInRing);
}

// Test of point in bigger Polygon
template<>
template<>
void object::test<2>
()
{
    const std::string wkt("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))");
    GeomPtr geom(reader_.read(wkt));

    geos::geom::Coordinate pt(0, 0);

    cs_ = geom->getCoordinates();
    bool isInRing = PointLocation::isInRing(pt, cs_.get());

    ensure_equals(true, isInRing);
}

} // namespace tut