Class: TG::Geometry::Line
- Inherits:
-
Object
- Object
- TG::Geometry::Line
- Defined in:
- lib/tg/geometry.rb,
ext/tg_geometry/tg_geometry_ext.c
Instance Method Summary collapse
- #bbox ⇒ Object
- #clockwise? ⇒ Boolean
- #length ⇒ Object
- #nearest_segment(x_value, y_value) ⇒ Object
- #num_points ⇒ Object
- #num_segments ⇒ Object
- #point_at(index_value) ⇒ Object
- #points ⇒ Object
- #segment_at(index_value) ⇒ Object
- #segments ⇒ Object
Instance Method Details
#bbox ⇒ Object
2477 2478 2479 2480 2481 2482 2483 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2477 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
2542 2543 2544 2545 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2542 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; } |
#length ⇒ Object
2537 2538 2539 2540 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2537 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
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2836 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_points ⇒ Object
2485 2486 2487 2488 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2485 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_segments ⇒ Object
2511 2512 2513 2514 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2511 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
2490 2491 2492 2493 2494 2495 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2490 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)); } |
#points ⇒ Object
2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2497 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
2516 2517 2518 2519 2520 2521 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2516 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)); } |
#segments ⇒ Object
2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 2523 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; } |