Module: PointInPoly

Defined in:
ext/vincenty.c

Class Method Summary collapse

Class Method Details

.point_in_poly(rb_x, rb_y, rb_points) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/pnpoly.c', line 73

VALUE point_in_poly(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_points) {
  Check_Type(rb_x, T_FLOAT);
  Check_Type(rb_y, T_FLOAT);
  Check_Type(rb_points, T_ARRAY);

  int i = 0;
  int s = (int)RARRAY_LEN(rb_points);
  double *vertx;
  double *verty;
  
  vertx = calloc(s, sizeof(double));
  verty = calloc(s, sizeof(double));
  
  double test_x = RFLOAT_VALUE(rb_x);
  double test_y = RFLOAT_VALUE(rb_y);
  
  ID i_x = rb_intern("x");
  ID i_y = rb_intern("y");
  
  for(i = 0; i < s; i++) {
    VALUE point = RARRAY_PTR(rb_points)[i];
    VALUE x = rb_funcall(point, i_x, 0);
    VALUE y = rb_funcall(point, i_y, 0);
    Check_Type(x, T_FLOAT);
    Check_Type(y, T_FLOAT);
    vertx[i] = RFLOAT_VALUE(x);
    verty[i] = RFLOAT_VALUE(y);
  }
  
  return pnpoly(s, vertx, verty, test_x, test_y);
}