Class: Cosmos::LineClip

Inherits:
Object show all
Defined in:
ext/cosmos/ext/line_graph/line_graph.c

Class Method Summary collapse

Class Method Details

.line_clip(x0, y0, x1, y1, xmin, ymin, xmax, ymax) ⇒ Object

This is a line-clipping algorithm. It takes two points and a viewable area. It returns the part of the line that is within the viewable area. If no part of the line is viewable, it returns nil



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'ext/cosmos/ext/line_graph/line_graph.c', line 176

static VALUE line_clip(VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE xmin, VALUE ymin, VALUE xmax, VALUE ymax) {
  volatile VALUE result = Qnil;
  volatile VALUE result_clipped0 = Qnil;
  volatile VALUE result_clipped1 = Qnil;
  volatile VALUE return_value = Qnil;
  double double_x0 = 0.0;
  double double_y0 = 0.0;
  double double_x1 = 0.0;
  double double_y1 = 0.0;
  double double_xmin = 0.0;
  double double_ymin = 0.0;
  double double_xmax = 0.0;
  double double_ymax = 0.0;
  double result_x0 = 0.0;
  double result_y0 = 0.0;
  double result_x1 = 0.0;
  double result_y1 = 0.0;

  double_x0 = RFLOAT_VALUE(rb_funcall(x0, id_method_to_f, 0));
  double_y0 = RFLOAT_VALUE(rb_funcall(y0, id_method_to_f, 0));
  double_x1 = RFLOAT_VALUE(rb_funcall(x1, id_method_to_f, 0));
  double_y1 = RFLOAT_VALUE(rb_funcall(y1, id_method_to_f, 0));
  double_xmin = RFLOAT_VALUE(rb_funcall(xmin, id_method_to_f, 0));
  double_ymin = RFLOAT_VALUE(rb_funcall(ymin, id_method_to_f, 0));
  double_xmax = RFLOAT_VALUE(rb_funcall(xmax, id_method_to_f, 0));
  double_ymax = RFLOAT_VALUE(rb_funcall(ymax, id_method_to_f, 0));

  result = line_clip_internal(double_x0, double_y0, double_x1, double_y1, double_xmin, double_ymin, double_xmax, double_ymax, &result_x0, &result_y0, &result_x1, &result_y1, &result_clipped0, &result_clipped1);

  if (result == Qtrue)
  {
    return_value = rb_ary_new2(6);
    rb_ary_push(return_value, rb_float_new(result_x0));
    rb_ary_push(return_value, rb_float_new(result_y0));
    rb_ary_push(return_value, rb_float_new(result_x1));
    rb_ary_push(return_value, rb_float_new(result_y1));
    rb_ary_push(return_value, result_clipped0);
    rb_ary_push(return_value, result_clipped1);
  }

  return return_value;
}