Method: RGeo::Geos::CAPIGeometryMethods#within?

Defined in:
ext/geos_c_impl/geometry.c

#within?(rhs) ⇒ Boolean



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'ext/geos_c_impl/geometry.c', line 549

static VALUE
method_geometry_within(VALUE self, VALUE rhs)
{
  VALUE result;
  RGeo_GeometryData* self_data;
  const GEOSGeometry* self_geom;
  const GEOSGeometry* rhs_geom;
  char val;
  int state = 0;
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
  const GEOSPreparedGeometry* prep;
#endif

  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);
    }
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
    prep = rgeo_request_prepared_geometry(self_data);
    if (prep)
      val = GEOSPreparedWithin(prep, rhs_geom);
    else
#endif
      val = GEOSWithin(self_geom, rhs_geom);
    if (val == 0) {
      result = Qfalse;
    } else if (val == 1) {
      result = Qtrue;
    }
  }
  return result;
}