@@ -371,6 +371,18 @@ pg_circle_as_frect(pgCircleObject *self, PyObject *_null)
371
371
return pgFRect_New4 ((float )x , (float )y , (float )diameter , (float )diameter );
372
372
}
373
373
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
+
374
386
static PyObject *
375
387
pg_circle_contains (pgCircleObject * self , PyObject * arg )
376
388
{
@@ -396,28 +408,12 @@ pg_circle_contains(pgCircleObject *self, PyObject *arg)
396
408
else if (pgRect_Check (arg )) {
397
409
SDL_Rect * temp = & pgRect_AsRect (arg );
398
410
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 );
408
412
}
409
413
else if (pgFRect_Check (arg )) {
410
414
SDL_FRect * temp = & pgFRect_AsRect (arg );
411
415
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 );
421
417
}
422
418
else if (pg_TwoDoublesFromObj (arg , & x , & y )) {
423
419
result = pgCollision_CirclePoint (scirc , x , y );
0 commit comments