Exemple #1
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;
  VsgVector3d v;
  gdouble res, ref;

  if (argc > 1 && g_ascii_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  vsg_vector3d_set (&v, 1, 0, 0);
  res = vsg_vector3d_norm (&v);
  ref = 1;
  ret += dcheck ("|[1, 0, 0]|== 1", res, ref);

  vsg_vector3d_set (&v, 0, 1, 0);
  res = vsg_vector3d_norm (&v);
  ref = 1;
  ret += dcheck ("|[0, 1, 0]| == 1", res, ref);

  vsg_vector3d_set (&v, 1, 2, 3);
  res = vsg_vector3d_norm (&v);
  ref = 3.741657387;
  ret += dcheck ("|[1, 2, 3]| == 3.741657387", res, ref);

  vsg_vector3d_set (&v, 0.1, 0.2, 0.3);
  res = vsg_vector3d_norm (&v);
  ref = 0.3741657387;
  ret += dcheck ("|[0.1, 0.2, 0.3]| == 0.3741657387", res, ref);

  vsg_vector3d_set (&v, 1.2e-2, 0, 0);
  res = vsg_vector3d_norm (&v);
  ref = 0.012;
  ret += dcheck ("|[1.2e-2, 0, 0]| == 0.012", res, ref);

  vsg_vector3d_set (&v, 1.2e-3, 0, 0);
  res = vsg_vector3d_norm (&v);
  ref = 0.0012;
  ret += dcheck ("|[1.2e-3, 0, 0]| == 0.0012", res, ref);

  vsg_vector3d_set (&v, 0, 0, 0);
  res = vsg_vector3d_norm (&v);
  ref = 0;
  ret += dcheck ("|[0, 0, 0]| == 0", res, ref);

  vsg_vector3d_set (&v, 1, 1, 1);
  res = vsg_vector3d_norm (&v);
  ref = 1.732050808;
  ret += dcheck ("|[1, 1, 1]| == 1.732050808", res, ref);

  vsg_vector3d_set (&v, 1, 2.123, 4.56);
  res = vsg_vector3d_norm (&v);
  ref = 5.128423637;
  ret += dcheck ("|[1, 2.123, 4.56]| == 5.128423637", res, ref);

  return ret;
}
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgVector3d lb = {-1., -1., -1.};
  VsgVector3d ub = {1., 1., 1.};

  VsgVector3d *points;
  gint lvl = 1;
  gint n, np;

  VsgPRTree3d *tree;
  gint i, j, k, l;

  if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  if (argc > 1)
    {
      sscanf (argv[1], "%d", &lvl);
    }

  n = 1<<lvl;
  np = n*n*n;

  vsg_init_gdouble ();

  /* create the points */
  points = g_malloc (np * sizeof (VsgVector3d));
  l = 0;
  for (i=0; i<n; i++)
    {
      gdouble x = 2. * ((i+0.5)/n) - 1.;

      for (j=0; j<n; j++)
        {
          gdouble y = 2. * ((j+0.5)/n) - 1.;

          for (k=0; k<n; k++)
            {
              gdouble z = 2. * ((k+0.5)/n) - 1.;

              vsg_vector3d_set (&points[l], x, y, z);
              l ++;
            }
        }
    }

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           NULL, 1);

  /* configure for hilbert curve order traversal */
  vsg_prtree3d_set_children_order (tree, hilbert3_order,
                                   GINT_TO_POINTER (HK3_0_2_1));

  /* insert some points */
  for (i=0; i<np; i++)
    {
      vsg_prtree3d_insert_point (tree, &points[i]);
    }

  /* do some traversal */
  i=0;
  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) traverse_point_count, &i);

  /* check the results */
  if (i != np)
    {
      g_printerr ("ERROR: traverse point count %d (should be %d)\n",
                  i, n);

      ret ++;
    }

  /* remove the points */
  for (i=0; i<np; i++)
    {
      vsg_prtree3d_remove_point (tree, &points[i]);
    }

  g_free (points);

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  return ret;
}
Exemple #3
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;
  VsgVector3d v, w, res, ref;

  if (argc > 1 && g_ascii_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  vsg_vector3d_set (&v, 1, 0, 0);
  vsg_vector3d_set (&w, 0, 1, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 1);
  ret += vcheck ("[1, 0, 0] ^ [0, 1, 0] == [0, 0, 1]", &res, &ref);

  vsg_vector3d_set (&v, 1, 2, 3);
  vsg_vector3d_set (&w, 0.1, 0.2, 0.3);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 0);
  ret += vcheck ("[1, 2, 3] ^ [0.1, 0.2, 0.3] == [0, 0, 0]", &res, &ref);

  vsg_vector3d_set (&v, 1.2e-2, 0, 0);
  vsg_vector3d_set (&w, 1.2e-3, 0, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 0);
  ret += vcheck ("[1.2e-2, 0, 0] ^ [1.2e-3, 0, 0] == [0, 0, 0]", &res, &ref);

  vsg_vector3d_set (&v, 0, 0, 0);
  vsg_vector3d_set (&w, 0, 0, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, 0, 0, 0);
  ret += vcheck ("[0, 0, 0] ^ [0, 0, 0] == [0, 0, 0]", &res, &ref);

  vsg_vector3d_set (&v, 1, 1, 1);
  vsg_vector3d_set (&w, 1, 2.123, 0);
  vsg_vector3d_vecp (&v, &w, &res);
  vsg_vector3d_set (&ref, -2.123, 1, 1.123);
  ret += vcheck ("[1, 1, 1] ^ [1, 2.123, 0] == [-2.123, 1, 1.123]", &res,
                 &ref);

  return ret;
}
Exemple #4
0
static void point_accum_clear_accum (PointAccum *pa)
{
  vsg_vector3d_set (&pa->field, 0., 0., 0.);
}