Пример #1
0
Expr* expr_edge(Expr* x0, Expr* y0, Expr* x1, Expr* y1) {
  auto dx = expr_sub(x1,x0);
  auto dy = expr_sub(y1,y0);
  auto res = expr_sub(expr_mul(dy, expr_sub(expr_x(),x0)), expr_mul(dx, expr_sub(expr_y(),y0)));
  // printf("EDGE %s\n", res->to_str().c_str());
  return res;
}
Пример #2
0
Expr* expr_zmag(Expr* dz, Expr* g) {
  auto tg = expr_mag(expr_lit(1.0),expr_lit(1.0),dz,g);
  tg->copy_bbox(g);
  tg->zmin = expr_mul(dz, g->zmin);
  tg->zmax = expr_mul(dz, g->zmax);
  return tg;
}
Пример #3
0
Expr* expr_ymag(Expr* dy, Expr* g) {
  auto tg = expr_mag(expr_lit(1.0),dy,expr_lit(1.0),g);
  tg->copy_bbox(g);
  tg->ymin = expr_mul(dy, g->ymin);
  tg->ymax = expr_mul(dy, g->ymax);
  return tg;
}
Пример #4
0
Expr* expr_xmag(Expr* dx, Expr* g) {
  auto tg = expr_mag(dx,expr_lit(1.0),expr_lit(1.0),g);
  tg->copy_bbox(g);
  tg->xmin = expr_mul(dx, g->xmin);
  tg->xmax = expr_mul(dx, g->xmax);
  return tg;
}
Пример #5
0
Expr* expr_taper(Expr* dz, Expr* s0, Expr* s1, Expr* g) {
  auto zrad = expr_mul(expr_lit(0.5), dz);
  auto z0   = expr_neg(zrad);
  auto z1   = zrad;
  return new ExprXform(expr_mul(expr_x(), expr_div(dz,expr_add(expr_mul(s1,expr_sub(expr_z(),z0)), expr_mul(s0,expr_sub(z1,expr_z()))))),
                       expr_mul(expr_y(), expr_div(dz,expr_add(expr_mul(s1,expr_sub(expr_z(),z0)), expr_mul(s0,expr_sub(z1,expr_z()))))),
                       expr_z(),
                       g);
}
Пример #6
0
Expr* expr_rect2(Expr* xd, Expr* yd) {
  auto xrad = expr_mul(expr_lit(0.5), xd);
  auto yrad = expr_mul(expr_lit(0.5), yd);
  auto g = expr_and(expr_and(expr_sub(expr_neg(xrad),expr_x()), expr_sub(expr_x(),xrad)), 
                    expr_and(expr_sub(expr_neg(yrad),expr_y()), expr_sub(expr_y(),yrad)));
  g->xmin = expr_neg(xrad);
  g->xmax = xrad;
  g->ymin = expr_neg(yrad);
  g->ymax = yrad;
  return g;
}
Пример #7
0
Expr* expr_shear_x_z(Expr* z0, Expr* z1, Expr* dx0, Expr* dx1, Expr* g) {
  return new ExprXform(expr_sub(expr_x(),
                                expr_sub(dx0, expr_div(expr_mul(expr_sub(dx1,dx0),expr_sub(expr_z(),z0)),
                                                       expr_sub(z1,z0)))),
                       expr_y(),
                       expr_z(),
                       g);
}
Пример #8
0
Expr* expr_circle(Expr* d) {
  auto r = expr_mul(expr_lit(0.5), d);
  auto g = expr_sub(expr_sqrt(expr_add(expr_sqr(expr_x()), expr_sqr(expr_y()))),r);
  g->xmin = expr_neg(r);
  g->xmax = r;
  g->ymin = expr_neg(r);
  g->ymax = r;
  return g;
}
Пример #9
0
Expr* expr_square(Expr* d) {
  auto r = expr_mul(expr_lit(0.5), d);
  auto g = expr_and(expr_and(expr_sub(expr_neg(r),expr_x()), expr_sub(expr_x(),r)), 
                    expr_and(expr_sub(expr_neg(r),expr_y()), expr_sub(expr_y(),r)));
  g->xmin = expr_neg(r);
  g->xmax = r;
  g->ymin = expr_neg(r);
  g->ymax = r;
  return g;
}
Пример #10
0
Expr* expr_space(Expr* d) {
  auto r = expr_mul(expr_lit(0.5), d);
  auto g = new ExprSpace();
  g->xmin = expr_neg(r);
  g->xmax = r;
  g->ymin = expr_neg(r);
  g->ymax = r;
  g->zmin = expr_neg(r);
  g->zmax = r;
  return g;
}
Пример #11
0
Expr* expr_zbox(Expr* a, Expr* b) {
  Expr* za = expr_sub(a->zmax,a->zmin);
  Expr* zb = expr_sub(b->zmax,b->zmin);
  Expr* r  = expr_mul(expr_lit(0.5),expr_add(za,zb));
  auto tg  = expr_or(expr_zmov(expr_sub(expr_neg(r),a->zmin),a),
                     expr_zmov(expr_sub(expr_add(expr_neg(r),za),b->zmin),b));
  tg->zmin = expr_neg(r);
  tg->zmax = r;
  tg->xmin = expr_min(a->xmin, b->xmin);
  tg->xmax = expr_max(a->xmax, b->xmax);
  tg->ymin = expr_min(a->ymin, b->ymin);
  tg->ymax = expr_max(a->ymax, b->ymax);
  return tg;
}
Пример #12
0
Expr* expr_ybox(Expr* a, Expr* b) {
  Expr* ha = expr_sub(a->ymax,a->ymin);
  Expr* hb = expr_sub(b->ymax,b->ymin);
  Expr* r = expr_mul(expr_lit(0.5),expr_add(ha,hb));
  auto tg = expr_or(expr_ymov(expr_sub(expr_neg(r),a->ymin),a),expr_ymov(expr_sub(expr_add(expr_neg(r),ha),b->ymin),b));
  tg->ymin = expr_neg(r);
  tg->ymax = r;
  tg->xmin = expr_min(a->xmin, b->xmin);
  tg->xmax = expr_max(a->xmax, b->xmax);
  if (a->zmin != NULL && b->zmin != NULL) {
    tg->zmin = expr_min(a->zmin, b->zmin);
    tg->zmax = expr_max(a->zmax, b->zmax);
  }
  return tg;
}
Пример #13
0
Expr* expr_extrude(Expr* d, Expr* g) {
  auto r  = expr_mul(expr_lit(0.5), d);
  auto lo = expr_neg(r);
  auto hi = r;
  auto tg = expr_and(expr_and(expr_sub(lo,expr_z()), expr_sub(expr_z(),r)), g);
  tg->xmin = g->xmin;
  tg->xmax = g->xmax;
  tg->ymin = g->ymin;
  tg->ymax = g->ymax;
  tg->zmin = lo;
  tg->zmax = hi;
  // printf("CHECKING EXT TG %p INF XMIN %p YMIN %p ZMIN %p XMAX %p YMAX %p ZMAX %p \n", 
  //        tg, tg->xmin, tg->ymin, tg->zmin, tg->xmax, tg->ymax, tg->zmax);
  return tg;
}
Пример #14
0
Expr* expr_mag1(Expr* dxyz, Expr* g) {
  auto tg = new ExprXform(expr_div(expr_x(), dxyz), expr_div(expr_y(), dxyz), expr_div(expr_z(), dxyz), g);
  tg->xmin = expr_mul(dxyz, g->xmin);
  tg->xmax = expr_mul(dxyz, g->xmax);
  tg->ymin = expr_mul(dxyz, g->ymin);
  tg->ymax = expr_mul(dxyz, g->ymax);
  tg->zmin = expr_mul(dxyz, g->zmin);
  tg->zmax = expr_mul(dxyz, g->zmax);
  return tg;
}
Пример #15
0
Expr* expr_mag(Expr* dx, Expr* dy, Expr* dz, Expr* g) {
  auto tg = new ExprXform(expr_div(expr_x(), dx), expr_div(expr_y(), dy), expr_div(expr_z(), dz), g);
  tg->xmin = expr_mul(dx, g->xmin);
  tg->xmax = expr_mul(dx, g->xmax);
  tg->ymin = expr_mul(dy, g->ymin);
  tg->ymax = expr_mul(dy, g->ymax);
  tg->zmin = expr_mul(dz, g->zmin);
  tg->zmax = expr_mul(dz, g->zmax);
  return tg;
}
Пример #16
0
static void test_compound()
{
    char *rn_from[] = {"a2"};
    char *rn_to[] = {"a"};
    char *pn[] = {"a2", "c"};

    Rel *tmp = load("compound_1");

    int a;
    Type ta;
    head_attr(tmp->head, rn_to[0], &a, &ta);

    Expr *e[] = { expr_mul(expr_int(10), expr_attr(a, Int)) };
    tmp = rel_extend(tmp, rn_from, e, 1);
    tmp = rel_project(tmp, pn, 2);
    tmp = rel_rename(tmp, rn_from, rn_to, 1);
    tmp = rel_union(tmp, load("compound_1"));

    if (!equal(tmp, "compound_1_res"))
        fail();

    /* compound with a parameter */
    char *names[] = {"car", "date", "email", "name", "phone", "pos", "when"};
    Type types[] = {String, String, String, String, String, Int, Int};
    char union_2_l[1024];
    str_cpy(union_2_l,
            "car,date,email,name,phone,pos,when\n"
            "myCar,28-Jun-2010,myEmail,myName,myPhone,2,14");

    if (!equal(rel_union(pack(union_2_l, names, types, 7),
                         load("union_2_r")),
               "union_2_res"))
        fail();

    str_cpy(union_2_l,
            "car,date,email,name,phone,pos,when\n"
            "myCar,28-Jun-2010,myEmail,myName,myPhone,2,14");
    if (!equal(rel_union(load("union_2_r"),
                         pack(union_2_l, names, types, 7)),
               "union_2_res"))
        fail();
}
Пример #17
0
static void test_arithmetic()
{
    double d0 = 0.0;
    double d1 = 0.0;

    Expr *e_isum = expr_sum(expr_int(2), expr_int(2));
    Expr *e_lsum = expr_sum(expr_long(2), expr_long(2));
    Expr *e_rsum = expr_sum(expr_real(2.2), expr_real(2.2));

    Expr *e_isub = expr_sub(expr_int(3), expr_int(7));
    Expr *e_lsub = expr_sub(expr_long(3), expr_long(7));
    Expr *e_rsub = expr_sub(expr_real(1.3), expr_real(0.3));

    Expr *e_idiv = expr_div(expr_int(8), expr_int(4));
    Expr *e_ldiv = expr_div(expr_long(8), expr_long(4));
    Expr *e_rdiv = expr_div(expr_real(3.0), expr_real(0.1));

    Expr *e_imul = expr_mul(expr_int(5), expr_int(5));
    Expr *e_lmul = expr_mul(expr_long(5), expr_long(5));
    Expr *e_rmul = expr_mul(expr_real(5.0), expr_real(0.5));

    if (4 != val_int(expr_new_val(e_isum, NULL, NULL)))
        fail();
    if (4LL != val_long(expr_new_val(e_lsum, NULL, NULL)))
        fail();

    d0 = val_real(expr_new_val(e_rsum, NULL, NULL));
    d1 = 4.4;
    if (d1 != d0)
        fail();

    if (-4 != val_int(expr_new_val(e_isub, NULL, NULL)))
        fail();
    if (-4LL != val_long(expr_new_val(e_lsub, NULL, NULL)))
        fail();

    d0 = val_real(expr_new_val(e_rsub, NULL, NULL));
    d1 = 1.0;
    if (d1 != d0)
        fail();

    if (2 != val_int(expr_new_val(e_idiv, NULL, NULL)))
        fail();
    if (2LL != val_long(expr_new_val(e_ldiv, NULL, NULL)))
        fail();

    d0 = val_real(expr_new_val(e_rdiv, NULL, NULL));
    d1 = 30;
    if (d1 != d0)
        fail();

    if (25 != val_int(expr_new_val(e_imul, NULL, NULL)))
        fail();
    if (25 != val_long(expr_new_val(e_lmul, NULL, NULL)))
        fail();

    d0 = val_real(expr_new_val(e_rmul, NULL, NULL));
    d1 = 2.5;
    if (d1 != d0)
        fail();

    expr_free(e_isum);
    expr_free(e_lsum);
    expr_free(e_rsum);

    expr_free(e_isub);
    expr_free(e_lsub);
    expr_free(e_rsub);

    expr_free(e_idiv);
    expr_free(e_ldiv);
    expr_free(e_rdiv);

    expr_free(e_imul);
    expr_free(e_lmul);
    expr_free(e_rmul);
}
Пример #18
0
Expr* expr_abs (Expr* a) { return expr_mul(a, a); }
Пример #19
0
Expr* expr_sqr (Expr* a) { return expr_mul(a, a); }
Пример #20
0
Expr* expr_zrot(Expr* a, Expr* g) {
  auto sa = expr_sin(a);
  auto ca = expr_cos(a);
  return new ExprXform(expr_add(expr_mul(ca, expr_x()), expr_mul(sa, expr_y())), expr_add(expr_mul(expr_neg(sa), expr_x()), expr_mul(ca, expr_y())), expr_z(), g);
}
Пример #21
0
Expr* expr_half(Expr* nx, Expr* ny, Expr* nz, Expr* d) {
  return expr_sub(d, expr_add(expr_mul(expr_x(), nx), expr_add(expr_mul(expr_y(), ny), expr_mul(expr_z(), nz))));
}