Skip to content

Commit

Permalink
Added onlyEdges parameter with added test
Browse files Browse the repository at this point in the history
  • Loading branch information
vishaltiwari committed Sep 13, 2013
1 parent 44951e8 commit fade372
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
4 changes: 2 additions & 2 deletions capi/geos_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,9 +1271,9 @@ GEOSDelaunayTriangulation(const Geometry *g, double tolerance, int onlyEdges)
}

Geometry*
GEOSVoronoiDiagramBuilder(const Geometry *g, double tolerance)
GEOSVoronoiDiagramBuilder(const Geometry *g, double tolerance, int onlyEdges)
{
return GEOSVoronoiDiagramBuilder_r(handle, g, tolerance);
return GEOSVoronoiDiagramBuilder_r(handle, g, tolerance, onlyEdges);
}

} /* extern "C" */
6 changes: 4 additions & 2 deletions capi/geos_c.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,14 @@ extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation_r(
*/
extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagramBuilder(
const GEOSGeometry *g,
double tolerance);
double tolerance,
int onlyEdges);

extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagramBuilder_r(
GEOSContextHandle_t extHandle,
const GEOSGeometry *g1,
double tolerance);
double tolerance,
int onlyEdges);


/************************************************************************
Expand Down
8 changes: 5 additions & 3 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6219,7 +6219,7 @@ GEOSDelaunayTriangulation_r(GEOSContextHandle_t extHandle, const Geometry *g1, d
return NULL;
}
Geometry*
GEOSVoronoiDiagramBuilder_r(GEOSContextHandle_t extHandle, const Geometry *g1,double tolerance)
GEOSVoronoiDiagramBuilder_r(GEOSContextHandle_t extHandle, const Geometry *g1,double tolerance, int onlyEdges)
{
if ( 0 == extHandle ) return NULL;

Expand All @@ -6230,11 +6230,13 @@ GEOSVoronoiDiagramBuilder_r(GEOSContextHandle_t extHandle, const Geometry *g1,do
using geos::triangulate::VoronoiDiagramBuilder;

try
{
{
VoronoiDiagramBuilder builder;
builder.setSites(*g1);
builder.setTolerance(tolerance);
return builder.getDiagram(*(g1->getFactory())).release();

if(onlyEdges) return builder.getSubdivision()->getEdges(*g1->getFactory()).release();
else return builder.getDiagram(*(g1->getFactory())).release();
}
catch(const std::exception &e)
{
Expand Down
58 changes: 53 additions & 5 deletions tests/unit/capi/GEOSVoronoiDiagramBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ namespace tut
{
geom1_ = GEOSGeomFromWKT("POINT(10 20)");

geom2_ = GEOSVoronoiDiagramBuilder(geom1_,0);
geom2_ = GEOSVoronoiDiagramBuilder(geom1_,0,0);
ensure_equals ( GEOSisEmpty(geom2_), 1 );
ensure_equals ( GEOSGeomTypeId(geom2_), GEOS_GEOMETRYCOLLECTION );
GEOSGeom_destroy(geom2_);
geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
std::string out(wkt_c);
free(wkt_c);
ensure_equals(out,"MULTILINESTRING EMPTY");
}

//More points:
Expand All @@ -102,8 +108,15 @@ namespace tut
{
geom1_ = GEOSGeomFromWKT("MULTIPOINT ((280 300), (420 330), (380 230), (320 160))");

geom2_ = GEOSVoronoiDiagramBuilder(geom1_,0);
geom2_ = GEOSVoronoiDiagramBuilder(geom1_,0,0);
ensure_equals_wkt(geom2_ ,"GEOMETRYCOLLECTION (POLYGON ((110 175.71428571428572, 110 500, 310.35714285714283 500, 353.515625 298.59375, 306.875 231.96428571428572, 110 175.71428571428572)), POLYGON ((590 204, 590 -10, 589.1666666666666 -10, 306.875 231.96428571428572, 353.515625 298.59375, 590 204)), POLYGON ((110 -10, 110 175.71428571428572, 306.875 231.96428571428572, 589.1666666666666 -10, 110 -10)), POLYGON ((310.35714285714283 500, 590 500, 590 204, 353.515625 298.59375, 310.35714285714283 500)))" );

GEOSGeom_destroy(geom2_);
geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
std::string out(wkt_c);
free(wkt_c);
ensure_equals(out, "MULTILINESTRING ((280 300, 420 330), (280 300, 320 160), (320 160, 380 230), (380 230, 420 330), (280 300, 380 230))");
}
//Larger number of points:
template<>
Expand All @@ -112,8 +125,15 @@ namespace tut
{
geom1_ = GEOSGeomFromWKT("MULTIPOINT ((170 270), (270 270), (230 310), (180 330), (250 340), (315 318), (330 260), (240 170), (220 220), (270 220))");

geom2_ = GEOSVoronoiDiagramBuilder(geom1_,0);
geom2_ = GEOSVoronoiDiagramBuilder(geom1_,0,0);
ensure_equals_wkt(geom2_,"GEOMETRYCOLLECTION (POLYGON ((0 329.1666666666667, 0 510, 190 510, 213.94736842105263 342.36842105263156, 195.625 296.5625, 0 329.1666666666667)), POLYGON ((0 76.50000000000001, 0 329.1666666666667, 195.625 296.5625, 216 266, 88.33333333333333 138.33333333333334, 0 76.50000000000001)), POLYGON ((216 266, 195.625 296.5625, 213.94736842105263 342.36842105263156, 267 307, 225 265, 216 266)), POLYGON ((245 245, 225 265, 267 307, 275.9160583941606 309.54744525547443, 303.1666666666667 284, 296.6666666666667 245, 245 245)), POLYGON ((225 265, 245 245, 245 201, 88.33333333333333 138.33333333333334, 216 266, 225 265)), POLYGON ((0 0, 0 76.50000000000001, 88.33333333333333 138.33333333333334, 245 201, 380 120, 500 0, 0 0)), POLYGON ((190 510, 343.76153846153846 510, 275.9160583941606 309.54744525547443, 267 307, 213.94736842105263 342.36842105263156, 190 510)), POLYGON ((245 201, 245 245, 296.6666666666667 245, 380 120, 245 201)), POLYGON ((343.76153846153846 510, 500 510, 500 334.9051724137931, 303.1666666666667 284, 275.9160583941606 309.54744525547443, 343.76153846153846 510)), POLYGON ((500 334.9051724137931, 500 0, 380 120, 296.6666666666667 245, 303.1666666666667 284, 500 334.9051724137931)))");

GEOSGeom_destroy(geom2_);
geom2_ = GEOSDelaunayTriangulation(geom1_, 0, 1);
char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
std::string out(wkt_c);
free(wkt_c);
ensure_equals(out, "MULTILINESTRING ((250 340, 315 318), (180 330, 250 340), (170 270, 180 330), (170 270, 240 170), (240 170, 330 260), (315 318, 330 260), (270 270, 330 260), (270 270, 315 318), (250 340, 270 270), (230 310, 270 270), (230 310, 250 340), (180 330, 230 310), (170 270, 230 310), (220 220, 230 310), (170 270, 220 220), (220 220, 240 170), (220 220, 270 220), (240 170, 270 220), (270 220, 330 260), (270 220, 270 270), (220 220, 270 270))");
}
//Test with non-zero Tolerance value
template<>
Expand All @@ -122,17 +142,45 @@ namespace tut
{
geom1_ = GEOSGeomFromWKT("MULTIPOINT ((150 210), (210 270), (150 220), (220 210), (215 269))");

geom2_ = GEOSVoronoiDiagramBuilder(geom1_,10);
geom2_ = GEOSVoronoiDiagramBuilder(geom1_,10,0);
ensure_equals_wkt(geom2_,"GEOMETRYCOLLECTION (POLYGON ((290 252.5, 290 140, 185 140, 185 215, 187.9268292682927 235.4878048780488, 290 252.5)), POLYGON ((80 215, 80 340, 100.83333333333336 340, 187.9268292682927 235.4878048780488, 185 215, 80 215)), POLYGON ((80 140, 80 215, 185 215, 185 140, 80 140)), POLYGON ((100.83333333333336 340, 290 340, 290 252.5, 187.9268292682927 235.4878048780488, 100.83333333333336 340)))");

GEOSGeom_destroy(geom2_);
geom2_ = GEOSDelaunayTriangulation(geom1_, 10, 1);
char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
std::string out(wkt_c);
free(wkt_c);
ensure_equals(out,"MULTILINESTRING ((150 220, 210 270), (150 210, 150 220), (150 210, 220 210), (210 270, 220 210), (150 220, 220 210))");
}
template<>
template<>
void object::test<5>()
{
geom1_ = GEOSGeomFromWKT("MULTIPOINT ((40 420), (50 420), (210 290), (300 360), (350 150), (170 70), (134 135) ,(305 359), (351 145), (175 71))");

geom2_ = GEOSVoronoiDiagramBuilder(geom1_,10);
geom2_ = GEOSVoronoiDiagramBuilder(geom1_,10,0);
ensure_equals_wkt(geom2_, "GEOMETRYCOLLECTION (POLYGON ((-310 146.559649122807, -310 770, 45 770, 45 263.64736842105265, -310 146.559649122807)), POLYGON ((-310 -153.37692307692305, -310 146.559649122807, 45 263.64736842105265, 59.16911764705881 267.8235294117647, 239.43506493506493 179.43506493506493, 241.34156378600824 151.98148148148147, -310 -153.37692307692305)), POLYGON ((45 770, 266.20000000000005 770, 181.94323144104806 418.9301310043668, 59.16911764705881 267.8235294117647, 45 263.64736842105265, 45 770)), POLYGON ((59.16911764705881 267.8235294117647, 181.94323144104806 418.9301310043668, 311.875 251.875, 239.43506493506493 179.43506493506493, 59.16911764705881 267.8235294117647)), POLYGON ((-310 -280, -310 -153.37692307692305, 241.34156378600824 151.98148148148147, 433.3333333333333 -280, -310 -280)), POLYGON ((266.20000000000005 770, 701 770, 701 344.5238095238096, 311.875 251.875, 181.94323144104806 418.9301310043668, 266.20000000000005 770)), POLYGON ((701 344.5238095238096, 701 -280, 433.3333333333333 -280, 241.34156378600824 151.98148148148147, 239.43506493506493 179.43506493506493, 311.875 251.875, 701 344.5238095238096)))");

GEOSGeom_destroy(geom2_);
geom2_ = GEOSDelaunayTriangulation(geom1_, 10, 1);
char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
std::string out(wkt_c);
free(wkt_c);
ensure_equals(out,"MULTILINESTRING ((50 420, 300 360), (40 420, 50 420), (40 420, 134 135), (134 135, 170 70), (170 70, 350 150), (300 360, 350 150), (210 290, 350 150), (210 290, 300 360), (50 420, 210 290), (134 135, 210 290), (50 420, 134 135), (134 135, 350 150))");
}
template<>
template<>
void object::test<6>()
{
geom1_ = GEOSGeomFromWKT("MULTIPOINT ((123 245), (165 313), (240 310), (260 260), (180 210), (240 210))");

geom2_ = GEOSVoronoiDiagramBuilder(geom1_,0,1);
char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
std::string out(wkt_c);
free(wkt_c);
ensure_equals(out , "MULTILINESTRING ((240 310, 260 260), (165 313, 240 310), (123 245, 165 313), (123 245, 180 210), (180 210, 240 210), (240 210, 260 260), (180 210, 260 260), (180 210, 240 310), (165 313, 180 210))");
}


} // namespace tut

0 comments on commit fade372

Please sign in to comment.