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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// $Id: GEOSNearestPointsTest.cpp 2424 2009-04-29 23:52:36Z mloskot $
//
// Test Suite for C-API GEOSNearestPoints
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include "capi_test_utils.h"
namespace tut {
//
// Test Group
//
// Common data used in test cases.
struct test_capigeosnearestpoints_data : public capitest::utility {
void checkNearestPoints(const char* wkt1, const char* wkt2,
double x1, double y1,
double x2, double y2)
{
geom1_ = GEOSGeomFromWKT(wkt1);
ensure(nullptr != geom1_);
geom2_ = GEOSGeomFromWKT(wkt2);
ensure(nullptr != geom2_);
GEOSCoordSequence* coords_ = GEOSNearestPoints(geom1_, geom2_);
unsigned int size;
GEOSCoordSeq_getSize(coords_, &size);
ensure_equals("CoordSeq size", size, 2u);
double ox, oy;
/* Point in geom1_ */
GEOSCoordSeq_getOrdinate(coords_, 0, 0, &ox);
GEOSCoordSeq_getOrdinate(coords_, 0, 1, &oy);
ensure_equals("P1 x", ox, x1);
ensure_equals("P1 y", oy, y1);
/* Point in geom2_ */
GEOSCoordSeq_getOrdinate(coords_, 1, 0, &ox);
GEOSCoordSeq_getOrdinate(coords_, 1, 1, &oy);
ensure_equals("P2 x", ox, x2);
ensure_equals("P2 y", oy, y2);
GEOSCoordSeq_destroy(coords_);
}
void checkNearestPointsNull(const char* wkt1, const char* wkt2)
{
geom1_ = GEOSGeomFromWKT(wkt1);
ensure(nullptr != geom1_);
geom2_ = GEOSGeomFromWKT(wkt2);
ensure(nullptr != geom2_);
GEOSCoordSequence* coords_ = GEOSNearestPoints(geom1_, geom2_);
ensure(nullptr == coords_);
}
};
typedef test_group<test_capigeosnearestpoints_data> group;
typedef group::object object;
group test_capigeosnearestpoints_group("capi::GEOSNearestPoints");
//
// Test Cases
//
template<>
template<>
void object::test<1>
()
{
checkNearestPointsNull("POLYGON EMPTY", "POLYGON EMPTY");
}
template<>
template<>
void object::test<2>
()
{
checkNearestPoints(
"POLYGON((1 1,1 5,5 5,5 1,1 1))",
"POLYGON((8 8, 9 9, 9 10, 8 8))",
5, 5, 8, 8
);
}
template<>
template<>
void object::test<3>
()
{
checkNearestPoints(
"POLYGON((1 1,1 5,5 5,5 1,1 1))",
"POINT(2 2)",
2, 2, 2, 2
);
}
template<>
template<>
void object::test<4>
()
{
checkNearestPoints(
"LINESTRING(1 5,5 5,5 1,1 1)",
"POINT(2 2)",
2, 1, 2, 2
);
}
template<>
template<>
void object::test<5>
()
{
checkNearestPoints(
"LINESTRING(0 0,10 10)",
"LINESTRING(0 10,10 0)",
5, 5, 5, 5
);
}
template<>
template<>
void object::test<6>
()
{
checkNearestPoints(
"POLYGON((0 0,10 0,10 10,0 10,0 0))",
"LINESTRING(8 5,12 5)",
/* But could also be the intersection point... */
8, 5, 8, 5
);
}
} // namespace tut
|