Method: RGeo::Geos::CAPIGeometryMethods#distance

Defined in:
ext/geos_c_impl/geometry.c

#distance(rhs) ⇒ Object



693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'ext/geos_c_impl/geometry.c', line 693

static VALUE
method_geometry_distance(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  double dist;
  int state = 0;

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom =
      rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
    if (state) {
      rb_jump_tag(state);
    }

    if (GEOSDistance(self_geom, rhs_geom, &dist)) {
      result = rb_float_new(dist);
    }
  }
  return result;
}