Class: TG::Geometry::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/tg/geometry.rb,
ext/tg_geometry/tg_geometry_ext.c

Instance Method Summary collapse

Instance Method Details

#bboxObject



2476
2477
2478
2479
2480
2481
2482
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2476

static VALUE rb_tg_geometry_line_bbox(VALUE self) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    VALUE rect = rect_from_tg_rect(tg_line_rect(w->line));

    RB_GC_GUARD(self);
    return rect;
}

#clockwise?Boolean

Returns:

  • (Boolean)


2541
2542
2543
2544
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2541

static VALUE rb_tg_geometry_line_clockwise_p(VALUE self) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    return tg_line_clockwise(w->line) ? Qtrue : Qfalse;
}

#lengthObject



2536
2537
2538
2539
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2536

static VALUE rb_tg_geometry_line_length(VALUE self) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    return rb_float_new(tg_line_length(w->line));
}

#nearest_segment(x_value, y_value) ⇒ Object



2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2835

static VALUE rb_tg_geometry_line_nearest_segment(VALUE self, VALUE x_value, VALUE y_value) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    tg_nearest_segment_ctx_t ctx;
    bool ok;

    ctx.query.x = NUM2DBL(x_value);
    ctx.query.y = NUM2DBL(y_value);
    check_finite_double(ctx.query.x, "x");
    check_finite_double(ctx.query.y, "y");
    ctx.best_index = -1;
    ctx.best_distance = INFINITY;
    ctx.found = false;

    ok = tg_line_nearest_segment(w->line, nearest_rect_distance, nearest_segment_distance,
                                 nearest_segment_iter, &ctx);
    if (!ok) {
        rb_raise(rb_eNoMemError, "nearest segment search failed");
    }
    if (!ctx.found) {
        return Qnil;
    }

    RB_GC_GUARD(self);
    return nearest_segment_wrap_value(&ctx);
}

#num_pointsObject



2484
2485
2486
2487
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2484

static VALUE rb_tg_geometry_line_num_points(VALUE self) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    return INT2NUM(tg_line_num_points(w->line));
}

#num_segmentsObject



2510
2511
2512
2513
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2510

static VALUE rb_tg_geometry_line_num_segments(VALUE self) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    return INT2NUM(tg_line_num_segments(w->line));
}

#point_at(index_value) ⇒ Object



2489
2490
2491
2492
2493
2494
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2489

static VALUE rb_tg_geometry_line_point_at(VALUE self, VALUE index_value) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    int index = checked_child_index(index_value, tg_line_num_points(w->line), "line point");

    return point_array_from_tg_point(tg_line_point_at(w->line, index));
}

#pointsObject



2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2496

static VALUE rb_tg_geometry_line_points(VALUE self) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    int count = tg_line_num_points(w->line);
    VALUE points = rb_ary_new_capa(count);

    for (int i = 0; i < count; i++) {
        rb_ary_push(points, point_array_from_tg_point(tg_line_point_at(w->line, i)));
    }

    RB_GC_GUARD(self);
    RB_GC_GUARD(points);
    return points;
}

#segment_at(index_value) ⇒ Object



2515
2516
2517
2518
2519
2520
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2515

static VALUE rb_tg_geometry_line_segment_at(VALUE self, VALUE index_value) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    int index = checked_child_index(index_value, tg_line_num_segments(w->line), "line segment");

    return segment_wrap_value(tg_line_segment_at(w->line, index));
}

#segmentsObject



2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2522

static VALUE rb_tg_geometry_line_segments(VALUE self) {
    tg_line_wrapper_t *w = get_line_wrapper(self);
    int count = tg_line_num_segments(w->line);
    VALUE segments = rb_ary_new_capa(count);

    for (int i = 0; i < count; i++) {
        rb_ary_push(segments, segment_wrap_value(tg_line_segment_at(w->line, i)));
    }

    RB_GC_GUARD(self);
    RB_GC_GUARD(segments);
    return segments;
}