Class: TG::Geometry::Ring

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

#areaObject



2606
2607
2608
2609
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2606

static VALUE rb_tg_geometry_ring_area(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    return rb_float_new(tg_ring_area(w->ring));
}

#bboxObject



2546
2547
2548
2549
2550
2551
2552
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2546

static VALUE rb_tg_geometry_ring_bbox(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    VALUE rect = rect_from_tg_rect(tg_ring_rect(w->ring));

    RB_GC_GUARD(self);
    return rect;
}

#clockwise?Boolean

Returns:

  • (Boolean)


2616
2617
2618
2619
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2616

static VALUE rb_tg_geometry_ring_clockwise_p(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    return tg_ring_clockwise(w->ring) ? Qtrue : Qfalse;
}

#convex?Boolean

Returns:

  • (Boolean)


2621
2622
2623
2624
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2621

static VALUE rb_tg_geometry_ring_convex_p(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    return tg_ring_convex(w->ring) ? Qtrue : Qfalse;
}

#nearest_segment(x_value, y_value) ⇒ Object



2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2861

static VALUE rb_tg_geometry_ring_nearest_segment(VALUE self, VALUE x_value, VALUE y_value) {
    tg_ring_wrapper_t *w = get_ring_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_ring_nearest_segment(w->ring, 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



2554
2555
2556
2557
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2554

static VALUE rb_tg_geometry_ring_num_points(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    return INT2NUM(tg_ring_num_points(w->ring));
}

#num_segmentsObject



2580
2581
2582
2583
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2580

static VALUE rb_tg_geometry_ring_num_segments(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    return INT2NUM(tg_ring_num_segments(w->ring));
}

#perimeterObject



2611
2612
2613
2614
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2611

static VALUE rb_tg_geometry_ring_perimeter(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    return rb_float_new(tg_ring_perimeter(w->ring));
}

#point_at(index_value) ⇒ Object



2559
2560
2561
2562
2563
2564
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2559

static VALUE rb_tg_geometry_ring_point_at(VALUE self, VALUE index_value) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    int index = checked_child_index(index_value, tg_ring_num_points(w->ring), "ring point");

    return point_array_from_tg_point(tg_ring_point_at(w->ring, index));
}

#pointsObject



2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2566

static VALUE rb_tg_geometry_ring_points(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    int count = tg_ring_num_points(w->ring);
    VALUE points = rb_ary_new_capa(count);

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

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

#segment_at(index_value) ⇒ Object



2585
2586
2587
2588
2589
2590
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2585

static VALUE rb_tg_geometry_ring_segment_at(VALUE self, VALUE index_value) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    int index = checked_child_index(index_value, tg_ring_num_segments(w->ring), "ring segment");

    return segment_wrap_value(tg_ring_segment_at(w->ring, index));
}

#segmentsObject



2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2592

static VALUE rb_tg_geometry_ring_segments(VALUE self) {
    tg_ring_wrapper_t *w = get_ring_wrapper(self);
    int count = tg_ring_num_segments(w->ring);
    VALUE segments = rb_ary_new_capa(count);

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

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