[geos-commits] [SCM] GEOS branch master updated. d1a55313b602b600d2e568336581b5d90fe8482e
git at osgeo.org
git at osgeo.org
Fri Nov 13 07:11:08 PST 2020
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, master has been updated
via d1a55313b602b600d2e568336581b5d90fe8482e (commit)
from 91e9df7650fd56409e383331d4a199996b4944d0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d1a55313b602b600d2e568336581b5d90fe8482e
Author: Sandro Santilli <strk at kbt.io>
Date: Fri Nov 13 16:08:15 2020 +0100
Simplify and improve NearestPoint CAPI tests
diff --git a/tests/unit/capi/GEOSNearestPointsTest.cpp b/tests/unit/capi/GEOSNearestPointsTest.cpp
index 1b7a6f2..17cb706 100644
--- a/tests/unit/capi/GEOSNearestPointsTest.cpp
+++ b/tests/unit/capi/GEOSNearestPointsTest.cpp
@@ -48,6 +48,48 @@ struct test_capigeosnearestpoints_data {
finishGEOS();
}
+ 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(size, 2u);
+
+ double ox, oy;
+
+ /* Point in geom1_ */
+ GEOSCoordSeq_getOrdinate(coords_, 0, 0, &ox);
+ GEOSCoordSeq_getOrdinate(coords_, 0, 1, &oy);
+ ensure_equals(ox, x1);
+ ensure_equals(oy, y1);
+
+ /* Point in geom2_ */
+ GEOSCoordSeq_getOrdinate(coords_, 1, 0, &ox);
+ GEOSCoordSeq_getOrdinate(coords_, 1, 1, &oy);
+ ensure_equals(ox, x2);
+ ensure_equals(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;
@@ -64,16 +106,7 @@ template<>
void object::test<1>
()
{
- geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
- geom2_ = GEOSGeomFromWKT("POLYGON EMPTY");
-
- ensure(nullptr != geom1_);
- ensure(nullptr != geom2_);
-
- GEOSCoordSequence* coords_;
- coords_ = GEOSNearestPoints(geom1_, geom2_);
-
- ensure(nullptr == coords_);
+ checkNearestPointsNull("POLYGON EMPTY", "POLYGON EMPTY");
}
template<>
@@ -81,40 +114,12 @@ template<>
void object::test<2>
()
{
- geom1_ = GEOSGeomFromWKT("POLYGON((1 1,1 5,5 5,5 1,1 1))");
- // geom2_ = GEOSGeomFromWKT("POINT(8 8)");
- geom2_ = GEOSGeomFromWKT("POLYGON((8 8, 9 9, 9 10, 8 8))");
-
- ensure(nullptr != geom1_);
- ensure(nullptr != geom2_);
-
- GEOSCoordSequence* coords_;
- coords_ = GEOSNearestPoints(geom1_, geom2_);
-
- ensure(nullptr != coords_);
-
- unsigned int size;
- GEOSCoordSeq_getSize(coords_, &size);
- ensure(2 == size);
-
- double x1, x2, y1, y2;
-
- /* Point in geom1_
- */
- GEOSCoordSeq_getOrdinate(coords_, 0, 0, &x1);
- GEOSCoordSeq_getOrdinate(coords_, 0, 1, &y1);
-
- /* Point in geom2_
- */
- GEOSCoordSeq_getOrdinate(coords_, 1, 0, &x2);
- GEOSCoordSeq_getOrdinate(coords_, 1, 1, &y2);
+ 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
+ );
- ensure(5 == x1);
- ensure(5 == y1);
- ensure(8 == x2);
- ensure(8 == y2);
-
- GEOSCoordSeq_destroy(coords_);
}
template<>
@@ -122,39 +127,36 @@ template<>
void object::test<3>
()
{
- geom1_ = GEOSGeomFromWKT("POLYGON((1 1,1 5,5 5,5 1,1 1))");
- geom2_ = GEOSGeomFromWKT("POINT(2 2)");
-
- ensure(nullptr != geom1_);
- ensure(nullptr != geom2_);
-
- GEOSCoordSequence* coords_;
- coords_ = GEOSNearestPoints(geom1_, geom2_);
-
- ensure(nullptr != coords_);
-
- unsigned int size;
- GEOSCoordSeq_getSize(coords_, &size);
- ensure(2 == size);
+ checkNearestPoints(
+ "POLYGON((1 1,1 5,5 5,5 1,1 1))",
+ "POINT(2 2)",
+ 2, 2, 2, 2
+ );
- double x1, x2, y1, y2;
-
- /* Point in geom1_
- */
- GEOSCoordSeq_getOrdinate(coords_, 0, 0, &x1);
- GEOSCoordSeq_getOrdinate(coords_, 0, 1, &y1);
-
- /* Point in geom2_
- */
- GEOSCoordSeq_getOrdinate(coords_, 1, 0, &x2);
- GEOSCoordSeq_getOrdinate(coords_, 1, 1, &y2);
+}
- ensure(2 == x1);
- ensure(2 == y1);
- ensure(2 == x2);
- ensure(2 == y2);
+template<>
+template<>
+void object::test<4>
+()
+{
+ checkNearestPoints(
+ "LINESTRING(1 5,5 5,5 1,1 1)",
+ "POINT(2 2)",
+ 2, 1, 2, 2
+ );
+}
- GEOSCoordSeq_destroy(coords_);
+template<>
+template<>
+void object::test<5>
+()
+{
+ checkNearestPoints(
+ "LINESTRING(0 0,10 10)",
+ "LINESTRING(0 10,10 0)",
+ 5, 5, 5, 5
+ );
}
} // namespace tut
diff --git a/tests/unit/capi/GEOSPreparedNearestPointsTest.cpp b/tests/unit/capi/GEOSPreparedNearestPointsTest.cpp
index 3217668..ff18b75 100644
--- a/tests/unit/capi/GEOSPreparedNearestPointsTest.cpp
+++ b/tests/unit/capi/GEOSPreparedNearestPointsTest.cpp
@@ -51,6 +51,52 @@ struct test_capigeospreparednearestpoints_data {
finishGEOS();
}
+ void checkNearestPoints(const char* wkt1, const char* wkt2,
+ double x1, double y1,
+ double x2, double y2)
+ {
+ geom1_ = GEOSGeomFromWKT(wkt1);
+ ensure(nullptr != geom1_);
+ pgeom1_ = GEOSPrepare(geom1_);
+ ensure(nullptr != pgeom1_);
+ geom2_ = GEOSGeomFromWKT(wkt2);
+ ensure(nullptr != geom2_);
+ GEOSCoordSequence* coords_ = GEOSPreparedNearestPoints(pgeom1_, geom2_);
+
+ unsigned int size;
+ GEOSCoordSeq_getSize(coords_, &size);
+ ensure_equals(size, 2u);
+
+ double ox, oy;
+
+ /* Point in geom1_ */
+ GEOSCoordSeq_getOrdinate(coords_, 0, 0, &ox);
+ GEOSCoordSeq_getOrdinate(coords_, 0, 1, &oy);
+ ensure_equals(ox, x1);
+ ensure_equals(oy, y1);
+
+ /* Point in geom2_ */
+ GEOSCoordSeq_getOrdinate(coords_, 1, 0, &ox);
+ GEOSCoordSeq_getOrdinate(coords_, 1, 1, &oy);
+ ensure_equals(ox, x2);
+ ensure_equals(oy, y2);
+
+ GEOSCoordSeq_destroy(coords_);
+ }
+
+ void checkNearestPointsNull(const char* wkt1, const char* wkt2)
+ {
+ geom1_ = GEOSGeomFromWKT(wkt1);
+ ensure(nullptr != geom1_);
+ pgeom1_ = GEOSPrepare(geom1_);
+ ensure(nullptr != pgeom1_);
+ geom2_ = GEOSGeomFromWKT(wkt2);
+ ensure(nullptr != geom2_);
+ GEOSCoordSequence* coords_ = GEOSPreparedNearestPoints(pgeom1_, geom2_);
+
+ ensure(nullptr == coords_);
+ }
+
};
typedef test_group<test_capigeospreparednearestpoints_data> group;
@@ -67,17 +113,7 @@ template<>
void object::test<1>
()
{
- geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
- pgeom1_ = GEOSPrepare(geom1_);
- geom2_ = GEOSGeomFromWKT("POLYGON EMPTY");
-
- ensure(nullptr != pgeom1_);
- ensure(nullptr != geom2_);
-
- GEOSCoordSequence* coords_;
- coords_ = GEOSPreparedNearestPoints(pgeom1_, geom2_);
-
- ensure(nullptr == coords_);
+ checkNearestPointsNull("POLYGON EMPTY", "POLYGON EMPTY");
}
template<>
@@ -85,39 +121,12 @@ template<>
void object::test<2>
()
{
- geom1_ = GEOSGeomFromWKT("POLYGON((1 1,1 5,5 5,5 1,1 1))");
- pgeom1_ = GEOSPrepare(geom1_);
- geom2_ = GEOSGeomFromWKT("POLYGON((8 8, 9 9, 9 10, 8 8))");
-
- ensure(nullptr != pgeom1_);
- ensure(nullptr != geom2_);
+ 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
+ );
- GEOSCoordSequence* coords_;
- coords_ = GEOSPreparedNearestPoints(pgeom1_, geom2_);
-
- ensure(nullptr != coords_);
-
- unsigned int size;
- GEOSCoordSeq_getSize(coords_, &size);
- ensure_equals(size, 2u);
-
- double x1, x2, y1, y2;
-
- /* Point in pgeom1_
- */
- GEOSCoordSeq_getOrdinate(coords_, 0, 0, &x1);
- GEOSCoordSeq_getOrdinate(coords_, 0, 1, &y1);
- ensure_equals(x1, 5);
- ensure_equals(y1, 5);
-
- /* Point in geom2_
- */
- GEOSCoordSeq_getOrdinate(coords_, 1, 0, &x2);
- GEOSCoordSeq_getOrdinate(coords_, 1, 1, &y2);
- ensure_equals(x2, 8);
- ensure_equals(y2, 8);
-
- GEOSCoordSeq_destroy(coords_);
}
template<>
@@ -125,39 +134,11 @@ template<>
void object::test<3>
()
{
- geom1_ = GEOSGeomFromWKT("POLYGON((1 1,1 5,5 5,5 1,1 1))");
- pgeom1_ = GEOSPrepare(geom1_);
- geom2_ = GEOSGeomFromWKT("POINT(2 2)");
-
- ensure(nullptr != geom1_);
- ensure(nullptr != geom2_);
-
- GEOSCoordSequence* coords_;
- coords_ = GEOSPreparedNearestPoints(pgeom1_, geom2_);
-
- ensure(nullptr != coords_);
-
- unsigned int size;
- GEOSCoordSeq_getSize(coords_, &size);
- ensure_equals(size, 2u);
-
- double x1, x2, y1, y2;
-
- /* Point in geom1_
- */
- GEOSCoordSeq_getOrdinate(coords_, 0, 0, &x1);
- GEOSCoordSeq_getOrdinate(coords_, 0, 1, &y1);
- ensure_equals(x1, 2);
- ensure_equals(y1, 2);
-
- /* Point in geom2_
- */
- GEOSCoordSeq_getOrdinate(coords_, 1, 0, &x2);
- GEOSCoordSeq_getOrdinate(coords_, 1, 1, &y2);
- ensure_equals(x2, 2);
- ensure_equals(y2, 2);
-
- GEOSCoordSeq_destroy(coords_);
+ checkNearestPoints(
+ "POLYGON((1 1,1 5,5 5,5 1,1 1))",
+ "POINT(2 2)",
+ 2, 2, 2, 2
+ );
}
template<>
@@ -165,40 +146,23 @@ template<>
void object::test<4>
()
{
- geom1_ = GEOSGeomFromWKT("LINESTRING(1 5,5 5,5 1,1 1)");
- pgeom1_ = GEOSPrepare(geom1_);
- geom2_ = GEOSGeomFromWKT("POINT(2 2)");
-
- ensure(nullptr != geom1_);
- ensure(nullptr != geom2_);
-
- GEOSCoordSequence* coords_;
- coords_ = GEOSPreparedNearestPoints(pgeom1_, geom2_);
-
- ensure(nullptr != coords_);
-
- unsigned int size;
- GEOSCoordSeq_getSize(coords_, &size);
- ensure_equals(size, 2u);
-
- double x1, x2, y1, y2;
-
- /* Point in geom1_
- */
- GEOSCoordSeq_getOrdinate(coords_, 0, 0, &x1);
- GEOSCoordSeq_getOrdinate(coords_, 0, 1, &y1);
- ensure_equals(x1, 2);
- ensure_equals(y1, 1);
-
-
- /* Point in geom2_
- */
- GEOSCoordSeq_getOrdinate(coords_, 1, 0, &x2);
- GEOSCoordSeq_getOrdinate(coords_, 1, 1, &y2);
- ensure_equals(x2, 2);
- ensure_equals(y2, 2);
+ checkNearestPoints(
+ "LINESTRING(1 5,5 5,5 1,1 1)",
+ "POINT(2 2)",
+ 2, 1, 2, 2
+ );
+}
- GEOSCoordSeq_destroy(coords_);
+template<>
+template<>
+void object::test<5>
+()
+{
+ checkNearestPoints(
+ "LINESTRING(0 0,10 10)",
+ "LINESTRING(0 10,10 0)",
+ 5, 5, 5, 5
+ );
}
} // namespace tut
-----------------------------------------------------------------------
Summary of changes:
tests/unit/capi/GEOSNearestPointsTest.cpp | 148 +++++++++---------
tests/unit/capi/GEOSPreparedNearestPointsTest.cpp | 182 +++++++++-------------
2 files changed, 148 insertions(+), 182 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list