The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

haha1111 (5) [Avatar] Offline
#1
If you look closly at Fig 6.5 output of listing 6.6, you'll see the double circles. I believe it's due to a rounding error:

Book version of listing 6.6 has:
void updateMe() {
[...]
midx = (x + otherCirc.x)/2;
midy = (y + otherCirc.y)/2;
stroke(0, 100);
noFill();
overlap *= -1;
ellipse(midx, midy, overlap, overlap);

to see it better, swap this line:
stroke(0, 100);

with:
if (radius >= otherCirc.radius) {
stroke(255, 0, 0, 100); // red one way
} else {
stroke(0, 0, 255, 100); // blue the other way
}

Once you see the red/blue pair of the rounding effect, or discover you are red/blue color blind. Here's a cure for the double vision:

if (radius >= otherCirc.radius) { //add line 1 of 2
stroke(0, 100);
noFill();
overlap *= -1;
ellipse(midx, midy, overlap, overlap);
} //add line 2 of 2

Note that each pairs are processed twice, you only need one circle to be drawn for each pair. The two added lines picks only one (except when they are equal in size).

Cheers,
haha