RStarTreeNodePtr RStarTreeNode::find_least_enlargement( const BoundingBox &bounding_box) const { float enlargement, min_enlargement, v; Uint32 i, index; assert(!get_leaf()); assert(get_count() > 0); min_enlargement = std::numeric_limits<float>::max(); index = std::numeric_limits<Uint32>::max(); for (i = 0; i < get_count(); i++) { v = get_element_bounding_box(i).get_volume(); enlargement = enclose(bounding_box, get_element_bounding_box(i)).get_volume() - v; if (enlargement < min_enlargement) { if (enlargement <= 0.0f) { return get_node(i); } min_enlargement = enlargement; index = i; } } return get_node(index); }
/* enclose -- build up a closure */ static void enclose(Format *f, Binding *binding, const char *sep) { if (binding != NULL) { Binding *next = binding->next; enclose(f, next, ";"); fmtprint(f, "%S=%#L%s", binding->name, binding->defn, " ", sep); } }
const IRect Entity::currentScreenRect() const { IRect rect = m_sprite.getRect(m_seq_idx, m_frame_idx, m_dir_idx); if(m_oseq_idx != -1 && m_oframe_idx != -1) rect = enclose(rect, m_sprite.getRect(m_oseq_idx, m_oframe_idx, m_dir_idx)); //TODO: float based results return rect + (int2)worldToScreen(pos()); }
// cling::Value std::string printValue(const Value *value) { cling::smallstream strm; if (value->isValid()) { clang::ASTContext &C = value->getASTContext(); clang::QualType QT = value->getType(); strm << "boxes ["; strm << enclose(QT, C, "(", ") ", 3); if (!QT->isVoidType()) { strm << printUnpackedClingValue(*value); } strm << "]"; } else strm << "<<<invalid>>> " << printAddress(value, '@'); return strm.str(); }
RStarTreeNodePtr RStarTreeNode::find_least_overlap( const BoundingBox &bounding_box) const { BoundingBox tmp_bounding_box; float overlap, min_overlap; Uint32 i, j, index; assert(!get_leaf()); assert(get_count() > 0); min_overlap = std::numeric_limits<float>::max(); index = std::numeric_limits<Uint32>::max(); for (i = 0; i < get_count(); i++) { tmp_bounding_box = enclose(bounding_box, get_element_bounding_box(i)); overlap = 0.0f; for (j = 0; j < get_count(); j++) { if (i != j) { overlap += tmp_bounding_box.overlap( get_element_bounding_box(j)); } } if (overlap < min_overlap) { if (overlap <= 0.0f) { return get_node(i); } min_overlap = overlap; index = i; } } assert(index < get_count()); return get_node(index); }
void BBox::enclose(const BBox& bbox) { enclose(bbox.vMin); enclose(bbox.vMax); }
trieNode parentLZTrie (lztrie T, trieNode i) { if (i == ROOT) return NULLT; // parent of root if (T->boost[T->letters[i-rank(T->pdata->bdata,i)]] == i) return ROOT; return enclose (T->pdata,i); }
int main(void) { int i=0,j=0,k=0,l=0,b[7][2],n=0,min=10000,a[8][2],area[1000][2],m=0,solution=0; struct node *root,*temp=NULL,*old=NULL; FILE *fr=fopen("packrec.in","r"),*fw=fopen("packrec.out","w"); for(i=0;i<=3;i++) /* creates an empty linked list with 4 nodes */ { temp=getnode(); if(i==0) { root=temp; } else { old->link=temp; } old=temp; } temp->link=NULL; i=0; while(fscanf(fr,"%d %d",&a[i][0],&a[i][1])!=EOF) { //fprintf(fw,"\nsanity check1:a[0][0]=%d %d\n",a[0][0],a[0][1]); a[i+1][0]=a[i][1]; a[i+1][1]=a[i][0]; //fprintf(fw,"i=%d l1=%d b1=%d\nl2=%d b2=%d\n",i,a[i][0],a[i][1],a[i+1][0],a[i+1][1]); i+=2; } //fprintf(fw,"\nsanity check2:a[0][0]=%d %d\n",a[0][0],a[0][1]); for(i=0;i<8;i++) { for(j=0;j<8;j++) { BAN(i,j) for(k=0;k<8;k++) { BAN(i,k) BAN(j,k) for(l=0;l<8;l++) { // fprintf(fw,"\nhere before ban\n"); BAN(i,l) BAN(j,l) BAN(k,l) //fprintf(fw,"\ni=%d,j=%d,k=%d,l=%d\n",i,j,k,l); place(fw,a,i,j,k,l,root); //fprintf(fw,"\nplace complete"); //fprintf(fw,"\nafter place i=%d,j=%d,k=%d,l=%d\n",i,j,k,l); n=enclose(fw,root,b); //fprintf(fw,"\nenclose complete n=%d\n",n); //fprintf(fw,"\nnew i=%d,j=%d,k=%d,l=%d\n",i,j,k,l); if(b[0][0]<min) { memset(area,0,2000*sizeof(area[0][0])); min=b[0][0];//min gives least area found m=1; solution=n;//no. of combos found while(m<=n) { area[m-1][0]=b[m][0]; area[m-1][1]=b[m][1]; //fprintf(fw,"\narea takes in %d %d %d %d\n",area[m-1][0],area[m-1][1],b[m][0],b[m][1]); m+=1; } } else if(b[0][0]==min) { m=1; while(m<=n) { area[solution+m-1][0]=b[m][0]; area[solution+m-1][1]=b[m][1]; //fprintf(fw,"\narea takes in%d %d %d %d\n",area[solution+m-1][0],area[solution+m-1][1],b[m][0],b[m][1]); m+=1; } solution+=n; } } //fprintf(fw,"\nexits l\n"); } //fprintf(fw,"\nexits k\n"); } //fprintf(fw,"\nexits j"); } //fprintf(fw,"\nexits i\n"); l=0; //fprintf(fw,"final min=%d,no. of sol.=%d\n",min,solution); fprintf(fw,"%d\n",min); for(i=0;i<solution;i++) { if(area[i][0]==0) { continue; } if(area[i][0]>area[i][1]) { l=area[i][0]; area[i][0]=area[i][1]; area[i][1]=l; } for(j=i+1;j<solution;j++) { if((area[j][0]==area[i][0])||(area[j][1]==area[i][0])) { area[j][0]=0; area[j][1]=0; } if(area[j][0]>area[j][1]) { l=area[j][0]; area[j][0]=area[j][1]; area[j][1]=l; } } } /*Sorts the solution*/ for(i=0;i<=solution;i++) { for(j=i+1;j<=solution;j++) { if(area[j][0]<area[i][0]) { l=area[j][0]; area[j][0]=area[i][0]; area[i][0]=l; l=area[j][1]; area[j][1]=area[i][1]; area[i][1]=l; } } } m=0; while(m<=solution) { if(area[m][0]!=0) fprintf(fw,"%d %d\n",area[m][0],area[m][1]); m+=1; } return 0; }
// Does bigger Box encloses smaller Box completely? bool Box::enclose (const Box &bigger,const Box &smaller) { if (enclose(bigger,smaller.low) && enclose(bigger,smaller.high)) return true; return false; }