static void test_normalise_err(const int x, const int y) { int x0=x; int y0=y; i_normalise(x0, y0); int mag0 = iround((fixed)sqrt(x0*x0+y0*y0)); int error0 = abs((1<<NORMALISE_BITS)-mag0); int x1=x; int y1=y; i_normalise_fast(x1, y1); int mag1 = ihypot(x1, y1); int error1 = abs((1<<NORMALISE_BITS)-mag1); bool err_ok = error1<= error0+1; if (!err_ok) { printf("# %d %d %d %d %d %d %d %d %d %d\n", x, y, x0, y0, mag0, error0, x1, y1, mag1, error1); } char label[80]; sprintf(label,"fast integer normalise error x=%d y=%d", x, y); ok(err_ok, label, 0); }
unsigned FlatBoundingBox::Distance(const FlatBoundingBox &f) const { unsigned dx = Distance1D(lower_left.x, upper_right.x, f.lower_left.x, f.upper_right.x); unsigned dy = Distance1D(lower_left.y, upper_right.y, f.lower_left.y, f.upper_right.y); return ihypot(dx, dy); }
static int placesystems(void) { int i, j, k; /* looping vars */ double x=0, y=0; /* to hold star coordinates */ int done; /* flag to indicate done */ double dx, dy; /* delta x and y's */ int n; /* number of planet to place */ int np; /* number of planets in system */ int attempts; n = SYSTEMS; /* first planet to place */ for (i = 0; i < SYSTEMS; i++) { /* planets for each system */ np = SYSPLMIN + lrand48() % (SYSPLADD + 1); /* how many planets */ for (k = 0; k < np; k++) { /* go place the planets */ attempts = 0; do { /* do until location found */ attempts++; done = 0; /* not done yet */ dx = (drand48() * SYSWIDTH - SYSWIDTH / 2.0); dy = (drand48() * SYSWIDTH - SYSWIDTH / 2.0); if (dx * dx + dy * dy > (SYSWIDTH / 2.0) * (SYSWIDTH / 2.0)) continue; /* might orbit its way out of the galaxy */ x = planets[i].pl_x + dx; y = planets[i].pl_y + dy; if ((x > GW - SYSBORD) || (x < SYSBORD) || (y < SYSBORD) || (y > GW - SYSBORD)) continue; /* too close to border? */ done = 1; /* assume valid coord found */ for (j = 0; j < n; j++) { /* go through previous planets */ dx = fabs(x - (double) planets[j].pl_x); dy = fabs(y - (double) planets[j].pl_y); if (dx * dx + dy * dy < SYSMIN2) { /* if too close to another star */ done = 0; /* we must get another coord */ } if( ihypot( (int)dx, (int)dy) < 3000 ) done = 0; } } while (!done && attempts < 200); /* do until location found */ if (!done) return 0; /* universe too crowded, try again */ move_planet(n, (int) x, (int) y, 0); planets[n].pl_system = i + 1; /* mark the sytem number */ planets[n].pl_armies = MINARMY + lrand48() % (MAXARMY - MINARMY); n++; /* go to next planet */ } } return (n); /* return index of next planet */ }
unsigned FlatBoundingBox::Distance(const FlatBoundingBox &f) const { if (Overlaps(f)) return 0; int dx = std::max(0, std::min(f.bb_ll.x - bb_ur.x, bb_ll.x - f.bb_ur.x)); int dy = std::max(0, std::min(f.bb_ll.y - bb_ur.y, bb_ll.y - f.bb_ur.y)); return ihypot(dx, dy); }
int FlatRay::Magnitude() const { return ihypot(vector.longitude, vector.latitude); }
unsigned FlatGeoPoint::Distance(const FlatGeoPoint &sp) const { const FlatGeoPoint delta = *this - sp; return ihypot(delta.Longitude, delta.Latitude); }