Esempio n. 1
0
int main(int argc, char** argv) {
  plan_tests(43 + ARRAY_SIZE(Hypot_test_values));

  /* check the division operator */
  ok((fixed_one / fixed_one) * fixed(1000) == fixed(1000), "1/1", 0);
  ok((fixed_two / fixed_two) * fixed(1000) == fixed(1000), "2/2", 0);
  ok((fixed_one / fixed_two) * fixed(1000) == fixed(500), "1/2", 0);
  ok((fixed(1000) / fixed(100)) * fixed(1000) == fixed(10000), "1000/100", 0);
  ok((fixed(100) / fixed(20)) * fixed(1000) == fixed(5000), "100/20", 0);
  ok((fixed(1000000) / fixed(2)) * fixed(1000) == fixed(500000000), "1M/2", 0);
  ok((fixed_minus_one / fixed_one) * fixed(1000) == -fixed(1000), "-1/1", 0);
  ok((fixed_one / fixed_minus_one) * fixed(1000) == -fixed(1000), "1/-1", 0);
  ok((fixed_minus_one / fixed_minus_one) * fixed(1000) == fixed(1000), "-1/-1", 0);
  ok((fixed(-1000000) / fixed(2)) * fixed(1000) == -fixed(500000000), "-1M/2", 0);
  ok((long)((fixed_one / (fixed_one / fixed(10))) * fixed(1000)) == (10000), "1/0.1", 0);
  ok((long)((fixed_one / (fixed_one / fixed(-10))) * fixed(1000)) == -(10000) ||
     (long)((fixed_one / (fixed_one / fixed(-10))) * fixed(1000)) == -(10001), "1/-0.1", 0);

  ok(equals(fixed_one / fixed_half, 2), "1/0.5", 0);
  ok(equals(fixed(1000) / fixed_half, 2000), "1/0.5", 0);
  ok(equals(fixed(1000) / (fixed_one / 5), 5000), "1/0.5", 0);

  ok(equals(fixed(1000000) / (fixed_one / 5), 5000000), "1/0.5", 0);
  ok(equals(fixed(10000000) / (fixed_one / 5), 50000000), "1/0.5", 0);

  double da = 20.0;
  double dsina = sin(da);

  fixed a(da);
  fixed sina(sin(a));

  printf("a=%g, sin(a)=%g\n", FIXED_DOUBLE(a), FIXED_DOUBLE(sina));
  printf("a=%g, sin(a)=%g\n", da, dsina);

  ok(fabs(sina - fixed(dsina)) < fixed(1.0e-5), "sin(a)", 0);

  double dx = -0.3;
  double dy = 0.6;
  double dt = atan2(dy, dx);

  fixed x(dx);
  fixed y(dy);
  fixed t(atan2(y, x));

  printf("x=%g, y=%g atan(y,x)=%g\n",
         FIXED_DOUBLE(x), FIXED_DOUBLE(y), FIXED_DOUBLE(t));
  printf("x=%g, y=%g atan(y,x)=%g\n", dx, dy, dt);

  ok(fabs(t - fixed(dt)) < fixed(1.0e-5), "atan(y,x)", 0);

  {
    for (int i=1; i<=2048; i*= 2) {
      test_mag_rmag(i);
    }
  }

  test_hypot();

  return exit_status();
}
Esempio n. 2
0
FlatGeoPoint
FlatRay::parametric(const fixed t) const
{
  FlatGeoPoint p = point;
  p.Longitude += (int)(vector.Longitude*FIXED_DOUBLE(t));
  p.Latitude += (int)(vector.Latitude*FIXED_DOUBLE(t));
  return p;
}
Esempio n. 3
0
static bool
test_qnh_round2()
{
  AtmosphericPressure pres;
  pres.FindQNH(fixed(100), fixed(120));
  fixed p0 = pres.get_QNH()*100;
  fixed h0 = pres.StaticPressureToQNHAltitude(p0);
  if (verbose) {
    printf("%g %g\n",FIXED_DOUBLE(p0),FIXED_DOUBLE(h0));
  }
  return fabs(h0)<fixed(1);
}
Esempio n. 4
0
static bool
test_qnh_round2()
{
  AtmosphericPressure sp = AtmosphericPressure::Standard().QNHAltitudeToStaticPressure(fixed(100));
  AtmosphericPressure pres =
    AtmosphericPressure::FindQNHFromPressure(sp, fixed(120));
  fixed h0 = pres.StaticPressureToQNHAltitude(pres);
  if (verbose) {
    printf("%g %g\n", FIXED_DOUBLE(pres.GetPascal()), FIXED_DOUBLE(h0));
  }
  return fabs(h0)<fixed(1);
}
Esempio n. 5
0
static bool
test_isa_density(const fixed alt, const fixed prat)
{
  fixed p0 = AtmosphericPressure::AirDensity(alt);
  if (verbose) {
    printf("%g\n",FIXED_DOUBLE(p0));
  }
  return fabs(p0/fixed(1.225)-prat)<fixed(0.001);
}
Esempio n. 6
0
static bool
test_isa_pressure(const fixed alt, const fixed prat)
{
  AtmosphericPressure pres;
  fixed p0 = pres.QNHAltitudeToStaticPressure(alt);
  if (verbose) {
    printf("%g\n",FIXED_DOUBLE(p0));
  }
  return fabs(p0/fixed(101325)-prat)<fixed(0.001);
}
Esempio n. 7
0
static bool
test_qnh_to_static()
{
  AtmosphericPressure pres;
  fixed p0 = pres.QNHAltitudeToStaticPressure(fixed_zero);
  if (verbose) {
    printf("%g\n",FIXED_DOUBLE(p0));
  }
  return fabs(p0-fixed(101325))<fixed(0.1);
}
Esempio n. 8
0
static bool
test_qnh_round()
{
  AtmosphericPressure pres;
  pres.FindQNH(fixed(100), fixed(120));
  fixed h0 = pres.AltitudeToQNHAltitude(fixed(100));
  if (verbose) {
    printf("%g\n",FIXED_DOUBLE(h0));
  }
  return fabs(h0-fixed(120))<fixed(1);
}
Esempio n. 9
0
static bool
test_find_qnh2()
{
  AtmosphericPressure pres;
  pres.FindQNH(fixed(100), fixed(120));
  if (verbose) {
    printf("%g\n",FIXED_DOUBLE(pres.get_QNH()));
  }
  return fabs(pres.get_QNH()-fixed(1015.6))<fixed(0.1);
  // example, QNH=1014, ps=100203
  // alt= 100
  // alt_known = 120
  // qnh= 1016
}
Esempio n. 10
0
static bool
test_find_qnh2()
{
  AtmosphericPressure sp = AtmosphericPressure::Standard().QNHAltitudeToStaticPressure(fixed(100));
  AtmosphericPressure pres =
    AtmosphericPressure::FindQNHFromPressure(sp, fixed(120));
  if (verbose) {
    printf("%g\n",FIXED_DOUBLE(pres.GetHectoPascal()));
  }
  return fabs(pres.GetHectoPascal() - fixed(1015.6)) < fixed(0.1);
  // example, QNH=1014, ps=100203
  // alt= 100
  // alt_known = 120
  // qnh= 1016
}
Esempio n. 11
0
int main(int argc, char **argv)
{
  plan_tests(46);

  // test constructor
  GeoPoint p1(Angle::Degrees(fixed(345.32)), Angle::Degrees(fixed(-6.332)));
  ok1(equals(p1, -6.332, 345.32));

  // test normalize()
  p1.Normalize();
  ok1(equals(p1, -6.332, -14.68));

  // test parametric()
  GeoPoint p2(Angle::Degrees(fixed_two), Angle::Degrees(fixed_one));
  GeoPoint p3 = p1.Parametric(p2, fixed(5));
  ok1(equals(p3, -1.332, -4.68));

  // test interpolate
  GeoPoint p4 = p1.Interpolate(p3, fixed_half);
  ok1(equals(p4, -3.832, -9.68));

  GeoPoint p5 = p1.Interpolate(p3, fixed(0.25));
  ok1(equals(p5, -5.082, -12.18));

  // test *
  GeoPoint p6 = p2 * fixed(3.5);
  ok1(equals(p6, 3.5, 7));

  // test +
  p6 = p6 + p2;
  ok1(equals(p6, 4.5, 9));

  // test +=
  p6 += p2;
  ok1(equals(p6, 5.5, 11));

  // test -
  p6 = p6 - p2;
  ok1(equals(p6, 4.5, 9));

  // test sort()
  ok1(!p1.Sort(p3));
  ok1(p3.Sort(p1));
  ok1(!p1.Sort(p4));
  ok1(p4.Sort(p1));
  ok1(!p1.Sort(p5));
  ok1(p5.Sort(p1));
  ok1(!p4.Sort(p3));
  ok1(p3.Sort(p4));
  ok1(!p5.Sort(p3));
  ok1(p3.Sort(p5));
  ok1(!p5.Sort(p4));
  ok1(p4.Sort(p5));

  // test distance()
  //
  // note: distance between p1 and p4 and between p3 and p4 is not
  // the same due to linear interpolation instead of real geographic
  // intermediate point calculation
  ok1(equals(p2.Distance(p6), 869326.653160));
  ok1(equals(p6.Distance(p2), 869326.653160));
  ok1(equals(p1.Distance(p5), 309562.219016));
  ok1(equals(p1.Distance(p4), 619603.149273));
  ok1(equals(p1.Distance(p3), 1240649.267606));
  ok1(equals(p3.Distance(p4), 621053.760625));

  // test bearing()
  //
  // note: the bearings p1 -> p5, p5 -> p4 and so on are not the same due to
  // linear interpolation instead of real geographic intermediate point
  // calculation
  ok1(equals(p2.Bearing(p6), 63.272424));
  ok1(equals(p6.Bearing(p2), 243.608847));
  ok1(equals(p1.Bearing(p5), 63.449343));
  ok1(equals(p1.Bearing(p4), 63.582620));
  ok1(equals(p1.Bearing(p3), 63.784526));
  ok1(equals(p5.Bearing(p4), 63.466726));
  ok1(equals(p5.Bearing(p3), 63.646072));
  ok1(equals(p4.Bearing(p3), 63.540756));
  ok1(equals(p5.Bearing(p6), 65.982854));
  ok1(equals(p2.Bearing(p3), 250.786774));

  // test distance_bearing()
  // note: should be the same output as bearing() and distance()
  GeoVector v = p2.DistanceBearing(p6);
  ok1(equals(v.distance, 869326.653160));
  ok1(equals(v.bearing, 63.272424));

  // test intermediate_point()
  GeoPoint p7(Angle::Degrees(fixed_zero), Angle::Degrees(fixed_zero));
  GeoPoint p8 = p7.IntermediatePoint(p2, fixed(100000));
  ok1(equals(p8, 0.402274, 0.804342));
  ok1(equals(p8.Distance(p7), 100000));
  GeoPoint p9 = p7.IntermediatePoint(p2, fixed(100000000));
  ok1(equals(p9, p2));

  // test projected_distance()
  ok1(equals(p8.ProjectedDistance(p7, p2), 100000));
  ok1(equals(p4.ProjectedDistance(p1, p3), 619599.304393));
  ok1(equals((p2 * fixed_two).ProjectedDistance(p2, p6), 248567.832772));

  // Tests moved here from test_fixed.cpp
  GeoPoint l1(Angle::Zero(), Angle::Zero());
  GeoPoint l2(Angle::Degrees(fixed(-0.3)), Angle::Degrees(fixed(1.0)));
  GeoPoint l3(Angle::Degrees(fixed(0.00001)), Angle::Degrees(fixed_zero));
  GeoPoint l4(Angle::Degrees(fixed(10)), Angle::Degrees(fixed_zero));

  v = l1.DistanceBearing(l2);
  printf("Dist %g bearing %d\n",
         FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees()));
  // 116090 @ 343

  v = l1.DistanceBearing(l3);
  printf("Dist %g bearing %d\n",
         FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees()));
  ok(positive(v.distance) && v.distance < fixed_two, "earth distance short", 0);

  v = l1.DistanceBearing(l4);
  printf("Dist %g bearing %d\n",
         FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees()));

  return exit_status();
}