(define (touching_rectangle-circle? otherObj)
;I know rectangle is the first object because the type is 'rectangle-circle
(let* ((width (obj 'getWidth))
(height (obj 'getHeight))
(obj_X ((obj 'getOrigin) 'getX))
(obj_Y ((obj 'getOrigin) 'getY))
(otherObj_X ((otherObj 'getOrigin) 'getX))
(otherObj_Y ((otherObj 'getOrigin) 'getY))
(radius (obj 'getRadius))
(circleDistance_X (abs (- otherObj_X obj_X (/ width 2))))
(circleDistance_Y (abs (- otherObj_Y obj_Y (/ height 2)))))
;(println circleDistance_X "-" circleDistance_Y "-" (otherObj 'getOrigin))
(cond ;Easy cases where the circle could not possibly touch the rect
((> circleDistance_X (+ (/ width 2) radius)) #f)
((> circleDistance_Y (+ (/ height 2) radius)) #f)
;Intersection is guaranteed, excludes calculation for corners
((<= circleDistance_X (/ width 2)) #t)
((<= circleDistance_Y (/ height 2)) #t)
;The difficult case where it may be touching the corner
(else (let ((cornerDistance_squared (+ (expt (- circleDistance_X (/ width 2)) 2)
(expt (- circleDistance_Y (/ height 2)) 2))))
(<= cornerDistance_squared (expt radius 2)))))))