@@ -371,6 +371,18 @@ pg_circle_as_frect(pgCircleObject *self, PyObject *_null)
371371 return pgFRect_New4 ((float )x , (float )y , (float )diameter , (float )diameter );
372372}
373373
374+
375+ #define RECT_CIRCLE_CONTAINS (rect , circle , result ) \
376+ if (pgCollision_CirclePoint(scirc, (double)rect->x, (double)rect->y) && \
377+ pgCollision_CirclePoint(circle, (double)(rect->x + rect->w), \
378+ (double)rect->y) && \
379+ pgCollision_CirclePoint(circle, (double)rect->x, \
380+ (double)(rect->y + rect->h)) && \
381+ pgCollision_CirclePoint(circle, (double)(rect->x + rect->w), \
382+ (double)(rect->y + rect->h))) { \
383+ result = 1; \
384+ }
385+
374386static PyObject *
375387pg_circle_contains (pgCircleObject * self , PyObject * arg )
376388{
@@ -396,28 +408,12 @@ pg_circle_contains(pgCircleObject *self, PyObject *arg)
396408 else if (pgRect_Check (arg )) {
397409 SDL_Rect * temp = & pgRect_AsRect (arg );
398410
399- if (pgCollision_CirclePoint (scirc , (double )temp -> x , (double )temp -> y ) &&
400- pgCollision_CirclePoint (scirc , (double )(temp -> x + temp -> w ),
401- (double )temp -> y ) &&
402- pgCollision_CirclePoint (scirc , (double )temp -> x ,
403- (double )(temp -> y + temp -> h )) &&
404- pgCollision_CirclePoint (scirc , (double )(temp -> x + temp -> w ),
405- (double )(temp -> y + temp -> h ))) {
406- result = 1 ;
407- }
411+ RECT_CIRCLE_CONTAINS (temp , scirc , result );
408412 }
409413 else if (pgFRect_Check (arg )) {
410414 SDL_FRect * temp = & pgFRect_AsRect (arg );
411415
412- if (pgCollision_CirclePoint (scirc , (double )temp -> x , (double )temp -> y ) &&
413- pgCollision_CirclePoint (scirc , (double )(temp -> x + temp -> w ),
414- (double )temp -> y ) &&
415- pgCollision_CirclePoint (scirc , (double )temp -> x ,
416- (double )(temp -> y + temp -> h )) &&
417- pgCollision_CirclePoint (scirc , (double )(temp -> x + temp -> w ),
418- (double )(temp -> y + temp -> h ))) {
419- result = 1 ;
420- }
416+ RECT_CIRCLE_CONTAINS (temp , scirc , result );
421417 }
422418 else if (pg_TwoDoublesFromObj (arg , & x , & y )) {
423419 result = pgCollision_CirclePoint (scirc , x , y );
0 commit comments