当前位置: 首页>>代码示例>>C++>>正文


C++ closest函数代码示例

本文整理汇总了C++中closest函数的典型用法代码示例。如果您正苦于以下问题:C++ closest函数的具体用法?C++ closest怎么用?C++ closest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了closest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: closest

pairs* closest(point* P[],int size)
{
	if(size <= 3)
		return bforce(P, size);

	int lvertical = (int) size/2;
	pairs* CL = closest(P,Y,lvertical);
	pairs* CR = closest(P+lvertical,Y+lvertical,size -lvertical);
	if(CL->dist < CR->dist)
		return CL;
	else
		return CR;
}
开发者ID:aurom,项目名称:VACode,代码行数:13,代码来源:closest.c

示例2: closest

float closest(point *A,long long N,point *u,point *v)
{
	if(N<3)
	{
		return bruteForce(A,N,u,v);
	}

	long long mid=N/2;
	point midPoint = A[mid];
	point a,b,r,s;
	long long i,j;


	double dl = closest(A, mid,&a,&b);
    double dr = closest(A + mid, N-mid,&r,&s);
    double d = min(dl, dr);
    if(dl<dr)
    {
    	u[0].x=a.x;u[0].y=a.y;
    	v[0].x=b.x;v[0].y=b.y;
    }
    else
    {
    	u[0].x=r.x;u[0].y=r.y;
    	v[0].x=s.x;v[0].y=s.y;
    }

    point strip[N];
    j=0;
    for (i = 0; i < N; i++)
        if (abs(A[i].x - midPoint.x) < d)
        {
            strip[j] = A[i];
            j++;
        }

    // return min(d, stripClosest(strip, j, d) );
    double minStrip = stripClosest(strip,j,d,&a,&b);
    if(d<minStrip)
    {
    	return d;
    }
    else
    {
    	u[0].x=a.x;u[0].y=a.y;
    	v[0].x=b.x;v[0].y=b.y;
    	return minStrip;
    }
}
开发者ID:greptruth,项目名称:algo_lab,代码行数:49,代码来源:assn3.c

示例3: closest

void closest(struct node *t,int start,int *distance)
{
	if (!t->left && !t->right)
	{
		if (*distance == -1)
			*distance = start;
		else if (start < *distance)
			*distance = start;
		return;
	}
	if (t->left)
		closest(t->left,start+1,distance);
	if (t->right)
	    closest(t->right,start+1,distance);
}
开发者ID:Yenni-Suresh,项目名称:MissionRnD-C-BinarySearchTree-Worksheet,代码行数:15,代码来源:BSTClosestLeafDistance.cpp

示例4: closest

    void map::precompute(const std::vector<point>& points)
    {
        for (auto& p1 : points)
        {
            auto start = closest(p1);
            std::vector<point const*> goals;
            goals.reserve(points.size());
            // find the closest for each goal
            std::transform(points.begin(), points.end(),
                           std::back_inserter(goals),
                           [&](const point& x) { return closest(x); });

            explore(start, goals);
        }
    }
开发者ID:Jinxit,项目名称:dijkstra,代码行数:15,代码来源:map.cpp

示例5: sphereVsCuboid

 bool sphereVsCuboid (const Vector3& sphere_center,
                      double sphere_radius,
                      const Vector3& cuboid_center,
                      const Vector3& cuboid_size)
 {
     Vector3 minBox = cuboid_center - cuboid_size;
     Vector3 maxBox = cuboid_center + cuboid_size;
     double x, y, z;
     
     if (sphere_center.x <= minBox.x)
         x = minBox.x;
     else if (sphere_center.x >= maxBox.x)
         x = maxBox.x;
     else
         x = sphere_center.x;
     
     if (sphere_center.y <= minBox.y)
         y = minBox.y;
     else if (sphere_center.y >= maxBox.y)
         y = maxBox.y;
     else
         y = sphere_center.y;
     
     if (sphere_center.z <= minBox.z)
         z = minBox.z;
     else if (sphere_center.z >= maxBox.z)
         z = maxBox.z;
     else
         z = sphere_center.z;
     
     Vector3 closest(x, y, z);
     return (closest.isDistanceLessThan(sphere_center, sphere_radius));
 }
开发者ID:streibeb,项目名称:cs409,代码行数:33,代码来源:GeometricCollisions.cpp

示例6: update_position

Array<TV> SurfacePins::closest_points(Array<const TV> X) {
  update_position(X,false);
  Array<TV> closest(particles.size(),uninit);
  for (int i=0;i<particles.size();i++)
    closest[i] = X[particles[i]]-info[i].phi*info[i].normal;
  return closest;
}
开发者ID:mikest,项目名称:geode,代码行数:7,代码来源:SurfacePins.cpp

示例7: main

int main()
{
        int i;
        point a, b;
 
        point pts  = malloc(sizeof(point_t) * NP);
        point* s_x = malloc(sizeof(point) * NP);
        point* s_y = malloc(sizeof(point) * NP);
 
        for(i = 0; i < NP; i++) {
                s_x[i] = pts + i;
                pts[i].x = 100 * (double) rand()/RAND_MAX;
                pts[i].y = 100 * (double) rand()/RAND_MAX;
        }
 
/*      printf("brute force: %g, ", sqrt(brute_force(s_x, NP, &a, &b)));
        printf("between (%f,%f) and (%f,%f)\n", a->x, a->y, b->x, b->y);        */
 
        memcpy(s_y, s_x, sizeof(point) * NP);
        qsort(s_x, NP, sizeof(point), cmp_x);
        qsort(s_y, NP, sizeof(point), cmp_y);
 
        printf("min: %g; ", sqrt(closest(s_x, NP, s_y, NP, &a, &b)));
        printf("point (%f,%f) and (%f,%f)\n", a->x, a->y, b->x, b->y);
 
        /* not freeing the memory, let OS deal with it.  Habit. */
        return 0;
}
开发者ID:sbourque,项目名称:GPU610-ClosestPair,代码行数:28,代码来源:closestPair.c

示例8: main

// Driver program to test above functions
int main()
{
    Point P[] = {{0,0}, {0,1}, {100,45}, {2,3}, {9,9}};
    int n = sizeof(P) / sizeof(P[0]);
    printf("The smallest distance is %f ", closest(P, n));
    return 0;
}
开发者ID:Amitjha1412,项目名称:Coding,代码行数:8,代码来源:closest_pair_of_points.c

示例9: TEST_F

TEST_F(BoxTests, ClosestVertexIsDirectlyToLeftWhenInLeftRegion)
{
	Box b(Point(-6, -9), 5, 7);
	std::auto_ptr<OrderedPair> closest(b.getClosestVertex(Point(-5.5, -10.7)));

	EXPECT_EQ(Point(-6, -10.7), *closest);
}
开发者ID:thomasplain,项目名称:arkanoids,代码行数:7,代码来源:Box_UnitTests.cpp

示例10: main

// Driver program to test above functions
int main()
{
    Point P[] = {{2, 3}, {12, 30}, {40, 50}, {5, 1}, {12, 10}, {3, 4}};
    int n = sizeof(P) / sizeof(P[0]);
    printf("The smallest distance is %f ", closest(P, n));
    return 0;
}
开发者ID:lshi2004,项目名称:Montevideo,代码行数:8,代码来源:closet_pair.cpp

示例11: getFirstTimestepYears

    bool TimeMap::isTimestepInFreqSequence (size_t timestep, size_t start_timestep, size_t frequency, bool years) const {
        bool timestep_right_frequency = false;
        const std::vector<size_t>& timesteps = (years) ? getFirstTimestepYears() : getFirstTimestepMonths();

        std::vector<size_t>::const_iterator ci_timestep = std::find(timesteps.begin(), timesteps.end(), timestep);
        std::vector<size_t>::const_iterator ci_start_timestep = std::find(timesteps.begin(), timesteps.end(), start_timestep);

        //Find new start_timestep if the given one is not a value in the timesteps vector
        bool start_ts_in_timesteps = false;
        if (ci_start_timestep != timesteps.end()) {
            start_ts_in_timesteps = true;
        } else if (ci_start_timestep == timesteps.end()) {
            size_t new_start = closest(timesteps, start_timestep);
            if (0 != new_start) {
                ci_start_timestep = std::find(timesteps.begin(), timesteps.end(), new_start);
                start_ts_in_timesteps = true;
            }
        }


        if (start_ts_in_timesteps) {
            //Pick every n'th element, starting on start_timestep + (n-1), that is, every n'th element from ci_start_timestep - 1 for freq n > 1
            if (ci_timestep >= ci_start_timestep) {
                int dist = std::distance( ci_start_timestep, ci_timestep ) + 1;
                if ((dist % frequency) == 0) {
                    timestep_right_frequency = true;
                }
            }
        }

        return timestep_right_frequency;
    }
开发者ID:GitPaean,项目名称:opm-parser,代码行数:32,代码来源:TimeMap.cpp

示例12: if

EyeCalibration::CalibrationPoint EyeCalibration::getClosestPoint(CalibrationPoint a, CalibrationPoint b, CalibrationPoint point, bool segmentClamp) {
	int ap_x = point.x() - a.x();
	int ap_y = point.y() - a.y();

	int ab_x = b.x() - a.x();
	int ab_y = b.y() - a.y();

	float ab2 = ab_x*ab_x + ab_y*ab_y;
	float ap_ab = ap_x*ab_x + ap_y*ab_y;

	float t = ap_ab / ab2;

	if (segmentClamp) {
		if (t < 0.f) t = 0.f;
		else if (t > 1.f) t = 1.f;
	}

	int closest_x = a.x() + ab_x * t;
	int closest_y = a.y() + ab_y * t;

	osg::Vec3 ab_ray = b.ray() - a.ray();
	osg::Vec3 ray = a.ray() + ab_ray * t;

	CalibrationPoint closest(closest_x, closest_y, ray);
	return closest;
}
开发者ID:mdfeist,项目名称:BlinkAnalysis,代码行数:26,代码来源:EyeCalibration.cpp

示例13: point

bool MsqLine::intersect( const MsqLine& other, double& param, double epsilon ) const
{
  if (!closest( other, param ))
    return false;
  Vector3D p1 = point(param);
  Vector3D p2 = other.point(other.closest(p1));
  return (p1 - p2).length_squared() < epsilon*epsilon;
}
开发者ID:00liujj,项目名称:trilinos,代码行数:8,代码来源:MsqGeomPrim.cpp

示例14: closest

void KJSeeker::paint(QPainter *p, const QRect &)
{
	closest();
	QPixmap *pixmap = toPixmap(g);
	pixmap->setMask(barModeMask);
	bitBlt(p->device(), rect().topLeft().x(), rect().topLeft().y(),
		pixmap, 0, 0, rect().width(), rect().height(), Qt::CopyROP);
}
开发者ID:serghei,项目名称:kde3-kdemultimedia,代码行数:8,代码来源:kjseeker.cpp

示例15: get_closest

int get_closest(struct node *t)
{
	int distance = -1;
		if (t)
			closest(t, 0, &distance);
		else return -1;
	return distance + 1;
}
开发者ID:Yenni-Suresh,项目名称:MissionRnD-C-BinarySearchTree-Worksheet,代码行数:8,代码来源:BSTClosestLeafDistance.cpp


注:本文中的closest函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。