Beispiel #1
0
Datei: btree.c Projekt: qd-cae/qd
void BT_delete(void *bti, void *data)
{
/*
  Go down the tree looking for this member.  If we find it,
  remove it.
*/
  BTREE *bt = (BTREE *) bti;
  NODE *node = bt->head;
  NODE *stack[STACK_SIZE];
  int comp,top=0;
  while(1) {
    comp = bt->compare(data,node->data);
    if(comp < 0) {
      if(node->left) {
        stack[top++] = node;
        node=node->left;
      } else {
        return;   /* not found */
      }
    } else if(comp > 0) {
      if(node->right) {
        stack[top++] = node;
        node=node->right;
      } else {
        return;   /* not found */
      }
    } else {
/*
  Found it.
*/
      if(node->left) {
        leftreplace(bt,node,stack,&top);
      } else if(node->right) {
        rightreplace(bt,node,stack,&top);
      } else {
        node->right = bt->unused;
        bt->unused = node;
        if(top) {
          if(stack[--top]->left == node) {
            stack[top]->left = NULL;
            stack[top]->balance++;
            if(stack[top]->balance != +1) shortened(stack,top+1);
          } else {
            stack[top]->right = NULL;
            stack[top]->balance--;
            if(stack[top]->balance != -1) shortened(stack,top+1);
          }
        } else {
          bt->head = NULL;
        }
      }
      bt->n--;
      return;
    }
  }
}
bool PowerScaledCoordinate::operator>(const PowerScaledCoordinate& other) const
{
    double ds = this->_vec[3] - other._vec[3];
    if (ds >= 0) {
        double p = pow(k, -ds);
        glm::dvec3 upscaled(other._vec[0] * p, other._vec[1] * p,
                                              other._vec[2] * p);
        glm::dvec3 shortened(_vec[0], _vec[1], _vec[2]);
        return glm::length(shortened) > glm::length(upscaled);
    } else {
        double p = pow(k, ds);
        glm::dvec3 upscaled(_vec[0] * p, _vec[1] * p, _vec[2] * p);
        glm::dvec3 shortened(other._vec[0], other._vec[1], other._vec[2]);
        return glm::length(shortened) > glm::length(upscaled);
    }
}
double PowerScaledCoordinate::dot(const PowerScaledCoordinate& rhs) const
{
    double ds = _vec[3] - rhs._vec[3];
    if (ds >= 0.0) {
        double p = pow(k, -ds);
        glm::dvec3 uPowerScaledCoordinatealed(rhs._vec[0] * p, rhs._vec[1] * p,
                                              rhs._vec[2] * p);
        glm::dvec3 shortened(_vec[0], _vec[1], _vec[2]);
        return glm::dot(uPowerScaledCoordinatealed, shortened);
    } else {
        double p = pow(k, ds);
        glm::dvec3 uPowerScaledCoordinatealed(_vec[0] * p, _vec[1] * p, _vec[2] * p);
        glm::dvec3 shortened(rhs._vec[0], rhs._vec[1], rhs._vec[2]);
        return glm::dot(uPowerScaledCoordinatealed, shortened);
    }
}
Beispiel #4
0
Datei: btree.c Projekt: qd-cae/qd
STATIC void rightreplace(BTREE *bt,NODE *top, NODE **stack, int *stop)
{
/*
  Replace indicated node with the smallest element in it's right subtree
*/
  NODE *node=top->right;
  NODE *parent = top;
  NODE *todel;
  stack[(*stop)++] = top;
  stack[(*stop)++] = node;
  while(node->left) {
    parent = node;
    node = node->left;
    stack[(*stop)++] = node;
  }
  (*stop)--;

  top->data = node->data;

  if(node->right) {
    todel = node->right;
    *node = *node->right;
    todel->right = bt->unused;
    bt->unused = todel;
    if(parent->right == node) {
      parent->balance--;
      if(parent->balance != -1) shortened(stack,*stop);
    } else {
      parent->balance--;
      if(parent->balance != +1) shortened(stack,*stop);
    }

  } else {
    node->right = bt->unused;
    bt->unused = node;
    if(parent->right == node) {
      parent->right = NULL;
      parent->balance--;
      if(parent->balance != -1) shortened(stack,*stop);
    } else {
      parent->left = NULL;
      parent->balance++;
      if(parent->balance != +1) shortened(stack,*stop);
    }
  }
}
double PowerScaledCoordinate::angle(const PowerScaledCoordinate& rhs) const
{
    glm::dvec3 uPowerScaledCoordinatealed(rhs._vec[0], rhs._vec[1], rhs._vec[2]);
    glm::dvec3 shortened(_vec[0], _vec[1], _vec[2]);
    uPowerScaledCoordinatealed = glm::normalize(uPowerScaledCoordinatealed);
    shortened = glm::normalize(shortened);

    return acos(glm::dot(uPowerScaledCoordinatealed, shortened));
}