Method: RGeo::Geos::CAPIGeometryMethods#==

Defined in:
ext/geos_c_impl/geometry.c

#==(rhs) ⇒ Object



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'ext/geos_c_impl/geometry.c', line 365

static VALUE
method_geometry_equals(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;

  // Shortcut when self and rhs are the same object.
  if (self == rhs) {
    return Qtrue;
  }

  result = Qnil;
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
  self_geom = self_data->geom;
  if (self_geom) {
    rhs_geom = rgeo_get_geos_geometry_safe(rhs);
    if (rhs_geom) {
      // GEOS has a bug where empty geometries are not spatially equal
      // to each other. Work around this case first.
      if (GEOSisEmpty(self_geom) == 1 && GEOSisEmpty(rhs_geom) == 1) {
        result = Qtrue;
      } else {
        result = GEOSEquals(self_geom, rhs_geom) ? Qtrue : Qfalse;
      }
    }
  }
  return result;
}