void
_gwy_grain_value_builtin_inscribed_disc(GwyGrainValue *inscrdrgrainvalue,
                                        GwyGrainValue *inscrdxgrainvalue,
                                        GwyGrainValue *inscrdygrainvalue,
                                        GwyGrainValue *edmeangrainvalue,
                                        const GwyGrainValue *xgrainvalue,
                                        const GwyGrainValue *ygrainvalue,
                                        const guint *grains,
                                        const guint *sizes,
                                        const GwyMaskField *mask,
                                        const GwyField *field)
{
    guint ngrains;
    const gdouble *xvalues, *yvalues;
    gdouble *inscrdrvalues, *inscrdxvalues, *inscrdyvalues, *edmeanvalues;
    if (all_null(4, &ngrains,
                 inscrdrgrainvalue, inscrdxgrainvalue, inscrdygrainvalue,
                 edmeangrainvalue)
        || !check_target(inscrdrgrainvalue, &inscrdrvalues,
                         GWY_GRAIN_VALUE_INSCRIBED_DISC_R)
        || !check_target(inscrdxgrainvalue, &inscrdxvalues,
                         GWY_GRAIN_VALUE_INSCRIBED_DISC_X)
        || !check_target(inscrdygrainvalue, &inscrdyvalues,
                         GWY_GRAIN_VALUE_INSCRIBED_DISC_Y)
        || !check_target(edmeangrainvalue, &edmeanvalues,
                         GWY_GRAIN_VALUE_MEAN_EDGE_DISTANCE)
        || !check_dependence(xgrainvalue, &xvalues, GWY_GRAIN_VALUE_CENTER_X)
        || !check_dependence(ygrainvalue, &yvalues, GWY_GRAIN_VALUE_CENTER_Y))
        return;

    inscribed_discs_and_friends(inscrdrvalues, inscrdxvalues, inscrdyvalues,
                                edmeanvalues,
                                xvalues, yvalues,
                                grains, sizes, ngrains, mask,
                                gwy_field_dx(field), gwy_field_dy(field));

    if (inscrdxvalues) {
        gdouble off = field->xoff;
        for (guint i = 1; i <= ngrains; i++)
            inscrdxvalues[i] += off;
    }
    if (inscrdyvalues) {
        gdouble off = field->yoff;
        for (guint i = 1; i <= ngrains; i++)
            inscrdyvalues[i] += off;
    }
}
예제 #2
0
void
form_dependency_graph (command_stream_t c_stream)
{
  // If there is only one command, the graph is done
  if(c_stream == NULL || c_stream->stream_size == 1)
    return;

  int i, j;
  command_t independent = NULL;
  command_t dependent = NULL;

  // We offset the beginning of our loop by 1 as the first command is always independent
  for(i = 1; i < c_stream->stream_size; i++)
    {
      dependent = c_stream->commands[i];
      for(j = 0; j < i; j++)
        {
          independent = c_stream->commands[j];
          if(check_dependence (independent, dependent))
            add_dependency (dependent, independent);
        }
    }
}
예제 #3
0
bool
check_dependence (command_t indep, command_t dep)
{
  // dep reads from the output of indep
  if(indep->output && dep->input && strcmp (indep->output, dep->input) == 0)
    return true;

  // Both write into the same output
  if(indep->output && dep->output && strcmp (indep->output, dep->output) == 0)
    return true;

  // If both commands are SIMPLE_COMMANs compare all their words and their I/O
  if(indep->type == SIMPLE_COMMAND && dep->type == SIMPLE_COMMAND)
    {
      // Skip the command names
      char **wi = indep->u.word + 1;
      while (*wi)
        {
          // dep is writing into something indep is reading from
          if(dep->output && strcmp (*wi, dep->output) == 0)
            return true;

          char **wd = dep->u.word + 1;
          while (*wd)
            {
              // dep is reading from something that indep is writing to
              if((indep->output && strcmp (indep->output, *wd) == 0))
                return true;
              wd++;
            }
            wi++;
        }
    }
  else if(indep->type == SIMPLE_COMMAND) // dep is not a SIMPLE_COMMAND, compare only words in indep
    {
      char **wi = indep->u.word + 1;
      while (*wi)
        {
          if(dep->output && strcmp (*wi, dep->output) == 0)
            return true;
          wi++;
        }
    }
  else // dep is a SIMPLE_COMMAND, indep is not
    {
      char **wd = dep->u.word + 1;
      while (*wd)
        {
          if(indep->output && strcmp (indep->output, *wd) == 0)
            return true;
          wd++;
        }
    }

  // Traverse the independent command
  switch (indep->type)
    {
      case SEQUENCE_COMMAND:
      case PIPE_COMMAND:
      case OR_COMMAND:
      case AND_COMMAND:
        if(check_dependence (indep->u.command[0], dep) || check_dependence (indep->u.command[1], dep))
          return true;
        break;

      case SUBSHELL_COMMAND:
        if(check_dependence (indep->u.subshell_command, dep))
          return true;
        break;

      case SIMPLE_COMMAND: break;
      default: break;
    }

  // Traverse the dependent command
  switch (dep->type)
    {
      case SEQUENCE_COMMAND:
      case PIPE_COMMAND:
      case OR_COMMAND:
      case AND_COMMAND:
        if(check_dependence (indep, dep->u.command[0]) || check_dependence (indep, dep->u.command[1]))
          return true;
        break;

      case SUBSHELL_COMMAND:
        if(check_dependence (indep, dep->u.subshell_command))
          return true;
        break;

      case SIMPLE_COMMAND: break;
      default: break;
    }

  return false;
}