• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ closest函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: sample

        void sample(double U1, double U2, double& PE, double& PT)
        {
            PE=photon_energy_sampler.sample(U1);

            auto result=photon_theta_samplers.lookup(PE);
            auto theta_sampler=result.closest(PE);
            theta_sampler->sample(U2, PT);
        }
开发者ID:Bhare8972,项目名称:RFD_modelling,代码行数:8,代码来源:bremsstrahlung_table.hpp


示例17: closest

void closest(struct KD_TREE *tree, struct Node *u, int k, struct Point *x, int h[], int *mndist) {
	if (u == NULL || heuristic(tree, h) >= *mndist)
		return ;
	int dist = pt_dist(&(u->pid), x), old;
	*mndist = min(*mndist, dist), old = h[k];
	if (x->d[k] < u->pid.d[k]) {    		
		closest(tree, u->lson, (k+1)%tree->kD, x, h, mndist);
		h[k] = abs(x->d[k] - u->pid.d[k]);
		closest(tree, u->rson, (k+1)%tree->kD, x, h, mndist);
		h[k] = old;
	} else {
		closest(tree, u->rson, (k+1)%tree->kD, x, h, mndist);
		h[k] = abs(x->d[k] - u->pid.d[k]);
		closest(tree, u->lson, (k+1)%tree->kD, x, h, mndist);
		h[k] = old;
	}
}
开发者ID:morris821028,项目名称:Testdata-generator-example,代码行数:17,代码来源:solve.c


示例18: operator

 //NOTE: For now, we assume OBB max = -min.
 bool operator()(const shape::Box& a, const shape::Sphere& b)const{
     auto pos = pb_.pos_;
     auto extent = pa_.size_ * a.extent() + feather_;
     clam::Vec3d closest(
         std::min(std::max(pos[0], -extent[0]), extent[0]),
         std::min(std::max(pos[1], -extent[1]), extent[1]),
         std::min(std::max(pos[2], -extent[2]), extent[2])
     );
     return (closest - pos).length2() < sqr(pb_.size_ * b.radius() + feather_);
 }
开发者ID:Grieverheart,项目名称:SimpleEDMD,代码行数:11,代码来源:bv_overlap.cpp


示例19: main

int main(int argc, char const *argv[])
{	
	point* pares[100];
	int size = 100 
	srand(time(NULL));
	int i;
	for (i = 0; i < size; i++) {
		int x = rand();
		int y = rand();
		pares[i] = newpoint(x, y);
	}
	otro_y = copia(pares, size)
	qsort(pares,size,sizeof(point), compareX);
	qsort(pares,size,sizeof(point), compareY);
	pairs* min_x = closest(pares, size);
	pairs* min_y = closest(pares, size);
	pairs* min_abs =  min_x->dist < min_y->dist ? min_x : min_y;
	printpairs (min_abs);
	return 0;
}
开发者ID:aurom,项目名称:VACode,代码行数:20,代码来源:closest.c


示例20: rayTrace

/** rayTrace **/
intensity_t rayTrace(scene_t *scene, point_t base, vector_t unitDir,
                 double total_dist, entity_t *self) {
  intensity_t intensity = ((intensity_t){0, 0, 0});
  entity_t * closestEnt;
  hitinfo_t * hit = malloc(sizeof(hitinfo_t));

  closestEnt = closest(scene, base, unitDir, self, hit);
  if (closestEnt == NULL) {
    free(hit);
    return (intensity);
  }

  total_dist += hit->distance;

  window_t * window = ((window_t *)(scene->window->entDerived));
  sobj_t   * sobj   = ((sobj_t   *)(closestEnt->entDerived));

  intensity = ((tuple_t){window->ambient.x * sobj->color.r,
                         window->ambient.y * sobj->color.g,
                         window->ambient.z * sobj->color.b});

  intensity_t light = lighting(scene, closestEnt, hit);
  intensity.x += light.x;
  intensity.y += light.y;
  intensity.z += light.z;

  intensity.x /= 255;
  intensity.y /= 255;
  intensity.z /= 255;
  
  intensity.x /= total_dist;
  intensity.y /= total_dist;
  intensity.z /= total_dist;

  sobj_t * closestSobj = closestEnt->entDerived;
  if (length(((tuple_t)(closestSobj->reflective))) != 0) {
    vector_t U = scale(unitDir, -1);
    vector_t N = hit->normal;
    vector_t V = unitize(add(scale(N, (2 * dot(U, N))), unitDir));

    intensity_t reflection;
    reflection = rayTrace(scene, hit->hitpoint, V, total_dist, closestEnt);

    multiply(reflection, closestSobj->reflective);
    intensity = add(intensity, reflection);
  }


  free(hit);
  return (intensity);

} /* End rayTrace */
开发者ID:zero-clouds-,项目名称:RayTracer,代码行数:53,代码来源:raytrace.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ closure函数代码示例发布时间:2022-05-30
下一篇:
C++ closesocket函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap