Example #1
0
static bool
have_two_corresponding_aux (ElementType *old_element,
                            ElementType *new_element,
                            bool unique,
                            bool non_coincident,
                            PadOrPinType* old1_pp_ptr,
                            PadOrPinType* old2_pp_ptr,
                            PadOrPinType* new1_pp_ptr,
                            PadOrPinType* new2_pp_ptr)
{
  PadOrPinType old1_pp = make_pad_or_pin(NULL, NULL);
  PadOrPinType new1_pp = make_pad_or_pin(NULL, NULL);
  bool first_found = false;

  PAD_OR_PIN_LOOP_HYG(old_element, _old);
  {
    if (! unique
        || is_number_unique(old_element,
                            pad_or_pin_number(&pp_old))) {
      CheapPointType old_pt = pad_or_pin_center(&pp_old);
      PAD_OR_PIN_LOOP_HYG(new_element, _new);
      {
        if (pad_or_pin_number_cmp(&pp_old, &pp_new) == 0
            && (! unique
                || is_number_unique(new_element,
                                    pad_or_pin_number(&pp_new)))) {
          CheapPointType new_pt = pad_or_pin_center(&pp_new);
          if (! non_coincident || point_distance2(old_pt, new_pt)) {
            if (! first_found) {
              old1_pp = pp_old;
              new1_pp = pp_new;
              first_found = true;
            } else {
              if (old1_pp_ptr) {
                *old1_pp_ptr = old1_pp;
              }
              if (new1_pp_ptr) {
                *new1_pp_ptr = new1_pp;
              }
              if (old2_pp_ptr) {
                *old2_pp_ptr = pp_old;
              }
              if (new2_pp_ptr) {
                *new2_pp_ptr = pp_new;
              }
              return true;
            }
          }
        }
      }
      END_LOOP;
    }
  }
  END_LOOP;
  return false;
}
Example #2
0
double
find_non_coincident(const ElementPadPinData* ppd, int len,
                    int* index1_ptr, int* index2_ptr)
{
  int index1 = 0;
  const ElementPadPinData* ppd1 = &ppd[index1];
  int i;
  for (i = 1; i < len; i++) {
    double d2 = point_distance2(ppd1->center, ppd[i].center);
    if (d2) {
      *index1_ptr = index1;
      *index2_ptr = i;
      return d2;
    }
  }
  return 0;
}
Example #3
0
/* Isn't guaranteed to find the minimum distances between all
   corresponding pads/pins when pad/pin numbers are shared, but it
   takes a pretty good stab at it. */
static double
calculate_sum_of_distances(ElementPadPinData* ppd_a, int len_a,
                           ElementPadPinData* ppd_b, int len_b)
{
  /* Clear the taken flags */
  int i;
  for (i = 0; i < len_b; i++) {
    ppd_b[i].taken = False;
  }

  double sum_d2 = 0;
  for (i = 0; i < len_a; i++) {
    int block_b_start = 0;
    int block_b_end = 0;
    ElementPadPinData* a = &ppd_a[i];
    if (find_number_block(ppd_b, len_b, &a->pp,
                          &block_b_start, &block_b_end)) {
      Boolean min_set = False;
      double min_d2 = 0;
      int min_index = 0;
      int j;
      for (j = block_b_start; j < block_b_end; j++) {
        ElementPadPinData* b = &ppd_b[j];
        if (! b->taken) {
          double d2 = point_distance2(a->transformed_center,
                                      b->transformed_center);
          if (! min_set || d2 < min_d2) {
            min_set = True;
            min_d2 = d2;
            min_index = j;
          }
        }
      }
      if (min_set) {
        ppd_b[min_index].taken = True;
        sum_d2 += min_d2;
      }
    }
  }
  return sum_d2;
}