In the intersection example, the code looks for the distance between point (x1,y1) and (x2,y2). However the code reads:

float distance = dist(x1,y2,x2,y2);

and it should be:

float distance = dist(x1,y1,x2,y2);

This occurs on both p. 172 and p. 173.