Class: TG::Geometry::Rect
- Inherits:
-
Object
- Object
- TG::Geometry::Rect
- Defined in:
- ext/tg_geometry/tg_geometry_ext.c
Instance Method Summary collapse
- #center ⇒ Object
- #contains_point?(x_value, y_value) ⇒ Boolean
- #expand_to_include(other) ⇒ Object
- #expand_to_include_point(x_value, y_value) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #intersects?(other) ⇒ Boolean
- #max_x ⇒ Object
- #max_y ⇒ Object
- #min_x ⇒ Object
- #min_y ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1847
static VALUE rb_tg_geometry_rect_initialize(int argc, VALUE *argv, VALUE self) {
VALUE min_x_value;
VALUE min_y_value;
VALUE max_x_value;
VALUE max_y_value;
tg_rect_wrapper_t *rect_data;
double min_x;
double min_y;
double max_x;
double max_y;
rb_check_arity(argc, 4, 4);
rb_scan_args(argc, argv, "40", &min_x_value, &min_y_value, &max_x_value, &max_y_value);
min_x = NUM2DBL(min_x_value);
min_y = NUM2DBL(min_y_value);
max_x = NUM2DBL(max_x_value);
max_y = NUM2DBL(max_y_value);
validate_rect_coordinates(min_x, min_y, max_x, max_y);
TypedData_Get_Struct(self, tg_rect_wrapper_t, &tg_rect_type, rect_data);
rect_data->min_x = min_x;
rect_data->min_y = min_y;
rect_data->max_x = max_x;
rect_data->max_y = max_y;
rect_data->initialized = true;
rb_obj_freeze(self);
return self;
}
|
Instance Method Details
#center ⇒ Object
1899 1900 1901 1902 1903 1904 1905 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1899
static VALUE rb_tg_geometry_rect_center(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
double center_x = rect_data->min_x + ((rect_data->max_x - rect_data->min_x) / 2.0);
double center_y = rect_data->min_y + ((rect_data->max_y - rect_data->min_y) / 2.0);
return rb_ary_new_from_args(2, rb_float_new(center_x), rb_float_new(center_y));
}
|
#contains_point?(x_value, y_value) ⇒ Boolean
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1914
static VALUE rb_tg_geometry_rect_contains_point_p(VALUE self, VALUE x_value, VALUE y_value) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
double x = NUM2DBL(x_value);
double y = NUM2DBL(y_value);
check_finite_double(x, "x");
check_finite_double(y, "y");
return rect_contains_point_data(rect_data, x, y) ? Qtrue : Qfalse;
}
|
#expand_to_include(other) ⇒ Object
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1925
static VALUE rb_tg_geometry_rect_expand_to_include(VALUE self, VALUE other) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
tg_rect_wrapper_t *other_data = get_rect_wrapper(other);
double min_x = rect_data->min_x < other_data->min_x ? rect_data->min_x : other_data->min_x;
double min_y = rect_data->min_y < other_data->min_y ? rect_data->min_y : other_data->min_y;
double max_x = rect_data->max_x > other_data->max_x ? rect_data->max_x : other_data->max_x;
double max_y = rect_data->max_y > other_data->max_y ? rect_data->max_y : other_data->max_y;
return rect_build(min_x, min_y, max_x, max_y);
}
|
#expand_to_include_point(x_value, y_value) ⇒ Object
1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1936
static VALUE rb_tg_geometry_rect_expand_to_include_point(VALUE self, VALUE x_value, VALUE y_value) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
double x = NUM2DBL(x_value);
double y = NUM2DBL(y_value);
double min_x;
double min_y;
double max_x;
double max_y;
check_finite_double(x, "x");
check_finite_double(y, "y");
min_x = rect_data->min_x < x ? rect_data->min_x : x;
min_y = rect_data->min_y < y ? rect_data->min_y : y;
max_x = rect_data->max_x > x ? rect_data->max_x : x;
max_y = rect_data->max_y > y ? rect_data->max_y : y;
return rect_build(min_x, min_y, max_x, max_y);
}
|
#intersects?(other) ⇒ Boolean
1907 1908 1909 1910 1911 1912 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1907
static VALUE rb_tg_geometry_rect_intersects_p(VALUE self, VALUE other) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
tg_rect_wrapper_t *other_data = get_rect_wrapper(other);
return rect_intersects_rect_data(rect_data, other_data) ? Qtrue : Qfalse;
}
|
#max_x ⇒ Object
1889 1890 1891 1892 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1889
static VALUE rb_tg_geometry_rect_max_x(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->max_x);
}
|
#max_y ⇒ Object
1894 1895 1896 1897 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1894
static VALUE rb_tg_geometry_rect_max_y(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->max_y);
}
|
#min_x ⇒ Object
1879 1880 1881 1882 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1879
static VALUE rb_tg_geometry_rect_min_x(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->min_x);
}
|
#min_y ⇒ Object
1884 1885 1886 1887 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1884
static VALUE rb_tg_geometry_rect_min_y(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->min_y);
}
|