Skip to content

Commit

Permalink
refactor: move simplify_polygon_hull to polygon.c
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksii-leonov committed Dec 2, 2023
1 parent 0c4f2cc commit 1300ade
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
35 changes: 0 additions & 35 deletions ext/geos_c_impl/geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,34 +831,6 @@ method_geometry_simplify_preserve_topology(VALUE self, VALUE tolerance)
return result;
}

#ifdef RGEO_GEOS_SUPPORTS_POLYGON_HULL_SIMPLIFY
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;
}
#endif

static VALUE
method_geometry_convex_hull(VALUE self)
{
Expand Down Expand Up @@ -1358,13 +1330,6 @@ rgeo_init_geos_geometry()
rb_define_method(
geos_geometry_methods, "polygonize", method_geometry_polygonize, 0);

#ifdef RGEO_GEOS_SUPPORTS_POLYGON_HULL_SIMPLIFY
rb_define_method(geos_geometry_methods,
"simplify_polygon_hull",
method_geometry_simplify_polygon_hull,
2);
#endif

#ifdef RGEO_GEOS_SUPPORTS_DENSIFY
rb_define_method(
geos_geometry_methods, "segmentize", method_geometry_segmentize, 1);
Expand Down
35 changes: 35 additions & 0 deletions ext/geos_c_impl/polygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,34 @@ method_polygon_interior_rings(VALUE self)
return result;
}

#ifdef RGEO_GEOS_SUPPORTS_POLYGON_HULL_SIMPLIFY
static VALUE
method_polygon_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;
}
#endif

static VALUE
cmethod_create(VALUE module,
VALUE factory,
Expand Down Expand Up @@ -335,6 +363,13 @@ rgeo_init_geos_polygon()
geos_polygon_methods, "interior_rings", method_polygon_interior_rings, 0);
rb_define_method(
geos_polygon_methods, "coordinates", method_polygon_coordinates, 0);

#ifdef RGEO_GEOS_SUPPORTS_POLYGON_HULL_SIMPLIFY
rb_define_method(geos_polygon_methods,
"simplify_polygon_hull",
method_polygon_simplify_polygon_hull,
2);
#endif
}

st_index_t
Expand Down

0 comments on commit 1300ade

Please sign in to comment.