Esempio n. 1
0
void gr_text(int x, int y, const char *s, int bold)
{
    GRFont *font = gr_font;
    unsigned off;

    if (!font->texture) return;
    if (gr_current_a == 0) return;

    bold = bold && (font->texture->height != font->cheight);

    x += overscan_offset_x;
    y += overscan_offset_y;

    while((off = *s++)) {
        off -= 32;
        if (outside(x, y) || outside(x+font->cwidth-1, y+font->cheight-1)) break;
        if (off < 96) {

            unsigned char* src_p = font->texture->data + (off * font->cwidth) +
                (bold ? font->cheight * font->texture->row_bytes : 0);
            unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes;

            text_blend(src_p, font->texture->row_bytes,
                       dst_p, gr_draw->row_bytes,
                       font->cwidth, font->cheight);

        }
        x += font->cwidth;
    }
}
Esempio n. 2
0
inline bool collisionWith(LevelObj& obj, f32 px, f32 py)
{
	int x = px.toint();
	int y = py.toint();
	if(outside(obj, 0, 1, x, y)) return false;
	if(outside(obj, 1, 2, x, y)) return false;
	if(outside(obj, 2, 3, x, y)) return false;
	if(outside(obj, 3, 0, x, y)) return false;
	
	return true;
}
Esempio n. 3
0
/* frame will be the frame of the parent window as*/
MessageWin::MessageWin(BRect parentFrame, const char *title,
	window_look look, window_feel feel, uint32 flags, uint32 workspace)
	: BWindow(parentFrame ,title ,look ,feel, flags, workspace)
{
	fBox = new BBox(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER);
	fBox->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	fBox->SetLowColor(fBox->ViewColor());

    // Rects for the text view
    BRect outside(fBox->Bounds());
    outside.InsetBy(10, 10);
	BRect insider(outside);
	insider.OffsetTo(B_ORIGIN);

	fText = new BTextView(outside, "message", insider, B_FOLLOW_NONE, B_WILL_DRAW);
	fText->MakeEditable(false);
	fText->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	fText->SetLowColor(fText->ViewColor());

	fBox->AddChild(fText);
 	AddChild(fBox);
   
 	/* Relocate the window to the center of what its being given */
  	ResizeTo(parentFrame.Width(), floor(parentFrame.Height() / 3));
 	MoveBy(0, floor(parentFrame.Height() / 2 - (parentFrame.Height()/3) / 2 ));

}
Esempio n. 4
0
void RichTextCtrlTestCase::Range()
{
    wxRichTextRange range(0, 10);

    CPPUNIT_ASSERT_EQUAL(0, range.GetStart());
    CPPUNIT_ASSERT_EQUAL(10, range.GetEnd());
    CPPUNIT_ASSERT_EQUAL(11, range.GetLength());
    CPPUNIT_ASSERT(range.Contains(5));

    wxRichTextRange outside(12, 14);

    CPPUNIT_ASSERT(outside.IsOutside(range));

    wxRichTextRange inside(6, 7);

    CPPUNIT_ASSERT(inside.IsWithin(range));

    range.LimitTo(inside);

    CPPUNIT_ASSERT(inside == range);
    CPPUNIT_ASSERT(inside + range == outside);
    CPPUNIT_ASSERT(outside - range == inside);

    range.SetStart(4);
    range.SetEnd(6);

    CPPUNIT_ASSERT_EQUAL(4, range.GetStart());
    CPPUNIT_ASSERT_EQUAL(6, range.GetEnd());
    CPPUNIT_ASSERT_EQUAL(3, range.GetLength());

    inside.SetRange(6, 4);
    inside.Swap();

    CPPUNIT_ASSERT(inside == range);
}
Esempio n. 5
0
void
test1 (short n)
{
  short i;

  for (i = 0; i < n; i++)
    outside (i);
}
 TaskResult MouseDown(const PosInfo& info) override{
   assert(m_textObject != nullptr);
   if (right_click(info) || outside(m_textObject, info)){
     return Commit(info.layerType);
   }
   m_newTask.Set(select_text_task(m_textObject, m_newTextObject, info.pos));
   return TaskResult::PUSH;
 }
Esempio n. 7
0
 Box Box::intersection(const Box& box) const
 {
     Box result;
     if (outside(box))
         return result;
     result.p0 = Point(std::max(p0.x, box.p0.x), std::max(p0.y, box.p0.y));
     result.p1 = Point(std::min(p1.x, box.p1.x), std::min(p1.y, box.p1.y));
     return result;
 }
Esempio n. 8
0
void leaf::findneighbours() {
	if(!outside(i-1,j))
		if(!up().visited)
			neighbours.push_back(up());

	if(!outside(i+1,j))
		if(!down().visited)
			neighbours.push_back(down());

	if(!outside(i,j-1))
		if(!left().visited)
			neighbours.push_back(left());

	if(!outside(i,j+1))
		if(!right().visited)
			neighbours.push_back(right());


}
Esempio n. 9
0
void gr_texticon(int x, int y, GRSurface* icon) {
    if (icon == NULL) return;

    if (icon->pixel_bytes != 1) {
        printf("gr_texticon: source has wrong format\n");
        return;
    }

    x += overscan_offset_x;
    y += overscan_offset_y;

    if (outside(x, y) || outside(x+icon->width-1, y+icon->height-1)) return;

    unsigned char* src_p = icon->data;
    unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes;

    text_blend(src_p, icon->row_bytes,
               dst_p, gr_draw->row_bytes,
               icon->width, icon->height);
}
void MovingPlane::bounceParticle(Particle& particle, double timeElapsed) const {
   if (timeElapsed > lifetime) return;
   double currentOffset = offset + timeElapsed*velocity;

   if(outside(particle)){
      Eigen::Vector3d tangential = 
         particle.restPosition - (particle.restPosition.dot(normal))*normal;

      particle.position = tangential + currentOffset*normal;
   }
}
Esempio n. 11
0
int
composite_box_rep::find_child (SI x, SI y, SI delta, bool force) {
  if (outside (x, delta, x1, x2) && (is_accessible (ip) || force)) return -1;
  int i, n= subnr(), d= MAX_SI, m= -1;
  for (i=0; i<n; i++)
    if (distance (i, x, y, delta)< d)
      if (bs[i]->accessible () || force) {
	d= distance (i, x, y, delta);
	m= i;
      }
  return m;
}
Esempio n. 12
0
void gr_fill(int x1, int y1, int x2, int y2)
{
    x1 += overscan_offset_x;
    y1 += overscan_offset_y;

    x2 += overscan_offset_x;
    y2 += overscan_offset_y;

    if (outside(x1, y1) || outside(x2-1, y2-1)) return;

    unsigned char* p = gr_draw->data + y1 * gr_draw->row_bytes + x1 * gr_draw->pixel_bytes;
    if (gr_current_a == 255) {
        int x, y;
        for (y = y1; y < y2; ++y) {
            unsigned char* px = p;
            for (x = x1; x < x2; ++x) {
                *px++ = gr_current_r;
                *px++ = gr_current_g;
                *px++ = gr_current_b;
                px++;
            }
            p += gr_draw->row_bytes;
        }
    } else if (gr_current_a > 0) {
        int x, y;
        for (y = y1; y < y2; ++y) {
            unsigned char* px = p;
            for (x = x1; x < x2; ++x) {
                *px = (*px * (255-gr_current_a) + gr_current_r * gr_current_a) / 255;
                ++px;
                *px = (*px * (255-gr_current_a) + gr_current_g * gr_current_a) / 255;
                ++px;
                *px = (*px * (255-gr_current_a) + gr_current_b * gr_current_a) / 255;
                ++px;
                ++px;
            }
            p += gr_draw->row_bytes;
        }
    }
}
Esempio n. 13
0
void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) {
    if (source == NULL) return;

    if (gr_draw->pixel_bytes != source->pixel_bytes) {
        printf("gr_blit: source has wrong format\n");
        return;
    }

    dx += overscan_offset_x;
    dy += overscan_offset_y;

    if (outside(dx, dy) || outside(dx+w-1, dy+h-1)) return;

    unsigned char* src_p = source->data + sy*source->row_bytes + sx*source->pixel_bytes;
    unsigned char* dst_p = gr_draw->data + dy*gr_draw->row_bytes + dx*gr_draw->pixel_bytes;

    int i;
    for (i = 0; i < h; ++i) {
        memcpy(dst_p, src_p, w * source->pixel_bytes);
        src_p += source->row_bytes;
        dst_p += gr_draw->row_bytes;
    }
}
int
main()
{
   IloEnv env;
   try {
      IloModel model(env);
    
      setData(env);
      IloNumVarArray  inside(env, nbProds);
      IloNumVarArray outside(env, nbProds);
   
      IloObjective obj = IloAdd(model, IloMinimize(env));
    
      // Must meet demand for each product
    
      for(IloInt p = 0; p < nbProds; p++) {
         IloRange demRange = IloAdd(model,
                                    IloRange (env, demand[p], demand[p]));
         inside[p]  = IloNumVar(obj(insideCost[p])  + demRange(1));
         outside[p] = IloNumVar(obj(outsideCost[p]) + demRange(1));
      }
    
      // Must respect capacity constraint for each resource
    
      for(IloInt r = 0; r < nbResources; r++)
         model.add(IloScalProd(consumption[r], inside) <= capacity[r]);
    
      IloCplex cplex(env);
      cplex.extract(model);
    
      cplex.solve();
    
      if (cplex.getStatus() != IloAlgorithm::Optimal)
         cout << "No optimal solution" << endl;
    
      cout << "Solution status: " << cplex.getStatus() << endl;
      displayResults(cplex, inside, outside);
      cout << "----------------------------------------" << endl;
   }
   catch (IloException& ex) {
      cerr << "Error: " << ex << endl;
   }
   catch (...) {
      cerr << "Error" << endl;
   }
   env.end();
   return 0;
}
bool MovingPlane::backsideReflectBounceParticle(Particle& particle, double timeElapsed, double epsilon) const {
   if (timeElapsed > lifetime) return false;
   //JAL believes this needs to be debug, it causes weird offsetting
  if (outside(particle)) return false;
   double w = (offset + timeElapsed*velocity);

   if (particle.position.dot(normal) > w) {
      particle.position += (epsilon + w - particle.position.dot(normal))*normal;

      //zero velocity in the normalal direction
      particle.velocity -= particle.velocity.dot(normal)*normal;
      particle.velocity *= 0.4; //friction
	  return true;
   }
   return false;
}
Esempio n. 16
0
//Helper function for rasterize without rotation
void HalfEllipsoid::do_rotation(  
	location_3d<int> loc, location_3d<int> cen, float angle, 
	std::vector<Geovalue> &gbRaster, GsTLGridProperty *propTi
) {
	location_3d<int> loc_new = rotate_loc( loc, cen, angle );
	if ( cursor_->check_triplet( loc_new[0], loc_new[1], loc_new[2] ) ) {
		euclidean_vector_3d<int> res = loc_new-cen;
		//Check if point is outside the ellipse
		if ( !outside( res ) ) {
			if ( cursor_->check_triplet( loc[0], loc[1], loc[2] ) ) {
				int cur_node_id = cursor_->node_id( loc[0], loc[1], loc[2] );
				gbRaster.push_back( Geovalue( grid_, propTi, cur_node_id ) );
			}
		}
	}
}
Esempio n. 17
0
// Test loading of volume
TEST(MAIN, RangeBasic){
  Range one(V3f(0,0,0), V3f(1,1,1)); //start
  Range inside(V3f(0.1,0.1,0.1), V3f(0.9,0.9,0.9)); 
  Range intersecting(V3f(0.1,0.1,0.1), V3f(0.9,5,0.9)); 
  Range outside(V3f(1.1,-2,3), V3f(1.2,-1,3.8)); 

  EXPECT_TRUE(ContainsPoint(one, V3f(0.5, 0.5, 0.5)));  // Some common cases
  EXPECT_FALSE(ContainsPoint(one, V3f(1.1, 0.5, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(-0.1, 0.5, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 1.1, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, -0.1, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 0.5, 1.1)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 0.5, -0.1)));
  EXPECT_TRUE(ContainsRange(one, inside));
  EXPECT_TRUE(IntersectsRange(one, intersecting));
  EXPECT_FALSE(ContainsRange(one, intersecting));
  EXPECT_FALSE(ContainsRange(one, outside));
};
Esempio n. 18
0
        void findOverlapRowsAndColumns(const Grid& grid, std::vector<std::pair<int,std::vector<int>>>& overlapRowAndColumns )
        {
            //only relevant in parallel case.
            if ( grid.comm().size() > 1) 
            {
                //Numbering of cells
                auto lid = grid.localIdSet();

                const auto& gridView = grid.leafGridView();
                auto elemIt = gridView.template begin<0>();
                const auto& elemEndIt = gridView.template end<0>();

                //loop over cells in mesh
                for (; elemIt != elemEndIt; ++elemIt) 
                {		
                    const auto& elem = *elemIt;

                    //If cell has partition type not equal to interior save row
                    if (elem.partitionType() != Dune::InteriorEntity)
                    {		    
                        //local id of overlap cell
                        int lcell = lid.id(elem);

                        std::vector<int> columns;
                        //loop over faces of cell
                        auto isend = gridView.iend(elem);
                        for (auto is = gridView.ibegin(elem); is!=isend; ++is) 
                        {
                            //check if face has neighbor
                            if (is->neighbor())
                            {
                                //get index of neighbor cell
                                int ncell = lid.id(is->outside());			    
                                columns.push_back(ncell);
                            }		
                        }
                        //add row to list
                        overlapRowAndColumns.push_back(std::pair<int,std::vector<int>>(lcell,columns));	
                    }    
                }	      
            }
        }				       
Esempio n. 19
0
//Helper function for rasterize with built-in rotation
void HalfEllipsoid::do_rotation( location_3d<int> loc, location_3d<int> cen,
	float angle, std::vector<Geovalue> &gbRaster, GsTLGridProperty *propTi,
	std::vector<float> &facies_props, int &total_nodes )
{
	location_3d<int> loc_new = rotate_loc( loc, cen, angle );
	if ( cursor_->check_triplet( loc_new[0], loc_new[1], loc_new[2] ) ) {
		euclidean_vector_3d<int> res = loc_new-cen;
		//Check if point is outside the ellipse
		if ( !outside( res ) ) {
			if ( cursor_->check_triplet( loc[0], loc[1], loc[2] ) ) {
				int cur_node_id = cursor_->node_id( loc[0], loc[1], loc[2] );
				gbRaster.push_back( Geovalue( grid_, propTi, cur_node_id ) );
				//Update proportion of the different facies in the rotated raster
				int cur_index = propTi->get_value( cur_node_id );
				gstl_assert( ( cur_index >= 0 ) && ( cur_index < facies_props.size() ) );
				facies_props[ cur_index ]++;
				total_nodes++;
			}
		}
	}
}
Esempio n. 20
0
int
EBRestart::makeGeometry(EBIndexSpace&                a_ebIndexSpace,
                        const EBRestart::GeomParams& a_geomParams)
{
  int eekflag = 0;
  SphereIF outside(a_geomParams.radius, a_geomParams.center, false);

  RealVect vectDx = RealVect::Unit;
  vectDx *= a_geomParams.dx;

  GeometryShop workshop(outside,0,vectDx);

  workshop.m_phase = 0;

  ProblemDomain pdomain( a_geomParams.domain );
  a_ebIndexSpace.define(pdomain,
                        a_geomParams.origin,
                        a_geomParams.dx,
                        workshop);

  return eekflag;
}
Esempio n. 21
0
void bordwalk(const struct Cell_head *from_hd, struct Cell_head *to_hd,
	      const struct pj_info *from_pj, const struct pj_info *to_pj)
{
    struct Cell_head cur_hd;

    /* Set some (un)reasonable defaults before we walk the borders */

    invert(&cur_hd, to_hd, 1.0e-6);

    /* Start walking */

    bordwalk1(from_pj, to_pj, from_hd, &cur_hd);

    intersect(&cur_hd, to_hd);

    /* check some special cases by reversing the projection */

    reverse_check(from_pj, to_pj, from_hd, to_hd, &cur_hd);

    debug("Extra check", &cur_hd);

    /* if we still have some unresonable default minmax left, then abort */

    if (outside(&cur_hd, to_hd))
	G_fatal_error(_("Input raster map is outside current region"));

    intersect(&cur_hd, to_hd);

    /* adjust to edges */

    snap_to_grid(&cur_hd, to_hd);

    intersect(to_hd, &cur_hd);

    debug("Final check", to_hd);
}
void MovingPlane::dragParticle(Particle& particle, double timeElapsed) const {
   if (timeElapsed > lifetime) return;
   if(outside(particle)){
      particle.velocity = velocity*normal;
   }
}
Esempio n. 23
0
Sivia::Sivia(repere& R,struct sivia_struct *my_struct) : R(R) {

    my_struct->areain = 0;
    my_struct->areap = 0;
    my_struct->isinside=0;
    Variable xvar,yvar,zvar,tvar;
    int n = my_struct->nb_beacon;
    double *x=my_struct->x; // vecteur des abcisses des donnees
    double *y=my_struct->y; // vecteur des ordonnees des donnees
    double *z=my_struct->z;
    double *r=new double[n]; // vecteur des rayons
    double xr=my_struct->robot_position[0],yr=my_struct->robot_position[1],zr=my_struct->robot_position[2];

    for (int i=0;i<n;i++) {
//        r[i]= sqrt(pow(xr-x[i],2)+pow(yr-y[i],2)+pow(zr-z[i],2));
        r[i]= sqrt(pow(xr-x[i],2)+pow(yr-y[i],2)+pow(zr-z[i],2));
        if (my_struct->outliers[i]!=0)
            r[i] *= (1+my_struct->outliers[i]*my_struct->erroutlier/100);
    }

    vector<Function*> f;
    double th1[n];
    double th2[n];
    for (int i=0;i<n;i++){
        th1[i] = my_struct->theta_sonar[i];
        th2[i] = th1[i] + 20;
    }

    for(int i=0;i<n;i++) {
//        f.push_back(new Function(xvar,yvar,zvar,sqrt(sqr(xvar-x[i])+sqr(yvar-y[i])+sqr(zvar-z[i]))));
        f.push_back(new Function(xvar,yvar,zvar,sqrt(sqr(xvar-Interval(x[i]-my_struct->beacon_interval*r[i]/100,x[i]+my_struct->beacon_interval*r[i]/100))
                                                +sqr(yvar-Interval(y[i]-my_struct->beacon_interval*r[i]/100,y[i]+my_struct->beacon_interval*r[i]/100))
                                                +sqr(zvar-Interval(z[i]-my_struct->beacon_interval*r[i]/100,z[i]+my_struct->beacon_interval*r[i]/100)))));
    }

    vector<Ctc*> vec_out;
    vector<Ctc*> vec_in;

    for(int i=0;i<n;i++) {
        vec_out.push_back(new CtcIn(*(f[i]),(r[i]+Interval(-1,1)*my_struct->err[i])));
        vec_in.push_back(new CtcNotIn(*(f[i]),(r[i]+Interval(-1,1)*my_struct->err[i])));
    }

    double re=0.5;
    int maxq = my_struct->nb_beacon; //nb of contractors
    int ctcq = maxq - my_struct->q + 1; //nb for q-relaxed function of Ibex
    int ninbox = 0;

    CtcQInter insidetmp(vec_in,ctcq);
    CtcQInter outsidetmp(vec_out,my_struct->q);
    CtcFixPoint inside(insidetmp);
    CtcFixPoint outside(outsidetmp);
    IntervalVector box = my_struct->box.back();
//    IntervalVector box(3);box[0]=box[1]=Interval(-25,25);box[2]=Interval(0,2);
    IntervalVector viinside(3);
    //vin.resize(4);

    LargestFirst lf;
    stack<IntervalVector> s;
    s.push(box);
    my_struct->in_perhaps=0;
    while (!s.empty()) {
        IntervalVector box=s.top();
        s.pop();
        contract_and_draw(inside,box,viinside,1,my_struct,ninbox,Qt::magenta,Qt::red);
        if (box.is_empty()) { continue; }

        contract_and_draw(outside,box,viinside,0,my_struct,ninbox,Qt::darkBlue,Qt::cyan);
        if (box.is_empty()) { continue; }

        if (box.max_diam()<my_struct->epsilon_sivia) {
            //R.DrawBox(box[0].lb(),box[0].ub(),box[1].lb(),box[1].ub(),QPen(Qt::yellow),QBrush(Qt::white));
            my_struct->areap += box[0].diam()*box[1].diam()*box[2].diam();
            my_struct->in_perhaps=1;
        } else {
            pair<IntervalVector,IntervalVector> boxes=lf.bisect(box);
            s.push(boxes.first);
            s.push(boxes.second);
        }
    }

    double tx[ninbox],ty[ninbox],tz[ninbox];

    //cout<<"next"<<ninbox<<endl;
    for(int i=0;i<ninbox;i++){
        IntervalVector cur = (my_struct->vin.back());
        my_struct->vin_prev.push_back(cur);
        //cout<<cur<<endl;
        Interval xcur=cur[0];
        Interval ycur=cur[1];
        Interval zcur=cur[2];
        tx[i]=xcur.mid();
        ty[i]=ycur.mid();
        tz[i]=zcur.mid();
        my_struct->vin.pop_back();
    }


    double xin=0,yin=0,zin=0;
    for(int i=0;i<ninbox;i++){
        xin += tx[i];
        yin += ty[i];
        zin += tz[i];
    }
    xin/=double(ninbox);
    yin/=double(ninbox);
    zin/=double(ninbox);

    my_struct->robot_position_found[0] = xin;
    my_struct->robot_position_found[1] = yin;
    my_struct->robot_position_found[2] = zin;
    for(int i=0;i<n;i++)
        R.DrawEllipse(x[i],y[i],re,QPen(Qt::black),QBrush(Qt::NoBrush));

    my_struct->vin.clear();
    vec_out.clear();
    vec_in.clear();
    f.clear();
}
Esempio n. 24
0
Sivia::Sivia(repere& R,struct sivia_struct *my_struct) : R(R) {

    my_struct->areain = 0;
    my_struct->areap = 0;
    my_struct->isinside=0;
    Variable xvar,yvar,zvar,tvar;
    int n = my_struct->nb_beacon;
    double *x=my_struct->x; // vecteur des abcisses des donnees
    double *y=my_struct->y; // vecteur des ordonnees des donnees
    double *z=my_struct->z;
    double *r=new double[n]; // vecteur des rayons
    //r1=9.0;r2=2.0;r3=6.0;r4=6.0;r5=10.0;
    //random config (original config)
    //y1=x1=14;x2=4;y2=-7;x3=7;y3=10;x4=y4=-10;x5=-4;y5=12;x6=0;y6=0;
    //square config
//    x1=-24;y1=24;x2=-24;y2=-24;x3=24;y3=24;x4=24;y4=-24;x5=y5=0;x6=y6=0;

    //Create a square pattern of beacon with the 5th in the center, after 6 beacons, their position is generated at random
//    if (n>=2){
//        x[0]=-24;y[0]=24;x[1]=-24;y[1]=22;
//    }
//    if (n>=3){
//        x[2]=-24;y[2]=-24;
//    }
//    if (n>=4){
//        x[3]=24;y[3]=24;
//    }
//    if (n>=5){
//        x[4]=24;y[4]=-24;
//    }
//    if (n>=6){
//        x[5]=y[5]=0;
//    }

    double xr=my_struct->robot_position[0],yr=my_struct->robot_position[1],zr=my_struct->robot_position[2];

    for (int i=0;i<n;i++) {
//        r[i]= sqrt(pow(xr-x[i],2)+pow(yr-y[i],2)+pow(zr-z[i],2));
        r[i]= sqrt(pow(xr-x[i],2)+pow(yr-y[i],2));
        if (my_struct->outliers[i]!=0)
            r[i] *= (1+my_struct->outliers[i]*my_struct->erroutlier/100);
    }

    vector<Function*> f;
    vector<Function*> fp;
    vector<Function*> theta_1;
    vector<Function*> theta_2;
    double th1[n];
    double th2[n];
    for (int i=0;i<n;i++){
        th1[i] = my_struct->theta_sonar[i];
        th2[i] = th1[i] + 20;
    }

    for(int i=0;i<n;i++) {
//        f.push_back(new Function(xvar,yvar,zvar,sqrt(sqr(xvar-x[i])+sqr(yvar-y[i])+sqr(zvar-z[i]))));
        f.push_back(new Function(xvar,yvar,sqrt(sqr(xvar-Interval(x[i]-my_struct->beacon_interval*r[i]/100,x[i]+my_struct->beacon_interval*r[i]/100))
                                                +sqr(yvar-Interval(y[i]-my_struct->beacon_interval*r[i]/100,y[i]+my_struct->beacon_interval*r[i]/100)))));
         fp.push_back(new Function(xvar,yvar,tvar,sqrt(sqr(xvar-x[i])+sqr(yvar-y[i]))));
         theta_1.push_back(new Function(xvar,yvar,yvar-y[i]-((r[i]*sin(th1[i])-y[i])/(r[i]*cos(th1[i])-x[i]))*(xvar-x[i])));
         theta_2.push_back(new Function(xvar,yvar,yvar-y[i]-((r[i]*sin(th2[i])-y[i])/(r[i]*cos(th2[i])-x[i]))*(xvar-x[i])));
    }

    vector<Ctc*> vec_out;
    vector<Ctc*> vec_in;
    CtcNotIn* intemp1,*intemp2,*intemp3;
    CtcIn* outtemp1,*outtemp2,*outtemp3;
//    for(int i=0;i<n;i++) {

//        if (cos(th1[i])>0){
//            outtemp1 = (new CtcIn(*(theta_1[i]),Interval(0,100)));
//            intemp1 = (new CtcNotIn(*(theta_1[i]),Interval(0,100)));
//        }
//        else{
//            outtemp1 = (new CtcIn(*(theta_1[i]),Interval(-100,0)));
//            intemp1 = (new CtcNotIn(*(theta_1[i]),Interval(-100,0)));
//        }
//        if (cos(th2[i])>0){
//            outtemp2 = (new CtcIn(*(theta_2[i]),Interval(-100,0)));
//            intemp2 =(new CtcNotIn(*(theta_2[i]),Interval(-100,0)));
//        }
//        else{
//            outtemp2 = (new CtcIn(*(theta_2[i]),Interval(0,100)));
//            intemp2 =(new CtcNotIn(*(theta_2[i]),Interval(0,100)));
//        }
//        outtemp3 = (new CtcIn(*(f[i]),(r[i]+Interval(-1,1)*my_struct->err[i])));
//        intemp3 = (new CtcNotIn(*(f[i]),(r[i]+Interval(-1,1)*my_struct->err[i])));

//        vec_out.push_back(new CtcUnion(*outtemp1,*outtemp2,*outtemp3));
//        vec_in.push_back(new CtcCompo(*intemp1,*intemp2,*intemp3));
//    }
//    free(intemp1);free(intemp2);free(intemp3);free(outtemp1);free(outtemp2);free(outtemp3);
//    cout<<"coucou"<<endl;
    for(int i=0;i<n;i++) {
        vec_out.push_back(new CtcIn(*(f[i]),(r[i]+Interval(-1,1)*my_struct->err[i])));
        vec_in.push_back(new CtcNotIn(*(f[i]),(r[i]+Interval(-1,1)*my_struct->err[i])));
    }

    double re=0.5;
    int maxq = my_struct->nb_beacon; //nb of contractors
    int ctcq = maxq - my_struct->q + 1; //nb for q-relaxed function of Ibex
    int ninbox = 0;

    CtcQInter insidetmp(vec_in,ctcq);
    CtcQInter outsidetmp(vec_out,my_struct->q);
    CtcFixPoint inside(insidetmp);
    CtcFixPoint outside(outsidetmp);
    IntervalVector box1 = my_struct->box.back();
//    IntervalVector box(3);box[0]=box[1]=Interval(-25,25);box[2]=Interval(0,2);
    IntervalVector viinside(3);
    //vin.resize(4);

    LargestFirst lf;
    stack<IntervalVector> s;
    s.push(box1);
    my_struct->in_perhaps=0;
    while (!s.empty()) {
        IntervalVector box=s.top();
        s.pop();
        contract_and_draw(inside,box,viinside,1,my_struct,ninbox,Qt::magenta,Qt::red);
        if (box.is_empty()) { continue; }

        contract_and_draw(outside,box,viinside,0,my_struct,ninbox,Qt::darkBlue,Qt::cyan);
        if (box.is_empty()) { continue; }

        if (box.max_diam()<my_struct->epsilon_sivia) {
            R.DrawBox(box[0].lb(),box[0].ub(),box[1].lb(),box[1].ub(),QPen(Qt::yellow),QBrush(Qt::white));
            my_struct->areap += box[0].diam()*box[1].diam();
            my_struct->in_perhaps=1;
        } else {
            pair<IntervalVector,IntervalVector> boxes=lf.bisect(box);
            s.push(boxes.first);
            s.push(boxes.second);
        }
    }

    double tx[ninbox],ty[ninbox],tz[ninbox];

    //cout<<"next"<<ninbox<<endl;
    for(int i=0;i<ninbox;i++){
        IntervalVector cur = (my_struct->vin.back());
        my_struct->vin_prev.push_back(cur);
        //cout<<cur<<endl;
        Interval xcur=cur[0];
        Interval ycur=cur[1];
        tx[i]=xcur.mid();
        ty[i]=ycur.mid();
        my_struct->vin.pop_back();
    }

    for(int i=0;i<ninbox;i++){
        IntervalVector cur = (my_struct->vper.back());
        my_struct->vin_prev.push_back(cur);
        my_struct->vper.pop_back();
    }

    double xin=0,yin=0,zin=0;
    for(int i=0;i<ninbox;i++){
        xin += tx[i];
        yin += ty[i];
        zin += tz[i];
    }
    xin/=double(ninbox);
    yin/=double(ninbox);
    zin/=double(ninbox);

    my_struct->robot_position_found[0] = xin;
    my_struct->robot_position_found[1] = yin;
    my_struct->robot_position_found[2] = zin;
    for(int i=0;i<n;i++)
        R.DrawEllipse(x[i],y[i],re,QPen(Qt::black),QBrush(Qt::NoBrush));

    my_struct->vin.clear();
    my_struct->vper.clear();
    vec_out.clear();
    vec_in.clear();
    f.clear();
}
Esempio n. 25
0
int makeGeometry(Box& a_domain)
{
  Real dx;
  RealVect origin;
  int eekflag =  0;
  //parse input file
  ParmParse pp;

  Vector<int> n_cell(SpaceDim);
  pp.getarr("n_cell",n_cell,0,SpaceDim);

  CH_assert(n_cell.size() == SpaceDim);
  IntVect lo = IntVect::Zero;
  IntVect hi;
  for (int ivec = 0; ivec < SpaceDim; ivec++)
    {
      if (n_cell[ivec] <= 0)
        {
          pout() << " bogus number of cells input = " << n_cell[ivec];
          return(-1);
        }
      hi[ivec] = n_cell[ivec] - 1;
    }

  a_domain.setSmall(lo);
  a_domain.setBig(hi);

  Vector<Real> prob_lo(SpaceDim, 1.0);
  Real prob_hi;
  pp.getarr("prob_lo",prob_lo,0,SpaceDim);
  pp.get("prob_hi",prob_hi);
  dx = (prob_hi-prob_lo[0])/n_cell[0];
  RealVect dxVect = dx*RealVect::Unit;
  for (int idir = 0; idir < SpaceDim; idir++)
    {
      origin[idir] = prob_lo[idir];
    }
  int verbosity = 0;
  int whichgeom;
  pp.get("which_geom",whichgeom);
  EBIndexSpace* ebisPtr = Chombo_EBIS::instance();

  if (whichgeom == 0)
    {
      //allregular
      pout() << "all regular geometry" << endl;
      AllRegularService regserv;
      ebisPtr->define(a_domain, origin, dx, regserv);
    }
  else if (whichgeom == 1)
    {
      pout() << "ramp geometry" << endl;
      int upDir;
      int indepVar;
      Real startPt;
      Real slope;
      pp.get("up_dir",upDir);
      pp.get("indep_var",indepVar);
      pp.get("start_pt", startPt);
      pp.get("ramp_slope", slope);

      RealVect normal = RealVect::Zero;
      normal[upDir] = 1.0;
      normal[indepVar] = -slope;

      RealVect point = RealVect::Zero;
      point[upDir] = -slope*startPt;

      bool normalInside = true;

      PlaneIF ramp(normal,point,normalInside);

      GeometryShop workshop(ramp,verbosity,dxVect);
      //this generates the new EBIS
      ebisPtr->define(a_domain, origin, dx, workshop);
    }
  else if (whichgeom == 5)
    {
      pout() << "sphere geometry" << endl;
      vector<Real> sphere_center(SpaceDim);
      pp.getarr("sphere_center",sphere_center, 0, SpaceDim);
      RealVect sphereCenter;
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          sphereCenter[idir] = sphere_center[idir];
        }
      Real sphereRadius;
      pp.get("sphere_radius", sphereRadius);

      bool     insideRegular = false;
      SphereIF implicit(sphereRadius,sphereCenter,insideRegular);
      GeometryShop workshop(implicit,verbosity,dxVect);
      //this generates the new EBIS
      ebisPtr->define(a_domain, origin, dx, workshop);
    }
  else if (whichgeom == 13)
    {
      pout() << "rhodonea geometry" << endl;
      vector<Real> tmp(SpaceDim);
      pp.getarr("rhodonea_center", tmp, 0, SpaceDim);
      RealVect rhodoneaCenter;
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          rhodoneaCenter[idir] = tmp[idir];
        }
      Real innerRadius;
      pp.get("inner_radius", innerRadius);

      Real outerRadius;
      pp.get("outer_radius", outerRadius);

      int frequency;
      pp.get("frequency", frequency);

      bool     insideRegular = false;

      RhodoneaIF implicit(innerRadius, outerRadius, frequency,
                          rhodoneaCenter, insideRegular);

      GeometryShop workshop(implicit,verbosity,dxVect);
      //this generates the new EBIS
      ebisPtr->define(a_domain, origin, dx, workshop);
    }
  else if (whichgeom == 18)
    {
      pout() << "Low swirl burner geometry" << endl;
      //        AttachDebugger();

      Box domain;

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          origin[idir] = prob_lo[idir];
        }

      Real outerRadius;
      pp.get("outer_radius",outerRadius);

      Real outerThick;
      pp.get("outer_thick",outerThick);

      Real outerHeight;
      pp.get("outer_height",outerHeight);

      Real outerOffset = ((prob_hi - prob_lo[0]) - outerHeight) / 2.0 + prob_lo[0];

      Real innerRadius;
      pp.get("inner_radius",innerRadius);

      Real innerThick;
      pp.get("inner_thick",innerThick);

      Real innerOffset = 0.0;
      innerOffset += outerOffset;

      Real innerHeight;
      pp.get("inner_height",innerHeight);

      Real plateHeight;
      pp.get("plate_height",plateHeight);
      plateHeight += outerOffset;

      Real plateThick;
      pp.get("plate_thick",plateThick);

      int doHoles;
      pp.get("do_holes",doHoles);

      Real holeRadius;
      pp.get("hole_radius",holeRadius);

      Real holeSpace;
      pp.get("hole_space",holeSpace);

      int vaneNum;
      pp.get("vane_num",vaneNum);

      Real vaneThick;
      pp.get("vane_thick",vaneThick);

      RealVect vaneNorm;

      Vector<Real> vectVaneNorm;
      pp.getarr("vane_norm",vectVaneNorm,0,SpaceDim);

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          vaneNorm[idir] = vectVaneNorm[idir];
        }

      Real vaneOffset;
      pp.get("vane_offset",vaneOffset);

      Real vaneHeight = innerHeight - 2*vaneOffset;

      vaneOffset += outerOffset;

      // Make the outer chamber
      BaseIF* outerChamber = makeChamber(outerRadius,outerThick,
                                         outerOffset,outerHeight);

      // Make the inner chamber
      BaseIF* innerChamber = makeChamber(innerRadius,innerThick,
                                         innerOffset,innerHeight);

      // Make the inner plate with holes
      BaseIF* holyPlate = makePlate(plateHeight,plateThick,innerRadius,
                                    doHoles,holeRadius,holeSpace);

      // Make the vanes
      BaseIF* vanes = makeVanes(vaneNum,vaneThick,vaneNorm,innerRadius,outerRadius,
                                vaneOffset,vaneHeight);

      // Union all the pieces together
      Vector<BaseIF*> pieces;

      pieces.push_back(outerChamber);
      pieces.push_back(innerChamber);
      pieces.push_back(holyPlate);
      pieces.push_back(vanes);

      UnionIF swirl(pieces);
      ComplementIF outside(swirl,true);

      GeometryShop workshop(outside,verbosity,dxVect);

      // This generates the new EBIS
      EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
      ebisPtr->define(a_domain, origin, dx, workshop);

    }
  else
    {
      //bogus which_geom
      pout() << " bogus which_geom input = " << whichgeom;
      eekflag = 33;
    }

  return eekflag;
}
Esempio n. 26
0
void ewol::resource::DistanceFieldFont::generateDistanceField(const egami::ImageMono& _input, egami::Image& _output) {
	std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
	int32_t size = _input.getSize().x() * _input.getSize().y();
	std::vector<short> xdist(size);
	std::vector<short> ydist(size);
	std::vector<double> gx(size);
	std::vector<double> gy(size);
	std::vector<double> data(size);
	std::vector<double> outside(size);
	std::vector<double> inside(size);
	// Convert img into double (data)
	double img_min = 255, img_max = -255;
	for (int32_t yyy = 0; yyy < _input.getSize().y(); ++yyy) {
		for (int32_t xxx = 0; xxx < _input.getSize().x(); ++xxx) {
			int32_t iii = yyy * _input.getSize().x() + xxx;
			double v = _input.get(ivec2(xxx, yyy));
			data[iii] = v;
			if (v > img_max) {
				img_max = v;
			}
			if (v < img_min) {
				img_min = v;
			}
		}
	}
	// Rescale image levels between 0 and 1
	for (int32_t yyy = 0; yyy < _input.getSize().y(); ++yyy) {
		for (int32_t xxx = 0; xxx < _input.getSize().x(); ++xxx) {
			int32_t iii = yyy * _input.getSize().x() + xxx;
			data[iii] = (_input.get(ivec2(xxx, yyy))-img_min)/img_max;
		}
	}
	
	// Compute outside = edtaa3(bitmap); % Transform background (0's)
	computegradient(&data[0], _input.getSize().x(), _input.getSize().y(), &gx[0], &gy[0]);
	edtaa3(&data[0], &gx[0], &gy[0], _input.getSize().x(), _input.getSize().y(), &xdist[0], &ydist[0], &outside[0]);
	for(size_t iii = 0; iii < outside.size(); ++iii) {
		if( outside[iii] < 0 ) {
			outside[iii] = 0.0;
		}
	}
	
	// Compute inside = edtaa3(1-bitmap); % Transform foreground (1's)
	for(size_t iii = 0; iii < gx.size(); ++iii) {
		gx[iii] = 0;
	}
	for(size_t iii = 0; iii < gy.size(); ++iii) {
		gy[iii] = 0;
	}
	for(size_t iii = 0; iii < data.size(); ++iii) {
		data[iii] = 1 - data[iii];
	}
	computegradient( &data[0], _input.getSize().x(), _input.getSize().y(), &gx[0], &gy[0]);
	edtaa3(&data[0], &gx[0], &gy[0], _input.getSize().x(), _input.getSize().y(), &xdist[0], &ydist[0], &inside[0]);
	for(size_t iii = 0; iii < inside.size(); ++iii) {
		if( inside[iii] < 0 ) {
			inside[iii] = 0.0;
		}
	}
	
	_output.resize(_input.getSize(), etk::Color<>(0));
	_output.clear(etk::Color<>(0));
	for (int32_t xxx = 0; xxx < _output.getSize().x(); ++xxx) {
		for (int32_t yyy = 0; yyy < _output.getSize().y(); ++yyy) {
			int32_t iii = yyy * _output.getSize().x() + xxx;
			outside[iii] -= inside[iii];
			outside[iii] = 128+outside[iii]*16;
			if( outside[iii] < 0 ) {
				outside[iii] = 0;
			}
			if( outside[iii] > 255 ) {
				outside[iii] = 255;
			}
			uint8_t val = 255 - (unsigned char) outside[iii];
			// TODO : Remove multiple size of the map ...
			_output.set(ivec2(xxx, yyy), etk::Color<>((int32_t)val,(int32_t)val,(int32_t)val,255));
		}
	}
}
Esempio n. 27
0
/*
  special time limit stuff...
*/
int stimer()
{
    int i, spk;
    static int clock3;

    g.foobar = g.foobar > 0 ? -g.foobar : 0;
    g.combo = g.combo > 0 ? -g.combo : 0;
    if (g.turns > 310 && g.abbnum != 10000 && !g.terse)
        rspeak(273);

    /* Bump all the right clocks for reconning battery life and closing */
    if (g.closed) {
        clock3--;
        if (clock3 == 0) {
            g.prop[PHONE] = 0;
            g.prop[BOOTH] = 0;
            rspeak(284);
        } else if (clock3 < -7) {
            rspeak(254);
            normend();
            return (TRUE);
        }
    }
    if (g.tally == 0 && inside(g.loc) && g.loc != Y2)
        --g.clock;
    if (g.clock == 0) {
        /* Start closing the cave */
        g.prop[GRATE] = 0;
        biton(GRATE, LOCKBT);
        bitoff(GRATE, OPENBT);
        g.prop[FISSURE] = 0;
        g.prop[TDOOR] = 0;
        biton(TDOOR, LOCKBT);
        bitoff(TDOOR, OPENBT);
        g.prop[TDOOR2] = 0;
        biton(TDOOR2, LOCKBT);
        bitoff(TDOOR2, OPENBT);
        for (i = 1; i <= DWARFMAX; ++i) {
            g.dseen[i] = FALSE;
            g.dloc[i] = 0;
        }
        move(TROLL, 0);
        move((TROLL + MAXOBJ), 0);
        move(TROLL2, plac[TROLL]);
        move((TROLL2 + MAXOBJ), fixd[TROLL]);
        juggle(CHASM);
        if (g.prop[BEAR] != 3)
            destroy(BEAR);
        g.prop[CHAIN] = 0;
        g.fixed[CHAIN] = 0;
        g.prop[AXE] = 0;
        g.fixed[AXE] = 0;
        rspeak(129);
        g.clock = -1;
        g.closing = TRUE;
        return (FALSE);
    }
    if (g.clock < 0)
        --g.clock2;
    if (g.clock2 == 0) {
        /* Set up storage room... and close the cave... */
        g.prop[BOTTLE] = put(BOTTLE, 115, 8);
        g.holder[BOTTLE] = WATER;
        g.place[WATER] = -BOTTLE;
        g.hlink[WATER] = 0;
        bitoff(BOTTLE, OPENBT);
        g.prop[PLANT] = put(PLANT, 115, 0);
        g.prop[OYSTER] = put(OYSTER, 115, 0);
        g.prop[LAMP] = put(LAMP, 115, 0);
        g.prop[ROD] = put(ROD, 115, 0);
        g.prop[DWARF] = put(DWARF, 115, 0);
        g.loc = 115;
        g.oldloc = 115;
        g.newloc = 115;
        /* Leave the grate with normal (non-negative property). */
        put(GRATE, 116, 0);
        biton(GRATE, LOCKBT);
        bitoff(GRATE, OPENBT);
        g.prop[SNAKE] = put(SNAKE, 116, 1);
        g.prop[BIRD] = put(BIRD, 116, 1);
        g.prop[CAGE] = put(CAGE, 116, 0);
        g.prop[ROD2] = put(ROD2, 116, 0);
        g.prop[PILLOW] = put(PILLOW, 116, 0);

        g.prop[BOOTH] = put(BOOTH, 116, -3);
        g.fixed[BOOTH] = 115;
        g.prop[PHONE] = put(PHONE, 212, -4);

        g.prop[MIRROR] = put(MIRROR, 115, 0);
        g.fixed[MIRROR] = 116;
        g.prop[BOOK2] = put(BOOK2, 115, 0);

        for (i = 1; i < MAXOBJ; ++i) {
            if (toting(i) && enclosed(i))
                extract(i);
            if (toting(i))
                destroy(i);
        }
        rspeak(132);
        g.closed = TRUE;
        clock3 = 20 + ranz(20);
        newtravel = TRUE;
        return (TRUE);
    }
    if (g.prop[LAMP] == 1)
        --g.limit;
    if (g.limit == 0) {
        --g.limit;
        g.prop[LAMP] = 0;
        if (here(LAMP))
            rspeak(184);
        return (FALSE);
    }
    if (g.limit < 0 && outside(g.loc)) {
        rspeak(185);
        normend();
        return (TRUE);
    }
    if (g.limit <= 40) {
        if (g.lmwarn || !here(LAMP))
            return (FALSE);
        g.lmwarn = TRUE;
        spk = 187;
        if (g.prop[BATTERIES] == 1)
            spk = 323;
        if (g.place[BATTERIES] == 0)
            spk = 183;
        if (g.prop[VEND] == 1)
            spk = 189;
        rspeak(spk);
        return (FALSE);
    }
    return (FALSE);
}
Esempio n. 28
0
/*
  Routine to take 1 turn
*/
void turn()
{
    int i, hint;
    static int waste = 0;

    if (newtravel) {
        /* If closing, then he can't leave except via the main office. */
        if (outside(g.newloc) && g.newloc != 0 && g.closing) {
            rspeak(130);
            g.newloc = g.loc;
            if (!g.panic)
                g.clock2 = 15;
            g.panic = TRUE;
        }
        /* See if a dwarf has seen him and has come from where he wants
           to go. */
        if (g.newloc != g.loc && !forced(g.loc) && g.loc_attrib[g.loc] & NOPIRAT == 0)
            for (i = 1; i < (DWARFMAX - 1); ++i)
                if (g.odloc[i] == g.newloc && g.dseen[i]) {
                    g.newloc = g.loc;
                    rspeak(2);
                    break;
                }

        g.loc = g.newloc;
        dwarves();			/* & special dwarf(pirate who
					   steals)	 */

        /* Check for death */
        if (g.loc == 0) {
            death();
            return;
        }
        /* Check for forced move */
        if (forced(g.loc)) {
            desclg(g.loc);
            ++g.visited[g.loc];
            domove();
            return;
        }
        /* Check for wandering in dark */
        if (g.wzdark && dark() && pct(35)) {
            rspeak(23);
            g.oldloc2 = g.loc;
            death();
            return;
        }
        /* see if he is wasting his batteies out in the open */
        if (outside(g.loc) && g.prop[LAMP]) {
            waste++;
            if (waste > 11) {
                rspeak(324);
                waste = 0;
            }
        } else
            waste = 0;

        /* If wumpus is chasing stooge, see if wumpus gets him */
        if (g.chase) {
            g.chase++;
            g.prop[WUMPUS] = g.chase / 2;
            move(WUMPUS, g.loc);
            if (g.chase >= 10) {
                if (dark())
                    rspeak(270);
                pspeak(WUMPUS, 5);
                death();
                return;
            }
        }
        /* check for radiation poisoning. */
        g.health += (outside(g.loc)) ? 3 : 1;
        if (g.health > 100)
            g.health = 100;
        if (here(RADIUM) && (g.place[RADIUM] != -SHIELD || ajar(SHIELD)))
            g.health -= 7;
        if (g.health < 60) {
            rspeak(391 + (60 - g.health) / 10);
            if (g.health < 0) {
                death();
                return;
            }
        }
        if ((g.oldloc == 188) && (g.loc != 188 && g.loc != 189)
                && (g.prop[BOOTH] == 1)) {
            move(GNOME, 0);
            g.prop[BOOTH] = 0;
        }
        /* Describe his situation */
        describe();
        if (!blind()) {
            ++g.visited[g.loc];
            descitem();
        }
    }					/* end of newtravel start for
					   second entry point */
    /* Check if this location is eligible for any hints.  If been here
       long enough, branch to help section. Ignore "hints" < HNTMIN
       (special stuff, see database notes. */
    for (hint = HNTMIN; hint <= HNTMAX; hint++) {
        if (g.hinted[hint])
            continue;
        if (g.loc_attrib[g.loc] / 256 != hint - 6)
            g.hintlc[hint] = -1;
        g.hintlc[hint]++;
        if (g.hintlc[hint] >= g.hints[hint][1])
            do_hint(hint);
    }

    if (g.closed) {
        if (g.prop[OYSTER] < 0 && toting(OYSTER))
            pspeak(OYSTER, 1);
        for (i = 1; i < MAXOBJ; ++i)
            if (toting(i) && g.prop[i] < 0)
                g.prop[i] = -1 - g.prop[i];
    }
    g.wzdark = dark();
    if (g.knfloc > 0 && g.knfloc != g.loc)
        g.knfloc = 0;
    ++g.turns;
    i = rand();

    if (stimer())			/* as the grains of sand slip
					   by */
        return;

    while (!english())			/* retrieve player instructions	 */
        ;

    vrbx = 1;
    objx = objs[1] ? 1 : 0;
    iobx = iobjs[1] ? 1 : 0;
    verb = VAL(verbs[vrbx]);
    do {
        object = objx ? objs[objx] : 0;
        iobj = iobx ? iobjs[iobx] : 0;
        if (object && (objs[2] || iobjs[2])) {
            pspeak(object, -1);
            printf("      ");
        }
        switch (CLASS(verbs[vrbx])) {
        case MOTION:
            motion = verb;
            domove();
            break;
        case NOUN:
            bug(22);
        case ACTION:
            if (object || iobj)
                trverb();
            else
                itverb();
            break;
        case MISC:
            rspeak(verb);
            if (verb == 51)
                g.hinted[1] = TRUE;
            break;
        default:
            bug(22);
        }
        if (objx) {
            objx++;
            if (objs[objx] == 0)
                objx = 0;
        }
        if ((!objx || !objs[objx]) && iobx) {
            iobx++;
            if (iobjs[iobx] == 0)
                iobx = 0;
            if (iobx && iobjs[1])
                objx = 1;
        }
    } while (objx || iobx);
    return;
}
void UnitTestStkMeshBoundaryAnalysis::test_boundary_analysis()
{
  // This test will only work for np=1
  if (m_num_procs > 1) {
    return;
  }

  // set up grid_mesh
  stk::mesh::fixtures::GridFixture grid_mesh(MPI_COMM_WORLD);

  stk::mesh::BulkData& bulk_data = grid_mesh.bulk_data();
  stk::mesh::MetaData& meta_data = grid_mesh.meta_data();
  stk::mesh::TopologicalMetaData& top_data = grid_mesh.top_data();

  // make shell part
  stk::mesh::Part& shell_part = top_data.declare_part<shards::ShellLine<2> >("shell_part");

  meta_data.commit();

  bulk_data.modification_begin();
  grid_mesh.generate_grid();

  // Add some shells
  const unsigned num_shell_faces = 4;

  // get a count of entities that have already been created
  std::vector<unsigned> count;
  stk::mesh::Selector locally_owned(meta_data.locally_owned_part());
  stk::mesh::count_entities(locally_owned, bulk_data, count);
  const unsigned num_entities = count[top_data.node_rank] +
    count[top_data.element_rank];

  std::vector<stk::mesh::Entity*> shell_faces;
  stk::mesh::PartVector shell_parts;
  shell_parts.push_back(&shell_part);
  for (unsigned i = 1; i <= num_shell_faces; ++i) {
    stk::mesh::Entity& new_shell = bulk_data.declare_entity(top_data.element_rank,
                                                            num_entities + i,
                                                            shell_parts);
    shell_faces.push_back(&new_shell);
  }

  // declare shell relationships
  unsigned node_list[5] = {20, 25, 30, 35, 40};
  for (unsigned i = 0; i < num_shell_faces; ++i) {
    stk::mesh::Entity& shell = *(shell_faces[i]);
    stk::mesh::Entity& node1 =
      *(bulk_data.get_entity(top_data.node_rank, node_list[i]));
    stk::mesh::Entity& node2 =
      *(bulk_data.get_entity(top_data.node_rank, node_list[i+1]));
    bulk_data.declare_relation(shell, node1, 0);
    bulk_data.declare_relation(shell, node2, 1);
  }

  bulk_data.modification_end();

  // create the closure we want to analyze
  std::vector<stk::mesh::Entity*> closure;
  unsigned num_faces_in_closure = 6;
  unsigned ids_of_entities_in_closure[] =
    {6, 7, 10, 11, 14, 15, 23, 24, 25, 28, 29, 30, 33, 34, 35, 38, 39, 40};
  for (unsigned i = 0;
       i < sizeof(ids_of_entities_in_closure)/sizeof(unsigned);
       ++i) {
    stk::mesh::EntityRank rank_of_entity;
    if (i < num_faces_in_closure) {
      rank_of_entity = top_data.element_rank;
    }
    else {
      rank_of_entity = 0;
    }
    stk::mesh::Entity* closure_entity =
      bulk_data.get_entity(rank_of_entity, ids_of_entities_in_closure[i]);
    closure.push_back(closure_entity);
  }
  // sort the closure
  std::sort(closure.begin(), closure.end(), stk::mesh::EntityLess());

  stk::mesh::EntitySideVector boundary;
  stk::mesh::boundary_analysis(bulk_data, closure, top_data.element_rank, boundary);
  STKUNIT_EXPECT_TRUE(!boundary.empty());

  std::vector<std::pair<std::pair<unsigned, unsigned>,
                        std::pair<unsigned, unsigned> > > results;
  std::vector<std::pair<std::pair<unsigned, unsigned>,
                        std::pair<unsigned, unsigned> > > expected_results;

  {
    std::pair<unsigned, unsigned> inside(6, 0);
    std::pair<unsigned, unsigned> outside(5, 2);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(6, 3);
    std::pair<unsigned, unsigned> outside(2, 1);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(7, 2);
    std::pair<unsigned, unsigned> outside(8, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(7, 2);
    std::pair<unsigned, unsigned> outside(43, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(7, 3);
    std::pair<unsigned, unsigned> outside(3, 1);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(10, 0);
    std::pair<unsigned, unsigned> outside(9, 2);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(11, 2);
    std::pair<unsigned, unsigned> outside(12, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(11, 2);
    std::pair<unsigned, unsigned> outside(44, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(14, 0);
    std::pair<unsigned, unsigned> outside(13, 2);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(14, 1);
    std::pair<unsigned, unsigned> outside(0, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(15, 1);
    std::pair<unsigned, unsigned> outside(0, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(15, 2);
    std::pair<unsigned, unsigned> outside(16, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }

  {
    std::pair<unsigned, unsigned> inside(15, 2);
    std::pair<unsigned, unsigned> outside(45, 0);
    expected_results.push_back(
      std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }


  for (stk::mesh::EntitySideVector::iterator itr = boundary.begin(); itr != boundary.end(); ++itr)
  {
    stk::mesh::EntitySide& side = *itr;
    stk::mesh::EntitySideComponent& inside_closure = side.inside;
    stk::mesh::EntityId inside_id = inside_closure.entity != NULL ? inside_closure.entity->identifier() : 0;
    stk::mesh::EntityId inside_side = inside_closure.entity != NULL ? inside_closure.side_ordinal : 0;
    stk::mesh::EntitySideComponent& outside_closure = side.outside;
    stk::mesh::EntityId outside_id = outside_closure.entity != NULL ? outside_closure.entity->identifier() : 0;
    stk::mesh::EntityId outside_side = outside_closure.entity != NULL ? outside_closure.side_ordinal : 0;

    std::pair<unsigned, unsigned> inside(inside_id, inside_side);
    std::pair<unsigned, unsigned> outside(outside_id, outside_side);
    results.push_back(std::pair<std::pair<unsigned, unsigned>, std::pair<unsigned, unsigned> >(inside, outside));
  }
  STKUNIT_EXPECT_TRUE(results == expected_results);
}