コード例 #1
0
ファイル: TreeOPE.cpp プロジェクト: whuang08/TreeScaper
NEWICKNODE *TreeOPE::findleaf(std::string leafname, NEWICKNODE *currentnode, NEWICKNODE *parent, int *icpt)
{
    currentnode->parent = parent;
    NEWICKNODE *resultnode = NULL;
    NEWICKNODE *temp = NULL;

    for(int i = 0; i < currentnode->Nchildren; i++)
    {
        temp = findleaf(leafname, currentnode->child[i], currentnode, icpt);
        if(temp != NULL)
        {
            resultnode = temp;
            if(parent == NULL)
                (*icpt) = i;
        }
    }

    if(currentnode->Nchildren == 0)
        if(0 == strcmp(leafname.c_str(), currentnode->label))
            resultnode = currentnode;

    return resultnode;
};
コード例 #2
0
ファイル: quadtree.c プロジェクト: whyqqqqq/pyquadtree
bool movepoint(QuadTree *qt, 
              float oldx, float oldy, 
              float newx, float newy, 
              void *data)
{
  Leaf *oldleaf = findleaf(qt, oldx, oldy);
  if (oldleaf->size == 0) {
    printf ("QuadTree -- point to move is not in Leaf\n");
    return false;
  }
  

  LeafData *cur  = oldleaf->contents.payload;
  LeafData *prev = NULL;
  while(cur) {
    if((data == cur->data)&&(oldx==cur->x)&&(oldy==cur->y)) {
      cur->x = newx;
      cur->y = newy;
      if(!(pointinside(newx, newy, &oldleaf->extents))) {
        if(prev){
          prev->next = cur->next;
        } else {
          oldleaf->contents.payload = cur->next;
        }
        oldleaf->size -= 1;
        addpointx(qt, qt->head,
                  newx, newy,
                  cur);
        return true;
      }
    }
    prev = cur;
    cur  = cur->next;
  } 
  return false;
}