Esempio n. 1
0
// Fit a quadratic warping function to the given points
// in a least-squares fashion
quadratic_2d find_quadratic(const double *out, const double *x,
                            const double *y, int numPts)
{
  int nTerms = 11;
  matrix *m = matrix_alloc(nTerms, nTerms + 1);
  int row, col;
  int i;
  quadratic_2d c;
  // For each data point, add terms to matrix
  for (i = 0; i < numPts; i++) {
    for (row=0;row<nTerms;row++) {
      double partial_Q = get_term(row, x[i], y[i]);
      for (col = 0; col < nTerms; col++) {
          m->coeff[row][col] += partial_Q * get_term(col, x[i], y[i]);
      }
      m->coeff[row][nTerms] += partial_Q * out[i];
    }
  }
  // Now solve matrix to find coefficients
  // matrix_print(m,"\nLeast-Squares Matrix:\n",stdout);
  matrix_solve(m);
  c.A = m->coeff[0][nTerms];
  c.B = m->coeff[1][nTerms];
  c.C = m->coeff[2][nTerms];
  c.D = m->coeff[3][nTerms];
  c.E = m->coeff[4][nTerms];
  c.F = m->coeff[5][nTerms];
  c.G = m->coeff[6][nTerms];
  c.H = m->coeff[7][nTerms];
  c.I = m->coeff[8][nTerms];
  c.J = m->coeff[9][nTerms];
  c.K = m->coeff[10][nTerms];

  return c;
}
Esempio n. 2
0
void GrGetCoeffBlendKnownComponents(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff,
                                    GrColor srcColor, GrColorComponentFlags srcColorFlags,
                                    GrColor dstColor, GrColorComponentFlags dstColorFlags,
                                    GrColor* outColor,
                                    GrColorComponentFlags* outFlags) {
    MaskedColor src(srcColor, srcColorFlags);
    MaskedColor dst(dstColor, dstColorFlags);

    MaskedColor srcTerm = get_term(srcCoeff, src, dst, src);
    MaskedColor dstTerm = get_term(dstCoeff, src, dst, dst);

    MaskedColor output = MaskedColor::SatAdd(srcTerm, dstTerm);
    *outColor = output.color();
    *outFlags = output.validFlags();
}
Esempio n. 3
0
/*
** Builds termcaps sequences
** @params self, env
** @return bool; Success => TRUE, Error => FALSE
*/
bool		line_editor_build_sequences(t_line_editor *self, char **env)
{
  int		ret;
  char		*key_pad;

  setupterm(get_term(env), 1, &ret);
  if (ret <= 0)
    return (false);
  if ((key_pad = tigetstr("smkx")) == NULL)
    return (false);
  putp(key_pad);
  if ((self->keys[L_KEY_LEFT].sequence = dup_key("kcub1")) == NULL)
    return (false);
  self->keys[L_KEY_LEFT].handle = line_editor_handle_left;
  if ((self->keys[L_KEY_RIGHT].sequence = dup_key("kcuf1")) == NULL)
    return (false);
  self->keys[L_KEY_RIGHT].handle = line_editor_handle_right;
  if ((self->keys[L_KEY_UP].sequence = dup_key("kcuu1")) == NULL)
    return (false);
  self->keys[L_KEY_UP].handle = line_editor_handle_up;
  if ((self->keys[L_KEY_DOWN].sequence = dup_key("kcud1")) == NULL)
    return (false);
  self->keys[L_KEY_DOWN].handle = line_editor_handle_down;
  if (line_editor_build_second_sequences(self) == false)
    return (false);
  return (true);
}
Esempio n. 4
0
File: main.c Progetto: oleiade/Ash
static char	*get_buffer(t_list *histo)
{
    t_tutils	utils;

    xwrite(1, PROMPT, strlen(PROMPT));
    if (get_term() || init_termcaps(&utils))
        return (get_next_line(0));
    else
        return (termcaps(&utils, histo));
}
Esempio n. 5
0
static node_t *get_termtail(token_stack_t *stack, node_t *left_expr,
                            GError **err)
{
    const token_t *token;
    node_t *op, *expr;
    GError *tmp_err = NULL;

    g_assert(stack);

    token = token_peak(stack);

    /* Is the tail an empty string? Then just give the left_expr back. */
    if (token == NULL) {
        g_free(token_pop(stack));
        return left_expr;
    } else if (token->type == TOK_RPAREN)
        return left_expr;

    /* First, there should an operator ... */
    if (token->type != TOK_OPERATOR) {
        set_error(err, "Expected operator", token);
        return left_expr;
    }

    op = g_malloc(sizeof(node_t));
    op->left = left_expr;
    op->type = NODE_OPERATOR;
    switch (token->val.op) {
    case '+':
        op->val.op = OP_PLUS;
        break;
    case '-':
        op->val.op = OP_MINUS;
        break;
    default:
        set_error(err, "Expected '+' or '-'", token);
        g_free(op);
        return left_expr;
    }
    g_free(token_pop(stack));

    /* ... then there should be a term ... */
    op->right = get_term(stack, &tmp_err);
    if (tmp_err) {
        g_propagate_error(err, tmp_err);
        return op;
    }

    /* ... and finally another termtail. */
    expr = get_termtail(stack, op, &tmp_err);
    if (tmp_err)
        g_propagate_error(err, tmp_err);

    return expr;
}
Esempio n. 6
0
/*
 * Process any signals we have received.
 * A received signal cause a bit to be set in "sigs".
 */
void
psignals(void)
{
	int tsignals;

	if ((tsignals = sigs) == 0)
		return;
	sigs = 0;

	if (tsignals & S_STOP) {
		/*
		 * Clean up the terminal.
		 */
		lsignal(SIGTTOU, SIG_IGN);
		clear_bot();
		deinit();
		flush(0);
		raw_mode(0);
		lsignal(SIGTTOU, SIG_DFL);
		lsignal(SIGTSTP, SIG_DFL);
		kill(getpid(), SIGTSTP);
		/*
		 * ... Bye bye. ...
		 * Hopefully we'll be back later and resume here...
		 * Reset the terminal and arrange to repaint the
		 * screen when we get back to the main command loop.
		 */
		lsignal(SIGTSTP, stop);
		raw_mode(1);
		init();
		screen_trashed = 1;
		tsignals |= S_WINCH;
	}
	if (tsignals & S_WINCH) {
		int old_width, old_height;
		/*
		 * Re-execute scrsize() to read the new window size.
		 */
		old_width = sc_width;
		old_height = sc_height;
		get_term();
		if (sc_width != old_width || sc_height != old_height) {
			wscroll = (sc_height + 1) / 2;
			calc_jump_sline();
			calc_shift_count();
			screen_trashed = 1;
		}
	}
	if (tsignals & S_INTERRUPT) {
		ring_bell();
		if (quit_on_intr)
			quit(QUIT_INTERRUPT);
	}
}
Esempio n. 7
0
int				termcap_init(void)
{
	char				*name_term;

	manage_signal();
	if ((get_stuff()->fd = open(ttyname(0), O_WRONLY | O_NOCTTY)) == -1)
		return (-1);
	if ((name_term = getenv("TERM")) == NULL)
		return (-1);
	if (tgetent(NULL, name_term) == -1)
		return (-1);
	if (tcgetattr(get_stuff()->fd, get_term()) == -1)
		return (-1);
	get_term()->c_lflag &= ~(ICANON | ECHO);
	get_term()->c_cc[VMIN] = 1;
	get_term()->c_cc[VTIME] = 0;
	if (tcsetattr(get_stuff()->fd, TCSADRAIN, get_term()) == -1)
		return (-1);
	tputs(tgetstr("ti", NULL), 1, ft_putchr);
	hide_cursor();
	enable_keyboard();
	get_s_win();
	return (0);
}
Esempio n. 8
0
static void smt_eval_mk_eq(tstack_t *stack, stack_elem_t *f, uint32_t n) {
  term_t *arg, last, first, t;
  uint32_t i;

  if (n == 2) {
    first = get_term(stack, f);
    last = get_term(stack, f+1);
    t = yices_eq(first, last);
  } else {
    arg = get_aux_buffer(stack, n);
    n --;
    last = get_term(stack, f+n);
    for (i=0; i<n; i++) {
      t = yices_eq(get_term(stack, f+i), last);
      check_term(stack, t);
      arg[i] = t;
    }
    t = yices_and(n, arg);
  }
  check_term(stack, t);

  tstack_pop_frame(stack);
  set_term_result(stack, t);
}
/* PUBLIC */
Term get_rigid_term(char *sym, int arity)
{
  Term t1;
  int sn;
  if (arity > MAX_ARITY) {
    printf("\nArity %d requested for symbol \"%s\"\n", arity, sym);
    fprintf(stderr, "\nArity %d requested for symbol \"%s\".\n", arity, sym);
    fatal_error("get_rigid_term, arity too big");
  }
  t1 = get_term(arity);
  sn = str_to_sn(sym, arity);
  if (sn >= MAX_SYM)
    fatal_error("get_rigid_term, too many symbols");
  t1->private_symbol = -sn;
  return t1;
}  /* get_rigid_term */
Esempio n. 10
0
int	init_sequences(t_config *config, char **env)
{
  int	i;

  if (setupterm(get_term(env), 1, &i) == 1 || i != 1)
    return (-1);
  if (config->drop == NULL)
    config->drop = tigetstr("kcud1");
  if (config->left == NULL)
    config->left = tigetstr("kcub1");
  if (config->right == NULL)
    config->right = tigetstr("kcuf1");
  if (config->turn == NULL)
    config->turn = tigetstr("kcuu1");
  return (0);
}
Esempio n. 11
0
int             my_underlinere()
{
  char          *res;
  extern char   **environ;

  if (tgetent(NULL, get_term(environ)) == 0)
    {
      my_putstr("problem terminal");
      return (2);
    }
  if ((res = tgetstr("ue", NULL)) == NULL)
    {
      my_putstr("bad termcaps");
      return (1);
    }
  tputs(res, 1, my_outc);
  return (0);
}
Esempio n. 12
0
static node_t *get_expr(token_stack_t *stack, GError **err)
{
    node_t *term, *expr;
    GError *tmp_err = NULL;
    const token_t *token;

    token = token_peak(stack);
    if (token == NULL || token->type == TOK_RPAREN) return NULL;

    term = get_term(stack, &tmp_err);
    if (tmp_err) {
        g_propagate_error(err, tmp_err);
        return term;
    }

    expr = get_termtail(stack, term, &tmp_err);
    if (tmp_err)
        g_propagate_error(err, tmp_err);

    return expr;
}
Esempio n. 13
0
static YAP_Term build_list(list l, int current_pos)
{
    if (l.size > 0)
    {
        if (l.nDims > 1)
        {
            YAP_Term curr_term = YAP_MkAtomTerm(YAP_LookupAtom("[]"));
            int cDims = l.dims[0], i, j, k, inc = cDims;

            for (i = cDims - 1; i >= 0; i--)
            {
                list newL;
                newL.nDims = l.nDims - 1;
                newL.size = l.size / cDims;
                k = 0;

                for (j = 1; j < l.nDims; j++)
                    newL.dims[j - 1] = l.dims[j];
                for (j = i; j < l.size; j += inc)
                    newL.values[k++] = l.values[j];

                curr_term = YAP_MkPairTerm(build_list(newL, 0), curr_term);
            }

            return curr_term;
        }
        else
        {
            YAP_Term curr_term = get_term(l.values[current_pos]);
            if (current_pos == l.size - 1)
                return YAP_MkPairTerm(curr_term, 
                                      YAP_MkAtomTerm(YAP_LookupAtom("[]")));
            else
                return YAP_MkPairTerm(curr_term, 
                                      build_list(l, current_pos + 1));
        }
    }

    return YAP_MkAtomTerm(YAP_LookupAtom("[]"));
}
Esempio n. 14
0
/* PUBLIC */
Term get_rigid_term_dangerously(int symnum, int arity)
{
  Term t1 = get_term(arity);
  t1->private_symbol = -symnum;
  return t1;
}  /* get_rigid_term_dangerously */
Esempio n. 15
0
/* PUBLIC */
Term get_rigid_term_like(Term t)
{
  Term t1 = get_term(ARITY(t));
  t1->private_symbol = t->private_symbol;
  return t1;
}  /* get_rigid_term_like */
Esempio n. 16
0
/*
 * Z_Operandを文字列に変換して返す。
 * まだgeneral以外には未対応。
 */
void get_operand(char *term, Z_Operand *op, bend_searchresult *r)
{
  int i = 0;
  char buf[BUFSIZE];
  char buf_term[BUFSIZE];
  Z_AttributeElement *element;

  term[0]='\0';

  switch (op->which) {
  case Z_Operand_APT:
    if (! op->u.attributesPlusTerm->num_attributes) {
      get_term(term, op->u.attributesPlusTerm->term, r);
      return;
    }
    /* AttributeListを見る */
    while (i < op->u.attributesPlusTerm->num_attributes) {
      element = op->u.attributesPlusTerm->attributeList[i];
      switch (*element->attributeType) {
      case 1:
	switch (element->which) {
	case Z_AttributeValue_numeric:
	  switch (*element->value.numeric) {
	  case 1016: /* 全部 (Any) */
	    get_term(buf_term, op->u.attributesPlusTerm->term, r);
	    strcat(term, buf_term);
	    logf(LOG_DEBUG, "This is Any search");
	    break;
	  case 4:    /* 書名 (Title) */
	    get_term(buf_term, op->u.attributesPlusTerm->term, r);
	    sprintf(buf, "+title:%s", buf_term);
	    strcat(term, buf);
	    logf(LOG_DEBUG, "This is Title-field search");
	    break;
	  case 1003: /* 著者名 (Author) */
	    get_term(buf_term, op->u.attributesPlusTerm->term, r);
	    sprintf(buf, "+author:%s", buf_term, buf_term);
	    strcat(term, buf);
	    logf(LOG_DEBUG, "This is Author-field search");
	    break;
	  case 7:    /* ISBN */
	    get_term(buf_term, op->u.attributesPlusTerm->term, r);
	    sprintf(buf, "+isbn:%s", buf_term);
	    strcat(term, buf);
	    logf(LOG_DEBUG, "This is ISBN-field search");
	    break;
	  case 21:   /* 件名 (Subject Headings) */
	    get_term(buf_term, op->u.attributesPlusTerm->term, r);
	    sprintf(buf, "+subject:%s", buf_term, buf_term);
	    strcat(term, buf);
	    logf(LOG_DEBUG, "This is SubjectHeadings-field search");
	    break;
	  case 1018: /* 出版者 (Publisher) */
	    get_term(buf_term, op->u.attributesPlusTerm->term, r);
	    sprintf(buf, "+publisher:%s", buf_term, buf_term);
	    strcat(term, buf);
	    logf(LOG_DEBUG, "This is Publisher-field search");
	    break;
	  case 63:  /* 注記 (Note) */
	    get_term(buf_term, op->u.attributesPlusTerm->term, r);
	    sprintf(buf, "+note:%s", buf_term, buf_term);
	    strcat(term, buf);
	    logf(LOG_DEBUG, "This is Note-field search");
	    break;
	  default: /* Non-support */
	    logf(LOG_LOG, "This is Non-Support-field search");
	    r->errcode = 114;
	    sprintf(r->errstring, "%d", *element->value.numeric);
	    break;
	  }
	  break;
	case Z_AttributeValue_complex:
	  logf(LOG_LOG, "This is Complex AttributesValue");
	  r->errcode = 246;
	  break;
	default:
	  r->errcode = 108;
	  logf(LOG_DEBUG, "Unknown AttributeValue");
	  break;
	}
	break;
      }
      i++;
    }
    break;
  case Z_Operand_resultSetId:
    logf(LOG_FATAL, "ResultSetID Not Support.");
    r->errcode = 18;
    r->errstring = "ResultSetID Not Support.";
    break;
  case Z_Operand_resultAttr:
    logf(LOG_FATAL, "ResultSetPlusAttributes Not Support.");
    r->errcode = 245;
    r->errstring = "ResultSetPlusAttributes Not Support.";
    break;
  default:
    logf(LOG_FATAL, "Unknown Operand");
    r->errcode = 3;
    r->errstring = "Unknown Operand";
    break;
  }
}