New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add simplify_polygon_hull method #366
Conversation
e6ed30b
to
185dc79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oleksii-leonov for the PR and the detailed tests. LGTM just one question about adding guards around one method, but looks great.
ext/geos_c_impl/geometry.c
Outdated
static VALUE | ||
method_geometry_simplify_polygon_hull(VALUE self, | ||
VALUE vertex_fraction, | ||
VALUE is_outer) | ||
{ | ||
VALUE result; | ||
RGeo_GeometryData* self_data; | ||
const GEOSGeometry* self_geom; | ||
VALUE factory; | ||
|
||
unsigned int is_outer_uint = RTEST(is_outer) ? 1 : 0; | ||
|
||
result = Qnil; | ||
self_data = RGEO_GEOMETRY_DATA_PTR(self); | ||
self_geom = self_data->geom; | ||
if (self_geom) { | ||
factory = self_data->factory; | ||
result = rgeo_wrap_geos_geometry( | ||
factory, | ||
GEOSPolygonHullSimplify( | ||
self_geom, is_outer_uint, rb_num2dbl(vertex_fraction)), | ||
Qnil); | ||
} | ||
return result; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add method guards around this too? Not sure if having the undefined GEOSPolygonHullSimplify
symbol will break compilation in older versions of not guarded or would only cause a segfault if it's called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keithdoggett , you are right 👍
It's safer to wrap the method with a guard.
I have updated the PR.
Thanks @oleksii-leonov I'll give @BuonOmo another day or 2 to review, but if he's not available I'll merge it in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the beautiful tests ! And for the overall feature. As always my concern is about the geos API. Can the hull generation method fail? And if it does, what happens?
Unfortunatily I cannot deep dive into geos codebase with my smartphone. So have verified that @oleksii-leonov ? You can also take advantage of running tests with MAINTAINER_MODE
for more insights.
If you can't be sure, maybe @keithdoggett you could have a second pair of eyes on this ? 👀
Besides that, LGTM
It looks like the PolygonHullSimplifier (https://github.com/libgeos/geos/blob/3.12/src/simplify/PolygonHullSimplifier.cpp) has only one possible exception: It's handled correctly by RGeo: RGeo::Geos.factory.parse_wkt("LINESTRING (0 0, 0 6, 6 6, 6 0, 0 0)").simplify_polygon_hull(0.1, true)
# (irb):4:in `simplify_polygon_hull': Input geometry must be polygonal (RGeo::Error::InvalidGeometry) I could move |
@oleksii-leonov thank you for verifying. I would add a test to reflect this. On moving the method I think you are right, it would indeed be a better place. |
1300ade
to
bd6a5c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for moving the method @oleksii-leonov and checking for the exception. I think this is good to merge now. WDYT @BuonOmo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleksii-leonov I’m sorry I don’t see the test catching the error we’ve talked about, have I missed it? I think it is an important inclusion!
@BuonOmo, Since I have moved |
@oleksii-leonov indeed got you! Sorry for the delay, and thank you for the clear contribution 🌮 May I rebase/squash before merging or would you rather do it? |
The feature is equal to [ST_SimplifyPolygonHull](https://postgis.net/docs/ST_SimplifyPolygonHull.html) in PostGIS. > Computes a simplified topology-preserving outer or inner hull of a polygonal geometry. > An outer hull completely covers the input geometry. > An inner hull is completely covered by the input geometry. > The result is a polygonal geometry formed by a subset of the input vertices. > MultiPolygons and holes are handled and produce a result with the same structure as the input. > https://postgis.net/docs/ST_SimplifyPolygonHull.html Utilizes the `GEOSPolygonHullSimplify` method introduced in [GEOS 3.11.0](https://github.com/libgeos/geos/releases/tag/3.11.0). - libgeos/geos#603 - locationtech/jts#861 - libgeos/geos@1b3521c
bd6a5c3
to
750f38f
Compare
@BuonOmo , no worries :) |
Summary
The feature is equal to ST_SimplifyPolygonHull in PostGIS.
Utilizes the
GEOSPolygonHullSimplify
method introduced in GEOS 3.11.0.Other Information