File: computeOrientationTest.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 (85 lines) | stat: -rw-r--r-- 2,438 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
// $Id: computeOrientationTest.cpp 1993 2007-06-10 11:53:49Z mloskot $
// 
// Test Suite for CGAlgorithms::computeOrientation() function
// Ported from JTS junit/algorithm/ComputeOrientationTest.java

// tut
#include <tut.h>
// geos
#include <geos/algorithm/CGAlgorithms.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/CoordinateArraySequence.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/Polygon.h>
#include <geos/io/WKTReader.h>
// std
#include <string>
#include <memory>

using namespace geos::geom;
using namespace geos::algorithm;

namespace tut
{
    //
    // Test Group
    //

    struct test_computeorientation_data
    {
        geos::io::WKTReader reader_;

        test_computeorientation_data() {}
    };

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

    group test_computeorientation_group("geos::algorithm::CGAlgorithms::computeOrientation");

    //
    // Test Cases
    //

    // 1 - Test CCW orientation
    template<>
    template<>
    void object::test<1>()
    {
        const std::string wkt("LINESTRING ( 0 0, 0 1, 1 1)");
        Geometry::AutoPtr geom(reader_.read(wkt));

        CoordinateSequence::AutoPtr pts(geom->getCoordinates());

        int const a = CGAlgorithms::computeOrientation(pts->getAt(0), pts->getAt(1), pts->getAt(2));
        int const b = CGAlgorithms::computeOrientation(pts->getAt(0), pts->getAt(1), pts->getAt(2));
        int const c = CGAlgorithms::computeOrientation(pts->getAt(0), pts->getAt(1), pts->getAt(2));

        ensure_equals( a, b );
        ensure_equals( a, c );
    }

    // 2 - Test CCW orientation
    template<>
    template<>
    void object::test<2>()
    {    
        Coordinate c1(1.0000000000004998, -7.989685402102996);
        Coordinate c2(10.0, -7.004368924503866);
        Coordinate c3(1.0000000000005, -7.989685402102996);

        CoordinateArraySequence pts;
        pts.add(c1);
        pts.add(c2);
        pts.add(c3);

        int const a = CGAlgorithms::computeOrientation(pts[0], pts[1], pts[2]);
        int const b = CGAlgorithms::computeOrientation(pts[0], pts[1], pts[2]);
        int const c = CGAlgorithms::computeOrientation(pts[0], pts[1], pts[2]);

        ensure_equals( a, b );
        ensure_equals( a, c );
    }

} // namespace tut