| 1 | // $Id: isCCWTest.cpp 3288 2011-04-19 07:57:14Z strk $
|
|---|
| 2 | //
|
|---|
| 3 | // Test Suite for CGAlgorithms::isCCW() function
|
|---|
| 4 | // Ported from JTS junit/algorithm/IsCCWTest.java
|
|---|
| 5 |
|
|---|
| 6 | // tut
|
|---|
| 7 | #include <tut.hpp>
|
|---|
| 8 | // geos
|
|---|
| 9 | #include <geos/algorithm/CGAlgorithms.h>
|
|---|
| 10 | #include <geos/geom/Polygon.h>
|
|---|
| 11 | #include <geos/geom/Geometry.h>
|
|---|
| 12 | #include <geos/geom/CoordinateSequence.h>
|
|---|
| 13 | #include <geos/geom/Coordinate.h>
|
|---|
| 14 | #include <geos/io/WKTReader.h>
|
|---|
| 15 | #include <geos/io/WKBReader.h>
|
|---|
| 16 | // std
|
|---|
| 17 | #include <string>
|
|---|
| 18 | #include <memory>
|
|---|
| 19 | #include <cassert>
|
|---|
| 20 | #include <sstream>
|
|---|
| 21 |
|
|---|
| 22 | using namespace geos::algorithm;
|
|---|
| 23 |
|
|---|
| 24 | namespace tut
|
|---|
| 25 | {
|
|---|
| 26 | //
|
|---|
| 27 | // Test Group
|
|---|
| 28 | //
|
|---|
| 29 |
|
|---|
| 30 | struct test_isccw_data
|
|---|
| 31 | {
|
|---|
| 32 | typedef std::auto_ptr<geos::geom::Geometry> GeometryPtr;
|
|---|
| 33 |
|
|---|
| 34 | geos::geom::CoordinateSequence* cs_;
|
|---|
| 35 | geos::io::WKTReader reader_;
|
|---|
| 36 | geos::io::WKBReader breader_;
|
|---|
| 37 |
|
|---|
| 38 | test_isccw_data()
|
|---|
| 39 | : cs_(0)
|
|---|
| 40 | {
|
|---|
| 41 | assert(0 == cs_);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | ~test_isccw_data()
|
|---|
| 45 | {
|
|---|
| 46 | delete cs_;
|
|---|
| 47 | cs_ = 0;
|
|---|
| 48 | }
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | typedef test_group<test_isccw_data> group;
|
|---|
| 52 | typedef group::object object;
|
|---|
| 53 |
|
|---|
| 54 | group test_isccw_group("geos::algorithm::CGAlgorithms::isCCW");
|
|---|
| 55 |
|
|---|
| 56 | //
|
|---|
| 57 | // Test Cases
|
|---|
| 58 | //
|
|---|
| 59 |
|
|---|
| 60 | // 1 - Test if coordinates of polygon are counter-clockwise oriented
|
|---|
| 61 | template<>
|
|---|
| 62 | template<>
|
|---|
| 63 | void object::test<1>()
|
|---|
| 64 | {
|
|---|
| 65 | const std::string wkt("POLYGON ((60 180, 140 240, 140 240, 140 240, 200 180, 120 120, 60 180))");
|
|---|
| 66 | GeometryPtr geom(reader_.read(wkt));
|
|---|
| 67 |
|
|---|
| 68 | cs_ = geom->getCoordinates();
|
|---|
| 69 | bool isCCW = CGAlgorithms::isCCW(cs_);
|
|---|
| 70 |
|
|---|
| 71 | ensure_equals( false, isCCW );
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | // 2 - Test if coordinates of polygon are counter-clockwise oriented
|
|---|
| 75 | template<>
|
|---|
| 76 | template<>
|
|---|
| 77 | void object::test<2>()
|
|---|
| 78 | {
|
|---|
| 79 | const std::string wkt("POLYGON ((60 180, 140 120, 100 180, 140 240, 60 180))");
|
|---|
| 80 | GeometryPtr geom(reader_.read(wkt));
|
|---|
| 81 |
|
|---|
| 82 | cs_ = geom->getCoordinates();
|
|---|
| 83 | bool isCCW = CGAlgorithms::isCCW(cs_);
|
|---|
| 84 |
|
|---|
| 85 | ensure_equals( true, isCCW );
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | // 3 - Test the same polygon as in test No 2 but with duplicated top point
|
|---|
| 89 | template<>
|
|---|
| 90 | template<>
|
|---|
| 91 | void object::test<3>()
|
|---|
| 92 | {
|
|---|
| 93 | const std::string wkt("POLYGON ((60 180, 140 120, 100 180, 140 240, 140 240, 60 180))");
|
|---|
| 94 | GeometryPtr geom(reader_.read(wkt));
|
|---|
| 95 |
|
|---|
| 96 | cs_ = geom->getCoordinates();
|
|---|
| 97 | bool isCCW = CGAlgorithms::isCCW(cs_);
|
|---|
| 98 |
|
|---|
| 99 | ensure_equals( true, isCCW );
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | // 4 - Test orientation the narrow (almost collapsed) ring
|
|---|
| 103 | // resulting in GEOS during execution of the union described
|
|---|
| 104 | // in http://trac.osgeo.org/geos/ticket/398
|
|---|
| 105 | template<>
|
|---|
| 106 | template<>
|
|---|
| 107 | void object::test<4>()
|
|---|
| 108 | {
|
|---|
| 109 | std::istringstream wkt("0102000000040000000000000000000000841D588465963540F56BFB214F0341408F26B714B2971B40F66BFB214F0341408C26B714B2971B400000000000000000841D588465963540");
|
|---|
| 110 | GeometryPtr geom(breader_.readHEX(wkt));
|
|---|
| 111 | cs_ = geom->getCoordinates();
|
|---|
| 112 | bool isCCW = CGAlgorithms::isCCW(cs_);
|
|---|
| 113 | ensure_equals( isCCW, false );
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | // 5 - Test orientation the narrow (almost collapsed) ring
|
|---|
| 117 | // resulting in JTS during execution of the union described
|
|---|
| 118 | // in http://trac.osgeo.org/geos/ticket/398
|
|---|
| 119 | template<>
|
|---|
| 120 | template<>
|
|---|
| 121 | void object::test<5>()
|
|---|
| 122 | {
|
|---|
| 123 | std::istringstream wkt("0102000000040000000000000000000000841D588465963540F56BFB214F0341408F26B714B2971B40F66BFB214F0341408E26B714B2971B400000000000000000841D588465963540");
|
|---|
| 124 | GeometryPtr geom(breader_.readHEX(wkt));
|
|---|
| 125 | cs_ = geom->getCoordinates();
|
|---|
| 126 | bool isCCW = CGAlgorithms::isCCW(cs_);
|
|---|
| 127 | ensure_equals( isCCW, true );
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | } // namespace tut
|
|---|
| 131 |
|
|---|