Exemple #1
0
int main() {
	freopen("H.in", "r", stdin);
	while (scanf("%d", &n) == 1) {
		if (n == 0) break;
		data.clear();
		for (int i = 1; i <= n; i++) {
			Geometry_3D::TPoint now;
			now.read();
			data.push_back(now);
		}
		convex = Geometry_3D::Convex_Hull::getConvex(data);
		std::pair<long double, long double> answer = std::make_pair(0, INF);
		for (int i = 0; i < (int)convex.size(); i++) {
			long double maxdist = 0;
			for (int j = 0; j < (int)data.size(); j++) {
				maxdist = std::max(maxdist, getDist(data[j], convex[i]));
			}
			if (dcmp(answer.first - maxdist) == 0) {
				answer.second = std::min(answer.second, getArea(data, convex[i]));
			}
			else if (dcmp(answer.first - maxdist) < 0) {
				answer.first = maxdist;
				answer.second = getArea(data, convex[i]);
			}
		}
		std::pair<double, double> out = std::make_pair(answer.first, answer.second);
		printf("%.3f %.3f\n", out.first, out.second);
	}
	return 0;
}
	void ScissorGLESv2::apply() 
	{
		if(get_scissor_stack().empty()) {
			glEnable(GL_SCISSOR_TEST);
		}
		glScissor(getArea().x(), getArea().y(), getArea().w(), getArea().h());
		get_scissor_stack().emplace(getArea());
	}
Exemple #3
0
/**
 * Get the current Physics engine instance.
 */
Physics* RigidBody::getPhysics() {
	Area* area = getArea();
	Physics* physics = NULL;
	if(area) {
		physics = getArea()->getPhysics();
	}
	return physics;
}
Exemple #4
0
// returns the corners of the door
vector<Coord> DoorObject::getCorners(bool recompute)
{
  if(!recompute && _corners_cached) return _corners;
  
  // assert: we need to recompute before returning

  vector<Coord> ret;

  // new procedure -- create a graph of all the intersections and the paths between them... will form graph of quads and triangles  (using corner_node_t object)
  pair<corner_node_t*,size_t> tree = corner_node_t::buildTree(_segments);  
  

  vector<corner_node_t*> corners_ptrs;

  // choose points as corners if they have a path back to themselves of length 4 (points on triangles only will not have this path)
  for(size_t i = 0; i < tree.second; i++)
    {
      if(tree.first[i].hasCycleOfFour()) {
	tree.first[i].corner = true;
	corners_ptrs.push_back(&tree.first[i]);
	ret.push_back(tree.first[i].point);
      }
    }
  
  // figure out a circular ordering of four corners
  sort(ret.begin(), ret.end());

  if(ret.size() < 4) // guard for four points
    {
      if(tree.first) delete [] tree.first;
      return ret;
    }
  // make all possible polgons.  Return one with most area
  CPoly buffer;
  
  for(size_t i = 0; i < ret.size(); i++)
    for(size_t j = i; j < ret.size(); j++)
      for(size_t k = j; k < ret.size(); k++)
	for(size_t l = k; l < ret.size(); l++) {
	  CPoly C;
	  C.bdy.push_back(ret[i]);
	  C.bdy.push_back(ret[j]);
	  C.bdy.push_back(ret[k]);
	  C.bdy.push_back(ret[l]);
	  if(getArea(C) > getArea(buffer)) 
	    buffer = C;
	}
  ret = buffer.bdy;
  

  // release the tree of corner_node_t
  if(tree.first) delete [] tree.first;
  
  // cache and return
  _corners = ret;
  _corners_cached = true;
  return ret; 
}
Exemple #5
0
double getArea(int n, Point *p, const Point &c, const double r)  {
	double ret = 0.0;
	for (int i = 0; i < n; i++) {
		int sgn = dcmp(det(p[i] - c, p[(i + 1) % n] - c));
		if (sgn > 0) ret += getArea(p[i] - c, p[(i + 1) % n] - c, r);
		else ret -= getArea(p[(i + 1) % n] - c, p[i] - c, r);
	}
	return fabs(ret);
}
Exemple #6
0
//---------------------------------------------------------------------------
float TEstimation::getCommonSurfaceRetainedPosterior(int p){
	//calculate common surface: norm area
	float areaPrior;
	float areaPosterior;
	float commonSurface=0;
	float posteriorSurface=0;
	areaPrior=getArea(retainedMatrix.column(p), theta)*(mySimData->paramMaxima[p-1]-mySimData->paramMinima[p-1]);
	areaPosterior=getArea(posteriorMatrix.column(p), theta)*(mySimData->paramMaxima[p-1]-mySimData->paramMinima[p-1]);
	for(int k=1;k<=posteriorDensityPoints;++k){
		commonSurface+=min(retainedMatrix(k,p)/areaPrior, posteriorMatrix(k,p)/areaPosterior);
		posteriorSurface+=posteriorMatrix(k,p)/areaPosterior;
	}
	return commonSurface/posteriorSurface;
}
bool BorderArea::contains(int x, int y)
{
    if (getRotation() == DEGREE_270 || getRotation() == DEGREE_90)
    {
        if (getX() <= x && static_cast<signed int>(getX() + getArea().getHeight() - 1) >= x && getY() <= y && static_cast<signed int>(getY() + getArea().getWidth() - 1) >= y)
        return true;
    }
    else
    {
        if (getX() <= x && static_cast<signed int>(getX() + getArea().getWidth() - 1) >= x && getY() <= y && static_cast<signed int>(getY() + getArea().getHeight() - 1) >= y)
        return true;
    }
    return false;
}
Exemple #8
0
bool ImageKnob::onMouse(int button, bool press, int x, int y)
{
    if (button != 1)
        return false;

    if (press)
    {
        if (! getArea().contains(x, y))
            return false;

        fDragging = true;
        fLastX = x;
        fLastY = y;

        if (fCallback != nullptr)
            fCallback->imageKnobDragStarted(this);

        return true;
    }
    else if (fDragging)
    {
        if (fCallback != nullptr)
            fCallback->imageKnobDragFinished(this);

        fDragging = false;
        return true;
    }

    return false;
}
bool ResponsibilityArea::detectMotion(cv::Mat const & motionFrame, int const MAX_DEVIATION, int const COVER_RATIO)
{
	cv::Mat submotionFrame(motionFrame, cv::Rect(xStart_, yStart_, width_, height_));
	cv::Scalar mean, stddev;
	cv::meanStdDev(submotionFrame, mean, stddev);

	if (stddev[0] > MAX_DEVIATION) {
		return false;
	}

	int number_of_changes = 0;

	//loop over part of image and detect changes
	for (int j = 0; j < height_; ++j) {
		for (int i = 0; i < width_; ++i) {
			if (static_cast<int>(submotionFrame.at<uchar>(j, i)) == 255) {
				++number_of_changes;
			}
		}
	}

    if (number_of_changes > (int)(COVER_RATIO * getArea() / 1000)) {
		//std::cout << number_of_changes << std::endl;
		return true;
	}

	return false;

}
Exemple #10
0
//----------------------------------------------------------------------------//
void Element::onNonClientChanged(ElementEventArgs& e)
{
    // TODO: Be less wasteful with this update
    setArea(getArea());

    fireEvent(EventNonClientChanged, e, EventNamespace);
}
Exemple #11
0
	const Rect& RenderBackend::getClipArea() const {
		if (m_clipstack.empty()) {
			return m_clipstack.top().r;
		} else {
			return getArea();
		}
	}
Exemple #12
0
void TRoomDB::buildAreas()
{
    QTime _time; _time.start();
    QMapIterator<int, TRoom *> it( rooms );
    while( it.hasNext() )
    {
       it.next();
       int id = it.key();
       TRoom * pR = getRoom(id);
       if( !pR ) continue;
       TArea * pA = getArea(pR->getArea());
       if( !pA )
       {
           areas[pR->getArea()] = new TArea( mpMap, this );
       }
    }

    // if the area has been created without any rooms add the area ID
    QMapIterator<int, QString> it2( areaNamesMap );
    while( it2.hasNext() )
    {
       it2.next();
       int id = it2.key();
       if( ! areas.contains( id ) )
       {
           areas[id] = new TArea( mpMap, this );
       }
    }
    qDebug()<<"BUILD AREAS run time:"<<_time.elapsed();
}
	Renderer(){
		mesh = 0;
		auto modelMesh = static_cast<IndexedMesh*>(Mesh::LoadWavefront<IndexedMesh>(MODELS_DIR "/suzanne.obj"));
		float area = modelMesh->getArea();

		int numPoints = 2000;
		
		K3DTree<glm::vec3> pointCloud;
		glm::vec3 minP = modelMesh->getBoundingAABB().minPos();
		glm::vec3 maxP = modelMesh->getBoundingAABB().maxPos();
		minP.x = std::min(std::min(minP.x,minP.y),minP.z);
		maxP.x = std::max(std::max(maxP.x,maxP.y),maxP.z);
		minP.z = minP.y = minP.x;
		maxP.z = maxP.y = maxP.x;
		auto triangles = modelMesh->getFaces();
		for(auto tri = triangles.begin();tri!=triangles.end();++tri){
			float p = numPoints * (tri->area() / area);
			int points = std::floorf(p + 0.5);
			for(int i = 0;i<points;i++){
				auto p = Random::getRandomGenerator()->inTriangle(*tri);
				p -= minP;
				p /= (maxP-minP);
				surfPoints.push_back(p);
				pointCloud.insert(p,glm::vec3(0,0,0));
			}
		}

		std::vector<glm::vec3> closePoints;
		IT_FOR(pointCloud,point){
			auto nodes = pointCloud.findNNearest(point->getPosition(),10);
			closePoints.clear();
			IT_FOR(nodes,p){
				closePoints.push_back(glm::vec3((*p)->getPosition()[0],(*p)->getPosition()[1],(*p)->getPosition()[2]));
			}
Exemple #14
0
void Rectangle::print() const
{
    std::cout << "Rectangle:   x: " << getX() << std::endl
              << "             y: " << getY() << std::endl
              << "          area: " << getArea() << std::endl
              << "     perimeter: " << getPerimeter() << std::endl;
}
Exemple #15
0
void SpritePolygonPerformanceTestStatic::initIncrementStats()
{
    auto t = experimental::SpritePolygon::create(s_pathGrossini);
    _incVert = (int)t->getVertCount();
    _incTri = (int)t->getTrianglesCount();
    _incPix = (int)t->getArea();
}
Exemple #16
0
 float Center::getAreaWithNeighbours(){
     float accum = 0;
     for(Center* c : neighbours){
         accum += c->getArea();
     }
     return getArea() + accum;
 }
void peanoclaw::statistics::LevelStatisticsPacked::toString (std::ostream& out) const {
   out << "("; 
   out << "area:" << getArea();
   out << ",";
   out << "level:" << getLevel();
   out << ",";
   out << "numberOfPatches:" << getNumberOfPatches();
   out << ",";
   out << "numberOfCells:" << getNumberOfCells();
   out << ",";
   out << "numberOfCellUpdates:" << getNumberOfCellUpdates();
   out << ",";
   out << "createdPatches:" << getCreatedPatches();
   out << ",";
   out << "destroyedPatches:" << getDestroyedPatches();
   out << ",";
   out << "patchesBlockedDueToNeighbors:" << getPatchesBlockedDueToNeighbors();
   out << ",";
   out << "patchesBlockedDueToGlobalTimestep:" << getPatchesBlockedDueToGlobalTimestep();
   out << ",";
   out << "patchesSkippingIteration:" << getPatchesSkippingIteration();
   out << ",";
   out << "patchesCoarsening:" << getPatchesCoarsening();
   out << ",";
   out << "estimatedNumberOfRemainingIterationsToGlobalTimestep:" << getEstimatedNumberOfRemainingIterationsToGlobalTimestep();
   out <<  ")";
}
Exemple #18
0
  WindowGroupControl WindowGroup::windowGroupControl() const
  {
    boost::optional<double> largestArea;
    boost::optional<Point3d> centroid;
    boost::optional<Vector3d> outwardNormal;

    for (const auto & windowPolygon : m_windowPolygons){
      boost::optional<double> area = getArea(windowPolygon);
      if (area){
        if (!largestArea || (*area > *largestArea)){
          boost::optional<Point3d> tmpCentroid = getCentroid(windowPolygon);
          boost::optional<Vector3d> tmpOutwardNormal = getOutwardNormal(windowPolygon);
          if (tmpCentroid && tmpOutwardNormal){
            largestArea = area;
            centroid = tmpCentroid;
            outwardNormal = tmpOutwardNormal;
          }
        }
      }
    }

    WindowGroupControl result;
    result.largestArea = largestArea;
    result.centroid = centroid;
    result.outwardNormal = outwardNormal;

    return result;
  }
void AreaCombat::getList(const Position& centerPos, const Position& targetPos, std::list<Tile*>& list) const
{
	const MatrixArea* area = getArea(centerPos, targetPos);
	if (!area) {
		return;
	}

	uint32_t centerY, centerX;
	area->getCenter(centerY, centerX);

	Position tmpPos(targetPos.x - centerX, targetPos.y - centerY, targetPos.z);
	uint32_t cols = area->getCols();
	for (uint32_t y = 0, rows = area->getRows(); y < rows; ++y) {
		for (uint32_t x = 0; x < cols; ++x) {
			if (area->getValue(y, x) != 0) {
				if (g_game.isSightClear(targetPos, tmpPos, true)) {
					Tile* tile = g_game.getTile(tmpPos);
					if (!tile) {
						tile = new StaticTile(tmpPos.x, tmpPos.y, tmpPos.z);
						g_game.setTile(tile);
					}
					list.push_back(tile);
				}
			}
			tmpPos.x++;
		}
		tmpPos.x -= cols;
		tmpPos.y++;
	}
}
Exemple #20
0
//---------------------------------------------------------------------------
void TEstimation::writeSmoothedSimsUsed(my_string filenameTag){
   //write file with prior
   cout << "   - write file with prior densities ...";
   ofstream output;
   my_string filename=outputPrefix + "TruncatedPrior";
   filename+= filenameTag;
   filename+=".txt";
   output.open(filename.c_str());
   //write Header
   output << "number";
   for(int p=0; p<mySimData->numParams;++p){
	  output << "\t" << mySimData->paramNames[p] << "\tdensity";
   }
   output << endl;
   //write values for each parameter: norm area!
   ColumnVector area(mySimData->numParams);
   for(int p=1; p<=mySimData->numParams;++p){
	   area(p)=getArea(retainedMatrix.column(p), theta)*(mySimData->paramMaxima[p-1]-mySimData->paramMinima[p-1]);
   }
   for(int k=1;k<=posteriorDensityPoints;++k){
	  output << k;
	  for(int p=1; p<=mySimData->numParams;++p){
		 output << "\t" << theatParameterScale(p, k) << "\t" << retainedMatrix(k,p)/area(p);
	  }
	  output << endl;
   }
   output.close();
   cout << " done!" << endl;
}
Exemple #21
0
void Disk::transform(const Vector3 &translation, const float &scale, const Matrix3x3 &rotation) {
    center = (rotation * (scale * center)) + translation;
    normal = rotation * normal;
    radius = radius * scale;
    radiusSquared = radius * radius;
    area = getArea();
}
Exemple #22
0
double getArea(const SurfaceMesh &mesh)
{
    double area;
    for (auto faceID : mesh.get_level_id<3>())
        area += getArea(mesh, faceID);
    return area;
}
Exemple #23
0
void Radiosity::ComputeFormFactors() {
    assert (formfactors == NULL);
    assert (num_faces > 0);
    formfactors = new double[num_faces*num_faces];

    // =====================================
    // ASSIGNMENT:  COMPUTE THE FORM FACTORS
    // =====================================
    for (int i = 0; i < num_faces; ++i) {
        for (int j = i; j < num_faces; ++j) {
            if (i == j) {
                formfactors[i * num_faces + j] = 0;
                continue;
            }
            
            Face *f1 = mesh->getFace(i);
            Face *f2 = mesh->getFace(j);
            
            double formfactor = 0.0;
            
            Vec3f p1 = f1->computeCentroid();
            Vec3f p2 = f2->computeCentroid();
            // Get the vec for p1-->p2
            Vec3f line_p1p2 = p2 - p1;
            double R2 = line_p1p2.Length() * line_p1p2.Length();
            Vec3f p1Normal = f1->computeNormal();
            line_p1p2.Normalize();
            double cos_p1 = p1Normal.Dot3(line_p1p2);
                        
            Vec3f p2Normal = f2->computeNormal();
            double cos_p2 = p2Normal.Dot3(-line_p1p2);
            
            double ff = 0.0;

            if (cos_p1 > EPSILON && cos_p2 > EPSILON) {
                ff = cos_p1 * cos_p2 / (M_PI * R2);
            }
            
            formfactor += ff;
            
            formfactors[i * num_faces + j] = formfactor * getArea(i)/getArea(j);
            formfactors[j * num_faces + i] = formfactor * getArea(j)/getArea(i);
        }
     
        normalizeFormFactors(i);
    }
}
Exemple #24
0
TraceMemoryAllocation const &
TraceMemoryState::getAllocationContaining(uintptr_t const Address,
                                          std::size_t const Length) const
{
  auto AllocPtr = getAllocationAtOrPreceding(Address);
  assert(AllocPtr->getArea().contains(MemoryArea(Address, Length)));
  return *AllocPtr;
}
Exemple #25
0
TraceMemoryAllocation const *
TraceMemoryState::findAllocationContaining(uintptr_t const Address) const
{
  auto AllocPtr = getAllocationAtOrPreceding(Address);
  if (AllocPtr && AllocPtr->getArea().contains(Address))
    return AllocPtr;
  return nullptr;
}
Exemple #26
0
Point::Point(double x, double y){
	this->x = x;
	this->y = y;
	this->area = getArea();
#ifdef _DEBUG_
	cout << "Point Constructor" << endl;
#endif // _DEBUG_
}
Exemple #27
0
double getArea(const SurfaceMesh &mesh, SurfaceMesh::SimplexID<3> faceID)
{
    auto name = mesh.get_name(faceID);
    auto a = *mesh.get_simplex_up({name[0]});
    auto b = *mesh.get_simplex_up({name[1]});
    auto c = *mesh.get_simplex_up({name[2]});
    return getArea(a, b, c);
}
Exemple #28
0
void Box::printDetails()
{

	// Print box details using getters 
	cout << "Box Name = " << getName() << ", (w,h,area): (" 
             << getHeight() << " , " 
	     << getWidth()  << " , "
	     << getArea()   << ")" << endl;
}
Exemple #29
0
//---------------------------------------------------------------------------
float TEstimation::getPosteriorMean(int param){
	//norm area!!
	float areaPosterior=getArea(posteriorMatrix.column(param), theta)*(mySimData->paramMaxima[param-1]-mySimData->paramMinima[param-1]);
	float mean=0;
	for(int k=1;k<=posteriorDensityPoints;++k){
			mean+=posteriorMatrix(k,param)*theatParameterScale(param, k);
	}
	return mean*step/areaPosterior;
}
Exemple #30
0
void Radiosity::findMaxUndistributed() {
  // find the patch with the most undistributed energy 
  // don't forget that the patches may have different sizes!
  max_undistributed_patch = -1;
  total_undistributed = 0;
  total_area = 0;
  float max = -1;
  for (int i = 0; i < num_faces; i++) {
    float m = glm::length(getUndistributed(i)) * getArea(i);
    total_undistributed += m;
    total_area += getArea(i);
    if (max < m) {
      max = m;
      max_undistributed_patch = i;
    }
  }
  assert (max_undistributed_patch >= 0 && max_undistributed_patch < num_faces);
}