Skip to content

Commit 5db420a

Browse files
committed
remove vectorio object arg implementations. Fix docstrings.
1 parent c44edcb commit 5db420a

File tree

8 files changed

+43
-170
lines changed

8 files changed

+43
-170
lines changed

shared-bindings/vectorio/Circle.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@ MP_PROPERTY_GETSET(vectorio_circle_color_index_obj,
106106
(mp_obj_t)&vectorio_circle_set_color_index_obj);
107107

108108

109-
//| def intersects(self, other_shape: Union[vectorio.Circle, vectorio.Rectangle]) -> bool:
110-
//| """Return true if this shape intersects (overlaps with) another shape."""
111-
//| ...
112-
static mp_obj_t vectorio_circle_obj_intersects(mp_obj_t self_in, mp_obj_t other_shape) {
113-
vectorio_circle_t *self = MP_OBJ_TO_PTR(self_in);
114-
return mp_obj_new_bool(common_hal_vectorio_circle_intersects(self, other_shape));
115-
}
116-
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_circle_intersects_obj, vectorio_circle_obj_intersects);
117-
118109
// Documentation for properties inherited from VectorShape.
119110

120111
//| x: int
@@ -142,7 +133,6 @@ static const mp_rom_map_elem_t vectorio_circle_locals_dict_table[] = {
142133
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
143134
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) },
144135
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_circle_color_index_obj) },
145-
{ MP_ROM_QSTR(MP_QSTR_intersects), MP_ROM_PTR(&vectorio_circle_intersects_obj) },
146136
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
147137
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
148138
};

shared-bindings/vectorio/Circle.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,3 @@ uint16_t common_hal_vectorio_circle_get_color_index(void *obj);
2828
void common_hal_vectorio_circle_set_color_index(void *obj, uint16_t color_index);
2929

3030
mp_obj_t common_hal_vectorio_circle_get_draw_protocol(void *circle);
31-
32-
bool common_hal_vectorio_circle_intersects(vectorio_circle_t *self, mp_obj_t other_shape);

shared-bindings/vectorio/Rectangle.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,6 @@ const mp_obj_property_t vectorio_rectangle_color_index_obj = {
136136
MP_ROM_NONE},
137137
};
138138

139-
//| def intersects(self, other_shape: Union[vectorio.Circle, vectorio.Rectangle]) -> bool:
140-
//| """Return true if this shape intersects (overlaps with) another shape."""
141-
//| ...
142-
static mp_obj_t vectorio_rectangle_obj_intersects(mp_obj_t self_in, mp_obj_t other_shape) {
143-
vectorio_rectangle_t *self = MP_OBJ_TO_PTR(self_in);
144-
return mp_obj_new_bool(common_hal_vectorio_rectangle_intersects(self, other_shape));
145-
}
146-
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_rectangle_intersects_obj, vectorio_rectangle_obj_intersects);
147-
148139

149140
// Documentation for properties inherited from VectorShape.
150141

@@ -172,7 +163,6 @@ static const mp_rom_map_elem_t vectorio_rectangle_locals_dict_table[] = {
172163
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
173164
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) },
174165
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_rectangle_color_index_obj) },
175-
{ MP_ROM_QSTR(MP_QSTR_intersects), MP_ROM_PTR(&vectorio_rectangle_intersects_obj) },
176166
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&vectorio_rectangle_width_obj) },
177167
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&vectorio_rectangle_height_obj) },
178168
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },

shared-bindings/vectorio/Rectangle.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ void common_hal_vectorio_rectangle_set_color_index(void *obj, uint16_t color_ind
2929

3030
int16_t common_hal_vectorio_rectangle_get_height(void *obj);
3131
void common_hal_vectorio_rectangle_set_height(void *obj, int16_t height);
32-
33-
bool common_hal_vectorio_rectangle_intersects(vectorio_rectangle_t *self, mp_obj_t other_shape);

shared-bindings/vectorio/__init__.c

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,23 @@
3838
//| group.append(polygon)
3939
//|
4040
//| """
41+
//|
4142

4243

4344
//| def circle_rectangle_intersects(
4445
//| cx: int, cy: int, cr: int, rx: int, ry: int, rw: int, rh: int
46+
//| ) -> bool:
47+
//| """Checks for intersection between a cricle and a rectangle.
48+
//|
4549
//| :param int cx: Circle center x coordinate
4650
//| :param int cy: Circle center y coordinate
4751
//| :param int cr: Circle radius
4852
//| :param int rx: Rectangle x coordinate
4953
//| :param int ry: Rectangle y coordinate
5054
//| :param int rw: Rectangle width
51-
//| :param int rh: Rectangle height
52-
//| ) -> None:
55+
//| :param int rh: Rectangle height"""
56+
//| ...
57+
//|
5358
static mp_obj_t vectorio_circle_rectangle_intersects(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
5459
enum {ARG_cx, ARG_cy, ARG_cr, ARG_rx, ARG_ry, ARG_rw, ARG_rh};
5560

@@ -75,28 +80,30 @@ static mp_obj_t vectorio_circle_rectangle_intersects(size_t n_args, const mp_obj
7580
int16_t rh = args[ARG_rh].u_int;
7681

7782
bool result = common_hal_vectorio_circle_rectangle_intersects(cx, cy, cr, rx, ry, rw, rh);
78-
if (result){
83+
if (result) {
7984
return mp_const_true;
80-
}else{
85+
} else {
8186
return mp_const_false;
8287
}
8388
}
8489
MP_DEFINE_CONST_FUN_OBJ_KW(vectorio_circle_rectangle_intersects_obj, 0, vectorio_circle_rectangle_intersects);
8590

8691

8792
//| def rectangle_rectangle_intersects(
88-
//| r1x: int, r1y: int, r1w: int, r1h: int,
89-
// r2x: int, r2y: int, r2w: int, r2h: int
93+
//| r1x: int, r1y: int, r1w: int, r1h: int, r2x: int, r2y: int, r2w: int, r2h: int
94+
//| ) -> bool:
95+
//| """Checks for intersection between a two rectangles.
96+
//|
97+
//| :param int r1x: First Rectangle x coordinate
98+
//| :param int r1y: First Rectangle y coordinate
99+
//| :param int r1w: First Rectangle width
100+
//| :param int r1h: First Rectangle height
101+
//| :param int r2x: Second Rectangle x coordinate
102+
//| :param int r2y: Second Rectangle y coordinate
103+
//| :param int r2w: Second Rectangle width
104+
//| :param int r2h: Second Rectangle height"""
105+
//| ...
90106
//|
91-
//| :param int r1x: Rectangle x coordinate
92-
//| :param int r1y: Rectangle y coordinate
93-
//| :param int r1w: Rectangle width
94-
//| :param int r1h: Rectangle height
95-
//| :param int r2x: Other Rectangle x coordinate
96-
//| :param int r2y: Other Rectangle y coordinate
97-
//| :param int r2w: Other Rectangle width
98-
//| :param int r2h: Other Rectangle height
99-
//| ) -> None:
100107
static mp_obj_t vectorio_rectangle_rectangle_intersects(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
101108
enum {ARG_r1x, ARG_r1y, ARG_r1w, ARG_r1h, ARG_r2x, ARG_r2y, ARG_r2w, ARG_r2h};
102109

@@ -126,24 +133,27 @@ static mp_obj_t vectorio_rectangle_rectangle_intersects(size_t n_args, const mp_
126133

127134

128135
bool result = common_hal_vectorio_rectangle_rectangle_intersects(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h);
129-
if (result){
136+
if (result) {
130137
return mp_const_true;
131-
}else{
138+
} else {
132139
return mp_const_false;
133140
}
134141
}
135142
MP_DEFINE_CONST_FUN_OBJ_KW(vectorio_rectangle_rectangle_intersects_obj, 0, vectorio_rectangle_rectangle_intersects);
136143

137-
138144
//| def circle_circle_intersects(
139-
//| cx: int, cy: int, cr: int, rx: int, ry: int, rw: int, rh: int
140-
//| :param int c1x: Circle center x coordinate
141-
//| :param int c1y: Circle center y coordinate
142-
//| :param int c1r: Circle radius
143-
//| :param int c2x: Other Circle center x coordinate
144-
//| :param int c2y: Other Circle center y coordinate
145-
//| :param int c2r: Other Circle radius
146-
//| ) -> None:
145+
//| c1x: int, c1y: int, c1r: int, c2x: int, c2y: int, c2r: int
146+
//| ) -> bool:
147+
//| """Checks for intersection between two circles.
148+
//|
149+
//| :param int c1x: First Circle center x coordinate
150+
//| :param int c1y: First Circle center y coordinate
151+
//| :param int c1r: First Circle radius
152+
//| :param int c2x: Second Circle center x coordinate
153+
//| :param int c2y: Second Circle center y coordinate
154+
//| :param int c2r: Second Circle radius"""
155+
//| ...
156+
//|
147157
static mp_obj_t vectorio_circle_circle_intersects(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
148158
enum {ARG_c1x, ARG_c1y, ARG_c1r, ARG_c2x, ARG_c2y, ARG_c2r};
149159

@@ -167,9 +177,9 @@ static mp_obj_t vectorio_circle_circle_intersects(size_t n_args, const mp_obj_t
167177
int16_t c2r = args[ARG_c2r].u_int;
168178

169179
bool result = common_hal_vectorio_circle_circle_intersects(c1x, c1y, c1r, c2x, c2y, c2r);
170-
if (result){
180+
if (result) {
171181
return mp_const_true;
172-
}else{
182+
} else {
173183
return mp_const_false;
174184
}
175185
}

shared-module/vectorio/Circle.c

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -81,63 +81,6 @@ void common_hal_vectorio_circle_set_color_index(void *obj, uint16_t color_index)
8181
}
8282
}
8383

84-
bool common_hal_vectorio_circle_intersects(vectorio_circle_t *self, mp_obj_t other_shape) {
85-
86-
mp_obj_t possible_rect = mp_obj_cast_to_native_base(other_shape, &vectorio_rectangle_type);
87-
if (possible_rect != MP_OBJ_NULL) {
88-
89-
vectorio_rectangle_t *other_rect = possible_rect;
90-
91-
mp_int_t self_x = common_hal_vectorio_vector_shape_get_x(self->draw_protocol_instance);
92-
mp_int_t self_y = common_hal_vectorio_vector_shape_get_y(self->draw_protocol_instance);
93-
94-
mp_int_t other_left = common_hal_vectorio_vector_shape_get_x(other_rect->draw_protocol_instance);
95-
mp_int_t other_right = other_left + other_rect->width;
96-
mp_int_t other_top = common_hal_vectorio_vector_shape_get_y(other_rect->draw_protocol_instance);
97-
mp_int_t other_bottom = other_top + other_rect->height;
98-
99-
mp_int_t test_x = self_x;
100-
mp_int_t test_y = self_y;
101-
102-
if (self_x < other_left) {
103-
test_x = other_left;
104-
} else if (self_x > other_right) {
105-
test_x = other_right;
106-
}
107-
108-
if (self_y < other_top) {
109-
test_y = other_top;
110-
} else if (self_y > other_bottom) {
111-
test_y = other_bottom;
112-
}
113-
114-
mp_int_t dist_x = self_x - test_x;
115-
mp_int_t dist_y = self_y - test_y;
116-
mp_int_t dist = sqrtf((dist_x * dist_x) + (dist_y * dist_y));
117-
118-
return dist <= self->radius;
119-
}
120-
mp_obj_t possible_circle = mp_obj_cast_to_native_base(other_shape, &vectorio_circle_type);
121-
if (possible_circle != MP_OBJ_NULL) {
122-
vectorio_circle_t *other_circle = possible_circle;
123-
124-
mp_int_t self_x = common_hal_vectorio_vector_shape_get_x(self->draw_protocol_instance);
125-
mp_int_t self_y = common_hal_vectorio_vector_shape_get_y(self->draw_protocol_instance);
126-
127-
mp_int_t other_circle_x = common_hal_vectorio_vector_shape_get_x(other_circle->draw_protocol_instance);
128-
mp_int_t other_circle_y = common_hal_vectorio_vector_shape_get_y(other_circle->draw_protocol_instance);
129-
130-
mp_int_t dist_x = self_x - other_circle_x;
131-
mp_int_t dist_y = self_y - other_circle_y;
132-
133-
mp_int_t dist = sqrtf((dist_x * dist_x) + (dist_y * dist_y));
134-
135-
return dist <= self->radius + other_circle->radius;
136-
137-
}
138-
139-
return false;
140-
}
14184

14285
mp_obj_t common_hal_vectorio_circle_get_draw_protocol(void *circle) {
14386
vectorio_circle_t *self = circle;

shared-module/vectorio/Rectangle.c

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -51,62 +51,6 @@ mp_obj_t common_hal_vectorio_rectangle_get_draw_protocol(void *rectangle) {
5151
return self->draw_protocol_instance;
5252
}
5353

54-
bool common_hal_vectorio_rectangle_intersects(vectorio_rectangle_t *self, mp_obj_t other_shape) {
55-
56-
mp_obj_t possible_rect = mp_obj_cast_to_native_base(other_shape, &vectorio_rectangle_type);
57-
if (possible_rect != MP_OBJ_NULL) {
58-
59-
vectorio_rectangle_t *other_rect = possible_rect;
60-
61-
mp_int_t self_left = common_hal_vectorio_vector_shape_get_x(self->draw_protocol_instance);
62-
mp_int_t self_right = self_left + self->width;
63-
mp_int_t self_top = common_hal_vectorio_vector_shape_get_y(self->draw_protocol_instance);
64-
mp_int_t self_bottom = self_top + self->height;
65-
66-
mp_int_t other_left = common_hal_vectorio_vector_shape_get_x(other_rect->draw_protocol_instance);
67-
mp_int_t other_right = other_left + other_rect->width;
68-
mp_int_t other_top = common_hal_vectorio_vector_shape_get_y(other_rect->draw_protocol_instance);
69-
mp_int_t other_bottom = other_top + other_rect->height;
70-
71-
return self_left < other_right && self_right > other_left &&
72-
self_top < other_bottom && self_bottom > other_top;
73-
}
74-
mp_obj_t possible_circle = mp_obj_cast_to_native_base(other_shape, &vectorio_circle_type);
75-
if (possible_circle != MP_OBJ_NULL) {
76-
vectorio_circle_t *other_circle = possible_circle;
77-
78-
mp_int_t self_left = common_hal_vectorio_vector_shape_get_x(self->draw_protocol_instance);
79-
mp_int_t self_right = self_left + self->width;
80-
mp_int_t self_top = common_hal_vectorio_vector_shape_get_y(self->draw_protocol_instance);
81-
mp_int_t self_bottom = self_top + self->height;
82-
83-
mp_int_t other_circle_x = common_hal_vectorio_vector_shape_get_x(other_circle->draw_protocol_instance);
84-
mp_int_t other_circle_y = common_hal_vectorio_vector_shape_get_y(other_circle->draw_protocol_instance);
85-
86-
mp_int_t test_x = other_circle_x;
87-
mp_int_t test_y = other_circle_y;
88-
89-
if (other_circle_x < self_left) {
90-
test_x = self_left;
91-
} else if (other_circle_x > self_right) {
92-
test_x = self_right;
93-
}
94-
95-
if (other_circle_y < self_top) {
96-
test_y = self_top;
97-
} else if (other_circle_y > self_bottom) {
98-
test_y = self_bottom;
99-
}
100-
101-
mp_int_t dist_x = other_circle_x - test_x;
102-
mp_int_t dist_y = other_circle_y - test_y;
103-
mp_int_t dist = sqrtf((dist_x * dist_x) + (dist_y * dist_y));
104-
105-
return dist <= other_circle->radius;
106-
}
107-
108-
return false;
109-
}
11054

11155
int16_t common_hal_vectorio_rectangle_get_width(void *obj) {
11256
vectorio_rectangle_t *self = obj;

shared-module/vectorio/__init__.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
bool common_hal_vectorio_circle_rectangle_intersects(
1515
int16_t cx, int16_t cy, int16_t cr,
16-
int16_t rx, int16_t ry, int16_t rw, int16_t rh){
16+
int16_t rx, int16_t ry, int16_t rw, int16_t rh) {
1717

1818
mp_int_t rect_left = rx;
1919
mp_int_t rect_right = rect_left + rw;
@@ -39,13 +39,13 @@ bool common_hal_vectorio_circle_rectangle_intersects(
3939
mp_int_t dist_y = cy - test_y;
4040
mp_int_t dist = (dist_x * dist_x) + (dist_y * dist_y);
4141

42-
return dist <= cr*cr;
42+
return dist <= cr * cr;
4343
}
4444

4545
bool common_hal_vectorio_circle_circle_intersects(
4646
int16_t c1x, int16_t c1y, int16_t c1r,
4747
int16_t c2x, int16_t c2y, int16_t c2r
48-
){
48+
) {
4949

5050
mp_int_t dist_x = c1x - c2x;
5151
mp_int_t dist_y = c1y - c2y;
@@ -58,7 +58,7 @@ bool common_hal_vectorio_circle_circle_intersects(
5858

5959
bool common_hal_vectorio_rectangle_rectangle_intersects(
6060
int16_t r1x, int16_t r1y, int16_t r1w, int16_t r1h,
61-
int16_t r2x, int16_t r2y, int16_t r2w, int16_t r2h){
61+
int16_t r2x, int16_t r2y, int16_t r2w, int16_t r2h) {
6262

6363

6464
mp_int_t r1_left = r1x;
@@ -73,4 +73,4 @@ bool common_hal_vectorio_rectangle_rectangle_intersects(
7373

7474
return r1_left < r2_right && r1_right > r2_left &&
7575
r1_top < r2_bottom && r1_bottom > r2_top;
76-
}
76+
}

0 commit comments

Comments
 (0)